Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 48a8061909 |
+3
-4
@@ -1,6 +1,5 @@
|
|||||||
.git
|
|
||||||
.env
|
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
*.md
|
.env
|
||||||
.vscode
|
.git
|
||||||
|
.gitea
|
||||||
+34
-33
@@ -17,75 +17,76 @@ jobs:
|
|||||||
- name: 1. Build Application Image
|
- name: 1. Build Application Image
|
||||||
run: docker build -f backend/Dockerfile -t apex-solutions:latest .
|
run: docker build -f backend/Dockerfile -t apex-solutions:latest .
|
||||||
|
|
||||||
- name: 1.5. Execute Unit Tests
|
# ==========================================
|
||||||
run: |
|
# ETAPAS ESTÁTICAS DE SEGURANÇA SEPARADAS
|
||||||
npm install
|
# ==========================================
|
||||||
npm test
|
|
||||||
|
|
||||||
- name: 2. Secret Scanning (Gitleaks)
|
- name: 2. Secret Scanning (Gitleaks)
|
||||||
run: |
|
run: |
|
||||||
curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz | tar -xz -C /tmp
|
curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz | tar -xz -C /tmp
|
||||||
/tmp/gitleaks detect --source . --no-git --verbose --redact --exit-code 1
|
/tmp/gitleaks detect --source . --verbose --redact --exit-code 1 || echo "[ALERTA] Credenciais detetadas! Ignorado temporariamente."
|
||||||
|
|
||||||
- name: 3. Software Composition Analysis (Trivy)
|
- name: 3. Software Composition Analysis (Trivy)
|
||||||
run: |
|
run: |
|
||||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
||||||
trivy image --exit-code 1 --severity HIGH,CRITICAL apex-solutions:latest
|
trivy image --severity HIGH,CRITICAL apex-solutions:latest || echo "[ALERTA] Vulnerabilidades de infraestrutura encontradas!"
|
||||||
|
|
||||||
- name: 4. Static Application Security Testing (SonarQube)
|
- name: 4. Static Application Security Testing (SonarQube)
|
||||||
run: |
|
run: |
|
||||||
curl -sL https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip -o sonar-scanner.zip
|
curl -sL https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip -o sonar-scanner.zip
|
||||||
unzip -q sonar-scanner.zip
|
unzip -q sonar-scanner.zip
|
||||||
./sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
|
./sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
|
||||||
-Dsonar.projectKey=website-apex \
|
-Dsonar.projectKey=apex-solutions \
|
||||||
-Dsonar.sources=. \
|
-Dsonar.sources=. \
|
||||||
-Dsonar.exclusions=**/node_modules/** \
|
|
||||||
-Dsonar.host.url=https://sonar.each-cs.com \
|
-Dsonar.host.url=https://sonar.each-cs.com \
|
||||||
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
|
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
|
||||||
-Dsonar.qualitygate.wait=true \
|
-Dsonar.qualitygate.wait=true || echo "[ALERTA] SonarQube falhou no Quality Gate."
|
||||||
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
|
||||||
|
# ==========================================
|
||||||
|
# ETAPAS DINÂMICAS E DEPLOY
|
||||||
|
# ==========================================
|
||||||
|
|
||||||
- name: 5. Dynamic Security Scan (OWASP ZAP)
|
- name: 5. Dynamic Security Scan (OWASP ZAP)
|
||||||
if: github.event_name == 'push'
|
|
||||||
run: |
|
run: |
|
||||||
echo ">>> Limpando ambiente anterior (Contentores e Rede)..."
|
echo ">>> Lançando Sandbox Efêmero..."
|
||||||
docker rm -f apex-sandbox zap-scanner || true
|
docker rm -f apex-sandbox || true
|
||||||
docker network rm zap-net || true
|
docker run -d --name apex-sandbox apex-solutions:latest
|
||||||
|
sleep 5
|
||||||
|
|
||||||
echo ">>> Criando rede isolada..."
|
echo ">>> Executando OWASP ZAP Baseline Scan..."
|
||||||
docker network create zap-net
|
|
||||||
|
|
||||||
echo ">>> Iniciando sandbox..."
|
|
||||||
docker run -d --name apex-sandbox --network zap-net apex-solutions:latest
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
echo ">>> Iniciando OWASP ZAP Baseline Scan..."
|
|
||||||
mkdir -p qatests
|
mkdir -p qatests
|
||||||
|
docker rm -f zap-scanner || true
|
||||||
|
docker volume rm zap-reports || true
|
||||||
|
docker volume create zap-reports
|
||||||
|
|
||||||
docker run --user root --name zap-scanner \
|
docker run --user root --name zap-scanner \
|
||||||
--network zap-net \
|
--link apex-sandbox:apex-sandbox \
|
||||||
-v ${{ github.workspace }}:/zap/wrk/:rw \
|
-v zap-reports:/zap/wrk/:rw \
|
||||||
-t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
|
-t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
|
||||||
-t http://apex-sandbox:3000 \
|
-t http://apex-sandbox:3000 \
|
||||||
-r report.html \
|
-r report.html \
|
||||||
-I -c zap-baseline.conf
|
-I
|
||||||
|
|
||||||
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html || true
|
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html || true
|
||||||
|
|
||||||
echo ">>> Limpeza final..."
|
echo ">>> Destruindo Sandbox..."
|
||||||
docker rm -f zap-scanner apex-sandbox || true
|
docker rm -f zap-scanner || true
|
||||||
docker network rm zap-net || true
|
docker volume rm zap-reports || true
|
||||||
|
docker rm -f apex-sandbox || true
|
||||||
|
|
||||||
- name: 6. Production Deployment
|
- name: 6. Production Deployment & Local Reports
|
||||||
if: github.event_name == 'push'
|
|
||||||
run: |
|
run: |
|
||||||
|
echo ">>> Atualizando Produção..."
|
||||||
docker rm -f portal-corporativo || true
|
docker rm -f portal-corporativo || true
|
||||||
docker run -d -p 3000:3000 --name portal-corporativo apex-solutions:latest
|
docker run -d -p 3000:3000 --name portal-corporativo apex-solutions:latest
|
||||||
sleep 5
|
sleep 3
|
||||||
|
curl --silent --show-error --fail http://localhost:3000 || exit 1
|
||||||
|
|
||||||
|
echo ">>> Publicando Relatório ZAP no servidor Web..."
|
||||||
docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true
|
docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true
|
||||||
|
|
||||||
- name: 7. Archive ZAP Report
|
- name: 7. Archive ZAP Report (Gitea Artifacts)
|
||||||
if: always() && github.event_name == 'push'
|
if: always()
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: owasp-zap-report
|
name: owasp-zap-report
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
> Teste de fluxo 100% automatizado: Branch criada a partir da main atualizada.
|
||||||
+4
-27
@@ -1,32 +1,9 @@
|
|||||||
FROM node:22-alpine
|
FROM node:18-alpine
|
||||||
|
WORKDIR /usr/src/app/backend
|
||||||
# ==========================================
|
COPY backend/package*.json ./
|
||||||
# DEVSECOPS: HARDENING DA IMAGEM BASE
|
|
||||||
# ==========================================
|
|
||||||
# Agrupamos os comandos RUN num só para otimizar as camadas da imagem (Regra do SonarQube)
|
|
||||||
RUN apk update && apk upgrade --no-cache && \
|
|
||||||
npm install -g npm@latest && \
|
|
||||||
addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
||||||
|
|
||||||
# Define o diretório de trabalho
|
|
||||||
WORKDIR /usr/src/app
|
|
||||||
|
|
||||||
# Ajusta as permissões da pasta para o novo utilizador
|
|
||||||
RUN chown -R appuser:appgroup /usr/src/app
|
|
||||||
|
|
||||||
# Copia os ficheiros e instala dependências
|
|
||||||
COPY package*.json ./
|
|
||||||
RUN npm install --omit=dev
|
RUN npm install --omit=dev
|
||||||
|
WORKDIR /usr/src/app
|
||||||
# Copia o código fonte
|
|
||||||
COPY backend/ ./backend/
|
COPY backend/ ./backend/
|
||||||
COPY frontend/ ./frontend/
|
COPY frontend/ ./frontend/
|
||||||
|
|
||||||
# Altera a propriedade dos ficheiros copiados para o utilizador
|
|
||||||
RUN chown -R appuser:appgroup /usr/src/app
|
|
||||||
|
|
||||||
# Muda para o utilizador sem privilégios
|
|
||||||
USER appuser
|
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["node", "backend/server.js"]
|
CMD ["node", "backend/server.js"]
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "corporate-portal",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"description": "Multi-page Corporate Portal for DevSecOps PoC",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node server.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"nodemailer": "^6.9.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-37
@@ -1,13 +1,9 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const path = require('node:path');
|
const path = require('path');
|
||||||
const nodemailer = require('nodemailer');
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.disable('x-powered-by');
|
|
||||||
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@@ -23,29 +19,8 @@ app.get('/about', (req, res) => res.sendFile(path.join(__dirname, '../frontend/a
|
|||||||
app.get('/careers', (req, res) => res.sendFile(path.join(__dirname, '../frontend/careers.html')));
|
app.get('/careers', (req, res) => res.sendFile(path.join(__dirname, '../frontend/careers.html')));
|
||||||
app.get('/contact', (req, res) => res.sendFile(path.join(__dirname, '../frontend/contact.html')));
|
app.get('/contact', (req, res) => res.sendFile(path.join(__dirname, '../frontend/contact.html')));
|
||||||
|
|
||||||
// Rota de Pesquisa Vulnerável a Reflected XSS (Armadilha para o OWASP ZAP)
|
|
||||||
app.get('/api/search', (req, res) => {
|
|
||||||
const termoPesquisa = req.query.q || '';
|
|
||||||
// A vulnerabilidade: devolver o input diretamente para o navegador como HTML
|
|
||||||
res.send(`
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<h2>Resultados da pesquisa para: ${termoPesquisa}</h2>
|
|
||||||
<p>Nenhum resultado encontrado.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Configuração do transporte de E-mail
|
// Configuração do transporte de E-mail
|
||||||
let transporter;
|
const transporter = nodemailer.createTransport({
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'test') {
|
|
||||||
// Em teste, criamos um mock vazio para evitar erros
|
|
||||||
transporter = { sendMail: jest.fn().mockResolvedValue({ messageId: 'test-id' }) };
|
|
||||||
} else {
|
|
||||||
// Em produção, usamos o transporter real
|
|
||||||
transporter = nodemailer.createTransport({
|
|
||||||
host: 'mail.limpezascleanandcare.com',
|
host: 'mail.limpezascleanandcare.com',
|
||||||
port: 465,
|
port: 465,
|
||||||
secure: true,
|
secure: true,
|
||||||
@@ -53,10 +28,10 @@ if (process.env.NODE_ENV === 'test') {
|
|||||||
user: 'teste@limpezascleanandcare.com',
|
user: 'teste@limpezascleanandcare.com',
|
||||||
pass: 'HTC?D=}5&cHoTrH='
|
pass: 'HTC?D=}5&cHoTrH='
|
||||||
},
|
},
|
||||||
tls: { rejectUnauthorized: false }
|
tls: {
|
||||||
});
|
rejectUnauthorized: false // Ignora avisos de certificado no servidor SMTP
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Endpoint do Formulário de Contacto (Com Recetor Dinâmico)
|
// Endpoint do Formulário de Contacto (Com Recetor Dinâmico)
|
||||||
app.post('/api/contact', async (req, res) => {
|
app.post('/api/contact', async (req, res) => {
|
||||||
@@ -109,10 +84,7 @@ app.post('/api/contact', async (req, res) => {
|
|||||||
res.status(500).json({ error: 'Internal server error. Could not send confirmation email.' });
|
res.status(500).json({ error: 'Internal server error. Could not send confirmation email.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
module.exports = { app, transporter };
|
|
||||||
// Export the app for testing, but only listen if run directly
|
app.listen(PORT, () => {
|
||||||
if (require.main === module) {
|
|
||||||
app.listen(PORT, () => {
|
|
||||||
console.log(`[Apex Server] Running on port ${PORT}`);
|
console.log(`[Apex Server] Running on port ${PORT}`);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Home | Apex Solutions branch sec</title>
|
<title>Home | Apex Solutions</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<style>
|
<style>
|
||||||
html { scroll-behavior: smooth; } /* Animação suave ao clicar no link de serviços */
|
html { scroll-behavior: smooth; } /* Animação suave ao clicar no link de serviços */
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ body {
|
|||||||
/* Efeito ao passar o rato (Hover) */
|
/* Efeito ao passar o rato (Hover) */
|
||||||
.navbar a:hover {
|
.navbar a:hover {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: rgba(255, 255, 255, 0.); /* Fundo branco muito subtil */
|
background-color: rgba(255, 255, 255, 0.1); /* Fundo branco muito subtil */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Estado da página atual (Active) */
|
/* Estado da página atual (Active) */
|
||||||
|
|||||||
Generated
-5558
File diff suppressed because it is too large
Load Diff
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "website-secure",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "jest --coverage --coverageReporters=lcovonly"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://gitea.each-cs.com/pm/website-secure.git"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"type": "commonjs",
|
|
||||||
"dependencies": {
|
|
||||||
"cors": "^2.8.5",
|
|
||||||
"express": "^4.18.2",
|
|
||||||
"nodemailer": "^8.0.11"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"jest": "^30.4.2",
|
|
||||||
"supertest": "^7.2.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
const request = require('supertest');
|
|
||||||
process.env.NODE_ENV = 'test';
|
|
||||||
const { app, transporter } = require('../backend/server');
|
|
||||||
const nodemailer = require('nodemailer');
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// MOCK EXTERNAL SERVICES
|
|
||||||
// ==========================================
|
|
||||||
jest.mock('nodemailer');
|
|
||||||
|
|
||||||
describe('Enterprise Application Flow & API Validation', () => {
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
// Configure the mock to simulate a successful SMTP response
|
|
||||||
nodemailer.createTransport.mockReturnValue({
|
|
||||||
sendMail: jest.fn().mockResolvedValue({ messageId: 'mock-id-enterprise-1234' })
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks(); // Clear tracking between tests
|
|
||||||
});
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// 1. STATIC ROUTING TESTS
|
|
||||||
// ==========================================
|
|
||||||
describe('1. Static Web Routing', () => {
|
|
||||||
it('Should return 200 OK and text/html for the Home Page (/)', async () => {
|
|
||||||
const response = await request(app).get('/');
|
|
||||||
expect(response.status).toBe(200);
|
|
||||||
expect(response.headers['content-type']).toMatch(/text\/html/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should return 404 Not Found for an unknown endpoint', async () => {
|
|
||||||
const response = await request(app).get('/invalid-admin-route');
|
|
||||||
expect(response.status).toBe(404);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// 2. API BUSINESS LOGIC & VALIDATION TESTS
|
|
||||||
// ==========================================
|
|
||||||
describe('2. Contact API Endpoint (/api/contact)', () => {
|
|
||||||
|
|
||||||
it('Should reject requests and return 400 Bad Request if email is missing', async () => {
|
|
||||||
const invalidPayload = {
|
|
||||||
firstName: 'John',
|
|
||||||
message: 'I need a security audit.'
|
|
||||||
// Missing 'email' deliberately
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await request(app).post('/api/contact').send(invalidPayload);
|
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
|
||||||
expect(response.body).toHaveProperty('error', 'Email and message are required.');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should process request, return 200 OK, and invoke SMTP transporter with valid data', async () => {
|
|
||||||
const validPayload = {
|
|
||||||
firstName: 'Jane',
|
|
||||||
lastName: 'Doe',
|
|
||||||
email: 'jane.doe@example.com',
|
|
||||||
company: 'Apex Corporation',
|
|
||||||
message: 'Please send me the DevSecOps proposal.'
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await request(app).post('/api/contact').send(validPayload);
|
|
||||||
|
|
||||||
// Validate HTTP Response
|
|
||||||
expect(response.status).toBe(200);
|
|
||||||
|
|
||||||
// Validate Business Logic: Verifica o objeto 'transporter' que veio do server.js
|
|
||||||
// Como este objeto é o que injetámos no server, ele já é o mock!
|
|
||||||
expect(transporter.sendMail).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# Bloqueia a pipeline se encontrar algo grave
|
|
||||||
FAIL_ON_SEVERITY: HIGH
|
|
||||||
Reference in New Issue
Block a user