Este diretório contém workflows automatizados de segurança para o ProStaff API.
Trigger: Push/PR em master ou develop, agendamento semanal
Jobs:
- Brakeman - Análise de segurança específica para Rails
- Dependency Check - Verifica vulnerabilidades em gems (Bundle Audit)
- Semgrep - Análise estática com regras customizáveis
- Secret Scan - Detecta secrets com TruffleHog
- SSRF Protection - Testa proteção contra Server-Side Request Forgery
- Testa bloqueio de localhost, IPs privados, AWS metadata
- Verifica whitelist de domínios
- Confirma que autenticação é obrigatória
- Authentication Test - Valida segurança de autenticação
- Testa rejeição de tokens inválidos/ausentes
- Verifica endpoints protegidos
- Valida endpoints públicos (health check)
- SQL Injection Test - Testa proteção contra SQL injection
- Testa queries parametrizadas
- Verifica bloqueio de UNION injection
- Valida que erros SQL não vazam
- Secrets Scan - Verifica secrets expostos
- Busca hardcoded passwords
- Verifica API keys
- Confirma .env não está no git
- Security Summary - Consolida todos os resultados
- Posta comentário no PR com tabela de status
- Separa SAST vs DAST
- Indica se pode fazer merge
Cada job DAST segue este padrão:
services:
postgres:
image: postgres:15-alpine
# ...
redis:
image: redis:7-alpine
# ...
steps:
1. Checkout do código
2. Setup Ruby + bundler
3. Setup database (rails db:migrate)
4. Start Rails server (porta 3333)
5. Wait for API (/up endpoint)
6. Run security test script
7. Upload results (artifacts)
Os scripts estão em .pentest/:
| Script | Testes | O que valida |
|---|---|---|
test-ssrf-quick.sh |
9 | SSRF protection |
test-authentication-quick.sh |
5 | JWT auth |
test-sql-injection-quick.sh |
4 | SQL injection |
test-secrets-quick.sh |
5 | Secrets management |
# Rodar todos os testes de segurança
./.pentest/test-ssrf-quick.sh
./.pentest/test-authentication-quick.sh
./.pentest/test-sql-injection-quick.sh
./.pentest/test-secrets-quick.sh
Ao criar um PR, o workflow automaticamente:
- Roda todos os scans (SAST + DAST)
- Posta comentário com resumo dos resultados
- Bloqueia merge se houver falhas críticas
Exemplo de comentário no PR:
## Security Scan Summary
### Static Analysis (SAST)
| Check | Status |
|-------|--------|
| Brakeman | success |
| Dependencies | success |
| Semgrep | success |
| Secrets | success |
### Dynamic Analysis (DAST)
| Check | Status |
|-------|--------|
| SSRF Protection | success |
| Authentication | success |
| SQL Injection | success |
All security checks passed!
O workflow pode rodar semanalmente (comentado por padrão):
# Descomentar para ativar
schedule:
- cron: '0 9 * * 1' # Segunda-feira 9am UTC
Cada job gera artifacts que podem ser baixados:
brakeman-report.json- Relatório Brakemanbundle-audit-report.txt- Relatório de dependênciassemgrep-report.json- Relatório Semgrepssrf-test-results/- Resultados dos testes SSRF
Como baixar:
- Vá em Actions > Workflow run
- Scroll down até "Artifacts"
- Download do artifact desejado
Problema: API não sobe ou timeout esperando /up
Solução:
# Aumentar timeout em .github/workflows/security-scan.yml
- name: Wait for API
run: |
timeout 120 bash -c 'until curl -sf http://localhost:3333/up; do sleep 2; done'
Problema: Testes passam localmente mas falham no CI
Causa comum: Diferenças de ambiente (variáveis, portas, etc)
Debug:
# Adicionar step de debug
- name: Debug
run: |
curl -v http://localhost:3333/up
docker logs <container_name>
Problema: TruffleHog não roda (action externa)
Solução: Script .pentest/test-secrets-quick.sh faz scan básico mesmo sem TruffleHog
Problema: Testes de multi-tenancy falham por rate limit (3 reg/hour)
Solução: Criar test data via seeds em vez de criar via API:
# db/seeds/test_organizations.rb
if Rails.env.test?
org1 = Organization.create!(name: "Test Org 1", slug: "test-org-1")
org2 = Organization.create!(name: "Test Org 2", slug: "test-org-2")
# ...
end# .pentest/test-new-feature.sh
#!/bin/bash
API_URL="http://localhost:3333"
# ... testes
new-feature-test:
name: New Feature Security Test
runs-on: ubuntu-latest
services:
postgres: { ... }
redis: { ... }
steps:
- uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4.8
bundler-cache: true
- name: Setup Database
run: bundle exec rails db:migrate RAILS_ENV=test
- name: Start Server
run: bundle exec rails s -p 3333 -d
- name: Run Tests
run: ./.pentest/test-new-feature.sh
security-summary:
needs: [..., new-feature-test]
# ...
const newFeature = '${{ needs.new-feature-test.result }}';
# ...
O workflow precisa destes secrets configurados em Settings → Secrets → Actions:
| Secret | Obrigatório? | Uso |
|---|---|---|
RIOT_API_KEY |
Não | Testes que envolvem Riot API (fallback: dummy_key) |
SENTRY_DSN |
Não | Reporting de erros |
Como configurar:
- GitHub → Repository → Settings
- Secrets and variables → Actions
- New repository secret
- Nome:
RIOT_API_KEY, Value:sua_api_key
Tempo médio de execução:
| Job | Duração | Pode rodar em paralelo? |
|---|---|---|
| Brakeman | ~1 min | Sim |
| Dependencies | ~2 min | Sim |
| Semgrep | ~3 min | Sim |
| SSRF Test | ~2 min | Sim |
| Auth Test | ~2 min | Sim |
| SQL Injection | ~2 min | Sim |
| Secrets | ~1 min | Sim |
Total: ~3-4 minutos (em paralelo)
- OWASP ZAP - Scan de vulnerabilidades web
- Nuclei - Template-based scanning
- Multi-tenancy test - Quando resolver rate limit
- JWT security test - Algorithm confusion, expiration
- Rate limiting test - Validar Rack::Attack
zap-scan:
name: OWASP ZAP Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: ZAP Baseline Scan
uses: zaproxy/action-baseline@v0.7.0
with:
target: 'http://localhost:3333'
Este workflow cobre:
-
OWASP Top 10 2025
-
A01: Broken Access Control (Auth tests)
-
A02: Cryptographic Failures (Secrets scan)
-
A03: Injection (SQL injection tests)
-
A04: Insecure Design (Code review)
-
A05: Security Misconfiguration (Brakeman)
-
A06: Vulnerable Components (Dependency check)
-
A07: Auth Failures (Auth tests)
-
A08: Data Integrity (Semgrep)
-
A09: Logging Failures (Code review)
-
A10: SSRF (SSRF tests)
-
SAST + DAST (Static + Dynamic analysis)
-
SCA (Software Composition Analysis)
-
Secrets Detection
Last Updated: 2026-03-04 Maintainer: Security Team CI/CD Status: Active