Merge pull request 'owasp zap config v16' (#21) from teste-bloqueio into main
DevSecOps Enterprise Pipeline / security-gate-and-deploy (push) Successful in 1m34s

Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
pm
2026-06-13 10:44:17 +00:00
4 changed files with 12 additions and 15 deletions
+5 -8
View File
@@ -46,7 +46,7 @@ jobs:
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
- name: 5. Dynamic Security Scan (OWASP ZAP)
if: github.event_name == 'push'
# REMOVIDO o "if: github.event_name == 'push'". Agora o ZAP corre SEMPRE (nos PRs e nos Merges)!
run: |
echo ">>> 1. Limpeza profunda do ambiente..."
docker rm -f apex-sandbox zap-scanner || true
@@ -64,10 +64,8 @@ jobs:
docker volume create zap-data
echo ">>> 4. Executar OWASP ZAP (FULL SCAN + AJAX SPIDER)..."
# Desligamos a paragem automática do Linux
set +e
# Adicionámos o -J report.json para criar um ficheiro legível por máquina
docker run --user root --name zap-scanner \
--network zap-net \
-v zap-data:/zap/wrk/:rw \
@@ -77,11 +75,9 @@ jobs:
-J report.json \
-j
# Voltamos a ligar a paragem de segurança
set -e
echo ">>> 5. Recolher os relatórios..."
# Agora extraímos os dois ficheiros (HTML para humanos, JSON para a pipeline)
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html || true
docker cp zap-scanner:/zap/wrk/report.json qatests/report.json || true
@@ -91,10 +87,9 @@ jobs:
docker volume rm zap-data || true
echo ">>> 7. Veredicto Final da Segurança (Gatekeeper Policy)..."
# Lemos os relatórios gerados. O -i ignora maiúsculas/minúsculas e o -E permite múltiplas procuras.
if grep -qi 'Cross Site Scripting (Reflected)' qatests/report.html || grep -iE '"riskcode"\s*:\s*"3"|"risk"\s*:\s*"High"' qatests/report.json; then
echo "🚨 ALERTA CRÍTICO: O OWASP ZAP detetou uma vulnerabilidade de Injeção de Código (XSS)!"
echo "🛑 Pipeline BLOQUEADA para proteger o ambiente de Produção."
echo "🛑 Pipeline BLOQUEADA para proteger a Branch Principal e a Produção."
exit 1
else
echo "✅ ZAP Scan concluído. Nenhuma falha Crítica ou Alta encontrada."
@@ -102,6 +97,7 @@ jobs:
fi
- name: 6. Production Deployment
# MANTIDO: O deploy para a Produção SÓ pode acontecer num push/merge direto para a main!
if: github.event_name == 'push'
run: |
docker rm -f portal-corporativo || true
@@ -110,7 +106,8 @@ jobs:
docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true
- name: 7. Archive ZAP Report
if: always() && github.event_name == 'push'
# ALTERADO: Usamos apenas always(). Queremos ver o relatório independentemente de ser PR ou Push.
if: always()
uses: actions/upload-artifact@v3
with:
name: owasp-zap-report
+3 -3
View File
@@ -23,9 +23,9 @@ app.get('/careers', (req, res) => res.sendFile(path.join(__dirname, '../frontend
app.get('/contact', (req, res) => res.sendFile(path.join(__dirname, '../frontend/contact.html')));
// ==========================================
// ROTA VULNERÁVEL (Armadilha infalível para o OWASP ZAP)
// VULNERÁVEL (OWASP ZAP)
// ==========================================
app.get('/api/search', (req, res) => {
/*app.get('/api/search', (req, res) => {
const termo = req.query.q || '';
// A vulnerabilidade crítica: devolver o input diretamente no HTML
res.send(`
@@ -37,7 +37,7 @@ app.get('/api/search', (req, res) => {
</body>
</html>
`);
});
});*/
// Configuração do transporte de E-mail (Mocks de teste vs Produção)
let transporter;
+2 -2
View File
@@ -93,12 +93,12 @@
</div>
</div>
</main>
<div style="display: none;">
<!--<div style="display: none;">
<form action="/api/search" method="GET">
<input type="text" name="q" value="teste">
<button type="submit">Pesquisar</button>
</form>
</div>
</div>-->
<footer class="bg-slate-900 text-slate-400 py-12 text-center">
<p>&copy; 2026 Apex Solutions. All rights reserved.</p>
</footer>
+2 -2
View File
@@ -36,7 +36,7 @@ describe('Enterprise Application Flow & API Validation', () => {
expect(response.status).toBe(404);
});
// NOVO TESTE: Valida a nossa armadilha para o OWASP ZAP (corrigido para /api/search)
/*// OWASP ZAP (/api/search)
it('Should reflect the search query in the HTML response (/api/search) - Vulnerable to XSS', async () => {
const maliciousPayload = '<script>alert("ZAP")</script>';
const response = await request(app).get(`/api/search?q=${maliciousPayload}`);
@@ -44,7 +44,7 @@ describe('Enterprise Application Flow & API Validation', () => {
expect(response.status).toBe(200);
// Verifica se o payload é refletido exatamente como entrou (confirmando a vulnerabilidade)
expect(response.text).toContain(`Resultados para: ${maliciousPayload}`);
});
});*/
});
// ==========================================