โ— CULTIVA IA โ€” Servicio de Seguridad

SAST Configuration Report
NutriTrack SaaS

Analisis de seguridad estatico con Semgrep + CodeQL. Baseline scan del repositorio Python/Django + React. Pipeline CI/CD configurado.

Semgrep v1.72
CodeQL 2.18
HIPAA + SOC 2
GitHub Actions
18 Jun 2026
3
Criticas
8
Altas
14
Medias
21
Bajas
46
Total
Hallazgos Criticos del Baseline Scan
3 hallazgos ยท requieren remediation inmediata
CRITICAL
SQL Injection via ORM raw() sin sanitizar
๐Ÿ“„ api/views/patients.py:87 ๐Ÿ”‘ CWE-89 ๐Ÿ“‹ OWASP A03:2021 ๐Ÿฅ HIPAA ยง164.312(a)
query = Patient.objects.raw(f"SELECT * FROM patients WHERE clinic_id = {clinic_id}")
Remediacion: Usar parametros posicionales de Django ORM: Patient.objects.raw("SELECT * FROM patients WHERE clinic_id = %s", [clinic_id]) o mejor Patient.objects.filter(clinic_id=clinic_id)
CRITICAL
JWT Secret hardcodeado en settings.py
๐Ÿ“„ nutritrack/settings.py:42 ๐Ÿ”‘ CWE-798 ๐Ÿ“‹ OWASP A02:2021
SECRET_KEY = "django-insecure-nutri2024supersecret!@#"
Remediacion: Mover a variable de entorno: SECRET_KEY = os.environ["DJANGO_SECRET_KEY"] y rotar el secret inmediatamente en prod.
CRITICAL
CSRF Protection deshabilitada en endpoint de pago
๐Ÿ“„ api/views/billing.py:12 ๐Ÿ”‘ CWE-352 ๐Ÿ“‹ OWASP A01:2021
@csrf_exempt
def process_payment(request):
Remediacion: Eliminar @csrf_exempt y usar tokens CSRF correctamente, o implementar autenticacion Bearer + @csrf_protect explicitamente.
โšก
GitHub Actions Workflow
.github/workflows/sast.yml
.github/workflows/sast.yml YAML
name: SAST Security Scan
on:
  pull_request:
    branches: [ main, develop ]
  push:
    branches: [ main ]

jobs:
  semgrep:
    name: Semgrep SAST
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v4
      - name: Run Semgrep
        uses: returntocorp/semgrep-action@v1
        with:
          config: |
            p/django
            p/python
            p/react
            p/owasp-top-ten
            p/jwt
            .semgrep/custom-rules.yaml
        env:
          SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}

  codeql:
    name: CodeQL Analysis
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: python, javascript
          queries: security-and-quality
      - name: Analyze
        uses: github/codeql-action/analyze@v3

  gate:
    name: Quality Gate
    needs: [ semgrep, codeql ]
    runs-on: ubuntu-latest
    steps:
      - name: Block on CRITICAL
        run: |
          echo "CRITICAL findings block merge"
          exit ${{ needs.semgrep.outputs.exit-code }}
โœฆ
Reglas Personalizadas Semgrep
.semgrep/custom-rules.yaml
Custom
hardcoded-jwt-secret
Detecta secrets JWT hardcodeados en llamadas a jwt.encode()
Custom
django-raw-sql-injection
Patron f-string en QuerySet.raw() o cursor.execute()
Custom
phi-data-logging
Registra si datos PHI (patient_id, diagnosis, weight) van a logs โ€” HIPAA
HIPAA
unencrypted-phi-field
Campos de modelo Django con datos de salud sin EncryptedField
Built-in
p/django ยท p/owasp-top-ten ยท p/jwt ยท p/react
887 reglas de la comunidad Semgrep activas por defecto
hardcoded-jwt-secret (custom rule)
rules:
  - id: hardcoded-jwt-secret
    patterns:
      - pattern: jwt.encode($DATA, "...", ...)
      - pattern: jwt.encode($DATA, '...', ...)
    message: "JWT secret hardcodeado. Usar os.environ['JWT_SECRET']"
    languages: [ python ]
    severity: ERROR
    metadata:
      cwe: CWE-798
      hipaa: "164.312(a)(2)(iv)"
โš–
Seleccion de Herramientas SAST
โœ“ Semgrep + CodeQL seleccionados para NutriTrack
Herramienta Python/Django React/JS CI/CD Reglas Custom Coste Tiempo scan HIPAA/SOC2 Decision
Semgrep
โœ“ โœ“ โœ“ โœ“ YAML Gratis ~90s โœ“ ELEGIDO
CodeQL
โœ“ โœ“ โœ“ Native GH โœ“ QL Gratis (OSS) ~4min โœ“ ELEGIDO
SonarQube
โœ“ โœ“ โœ“ Limitado $150+/mes ~3min โœ“ Descartado (coste)
โฑ
Pipeline CI/CD Timing
+2m 30s al pipeline existente
1
Checkout + Setup
Clone repo, instalar dependencias Semgrep/CodeQL
โฑ ~15s
2
Semgrep Scan (paralelo)
Reglas oficiales + custom rules NutriTrack, solo archivos modificados en PR
โฑ ~90s (incremental en PR)
3
CodeQL Analysis (paralelo)
Python + JavaScript, security-and-quality queries, cache de BD CodeQL
โฑ ~60s (con cache)
4
Quality Gate
Bloquea merge si hay CRITICAL. HIGH genera warnings. SARIF a GitHub Security tab.
โฑ ~5s
Objetivo cumplido: Pipeline total ~10:30 min vs 8:00 anterior. Overhead de 2m 30s dentro del limite de 3 minutos acordado.
๐Ÿ“Š
Cobertura por Modulo
% archivos escaneados / total
Python / Django (backend) 94% (187/199 files)
React / TypeScript (frontend) 89% (312/351 files)
SQL Migrations 100% (28/28 files)
Docker / IaC 75% (9/12 files)
Tests (excluidos del gate) 0% (excluidos)
Archivos excluidos: tests/, migrations/ (solo lectura), node_modules/, *.min.js
๐Ÿ—บ
Roadmap de Remediacion
6 semanas ยท Sprint de seguridad
โœ“
Semana 0 โ€” Baseline + Configuracion SAST
Pipeline configurado, custom rules creadas, baseline scan ejecutado. 46 hallazgos identificados.
18 Jun 2026 ยท COMPLETADO
โ†’
Semana 1-2 โ€” Remediacion CRITICAL + HIGH
Fix SQL injection, rotar JWT secret, restaurar CSRF, resolver 5 XSS en React. Bloqueo de merge activado para CRITICAL.
25 Jun โ€“ 2 Jul 2026 ยท EN PROGRESO
3
Semana 3 โ€” MEDIUM + Falsos Positivos
Revisar 14 hallazgos medios, documentar supresiones legitimas, afinar reglas PHI para HIPAA.
9 Jul 2026
4
Semana 4 โ€” Pre-commit Hooks + Training
Instalar semgrep en pre-commit, workshop 2h con el equipo de desarrollo sobre patrones inseguros en Django.
16 Jul 2026
5
Semana 5-6 โ€” LOW + SOC 2 Evidence Pack
Cerrar hallazgos bajos, generar reporte SARIF para auditores SOC 2, documentar proceso en runbook de seguridad.
23 Jul โ€“ 1 Ago 2026