# Flujo de GeneraciΓ³n del Informe ASVS 4.0.3 Este documento explica el flujo completo de cΓ³mo se obtienen los datos y se genera el informe ASVS automΓ‘ticamente. ## πŸ“Š Diagrama del Flujo ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ INICIO: make pdf_report β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PASO 1: generate_asvs_report.py β”‚ β”‚ ──────────────────────────────────────────────────────────── β”‚ β”‚ πŸ”— INTEGRADO CON DEFECTDOJO β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 1.1. CONEXIΓ“N CON DEFECTDOJO β”‚ β”‚ β”‚ β”‚ - Inicializa Django para acceso a DefectDojo β”‚ β”‚ β”‚ β”‚ - Obtiene producto "Medical Register App" β”‚ β”‚ β”‚ β”‚ - Obtiene Benchmark_Product_Summary (puntajes ASVS) β”‚ β”‚ β”‚ β”‚ - Obtiene findings activos del producto β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 1.2. MAPEO DE FINDINGS A ASVS β”‚ β”‚ β”‚ β”‚ - Mapea CWE β†’ CategorΓ­as ASVS: β”‚ β”‚ β”‚ β”‚ β€’ CWE-20, CWE-1287, CWE-843 β†’ V5 (ValidaciΓ³n) β”‚ β”‚ β”‚ β”‚ β€’ CWE-703 β†’ V7 (Error Handling) β”‚ β”‚ β”‚ β”‚ β€’ CWE-1021 β†’ V8 (Data Protection) β”‚ β”‚ β”‚ β”‚ β€’ CWE-942 β†’ V9 (Communications) β”‚ β”‚ β”‚ β”‚ - Agrupa findings por categorΓ­a ASVS β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 1.3. INICIALIZACIΓ“N β”‚ β”‚ β”‚ β”‚ - Crea ASVSAnalyzer con estructura ASVS 4.0.3 β”‚ β”‚ β”‚ β”‚ - Define 14 categorΓ­as (V1-V14) β”‚ β”‚ β”‚ β”‚ - Define requisitos Nivel 2 por categorΓ­a β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 1.4. ANÁLISIS DE CΓ“DIGO FUENTE (COMPLEMENTARIO) β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ Archivos Python analizados: β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - app/routes.py β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - app/helpers.py β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - app/storage.py β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - app/config.py β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ Archivos JavaScript analizados: β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - app/static/js/main.js β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - app/static/js/storage.js β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - app/static/js/validation.js β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Patrones detectados: β”‚ β”‚ β”‚ β”‚ βœ“ Validaciones (validate, sanitize) β”‚ β”‚ β”‚ β”‚ βœ“ Manejo de errores (try/except) β”‚ β”‚ β”‚ β”‚ βœ“ Headers de seguridad (X-Frame-Options, CSP, CORS) β”‚ β”‚ β”‚ β”‚ βœ“ ConfiguraciΓ³n centralizada (config.py) β”‚ β”‚ β”‚ β”‚ βœ“ API REST (@api.route, Blueprint) β”‚ β”‚ β”‚ β”‚ βœ“ SanitizaciΓ³n frontend (trim, replace) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 1.3. VERIFICACIΓ“N ASVS 4.0.3 Nivel 2 β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Para cada categorΓ­a V1-V14: β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ V1: Architecture, Design and Threat Modeling β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V1.1: ΒΏExiste README.md? β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V1.2: ΒΏExiste carpeta docs/? β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V1.3: ΒΏHay validaciones/error handling? β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V1.4: ΒΏHay API REST? β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ V5: Validation, Sanitization and Encoding β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V5.1: ΒΏValidaciΓ³n frontend Y backend? β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V5.2: ΒΏValidaciΓ³n de tipos? β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V5.3: ΒΏSanitizaciΓ³n implementada? β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V5.4: ΒΏValidaciΓ³n NaN/Infinity? (parcial) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V5.5: ΒΏValidaciΓ³n de lΓ­mites? β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - V5.6: ΒΏValidaciΓ³n de formato? β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ V2, V3, V4, V6: No aplicable (monousuario) β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ ... (resto de categorΓ­as) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Resultado: findings = { β”‚ β”‚ β”‚ β”‚ 'compliant': ['V1', 'V10', 'V11', 'V13', 'V14'], β”‚ β”‚ β”‚ β”‚ 'partial': ['V5', 'V7', 'V8', 'V9'], β”‚ β”‚ β”‚ β”‚ 'non_applicable': ['V2', 'V3', 'V4', 'V6'], β”‚ β”‚ β”‚ β”‚ 'missing': [] β”‚ β”‚ β”‚ β”‚ } β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 1.4. GENERACIΓ“N DEL INFORME MARKDOWN β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ ASVSReportGenerator genera: β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Encabezado (con ASVS 4.0.3 explΓ­cito) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ SecciΓ³n 1: DescripciΓ³n de la aplicaciΓ³n β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ SecciΓ³n 2: AnΓ‘lisis de seguridad β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ SecciΓ³n 3: Debilidades identificadas β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ SecciΓ³n 4: Nivel ASVS y requisitos β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ - Para cada V1-V14: β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ * Estado: βœ… CUMPLE / ⚠️ PARCIAL / ❌ PENDIENTEβ”‚ β”‚ β”‚ β”‚ β”‚ β”‚ * Requisitos cumplidos β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ * Justificaciones β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ SecciΓ³n 5: Recomendaciones β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Referencias (enlaces a GitHub ASVS 4.0.3) β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Guarda en: docs/INFORME_SEGURIDAD.md β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PASO 2: generate_pdf_report.py β”‚ β”‚ ──────────────────────────────────────────────────────────── β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 2.1. LECTURA DEL MARKDOWN β”‚ β”‚ β”‚ β”‚ - Lee: docs/INFORME_SEGURIDAD.md β”‚ β”‚ β”‚ β”‚ - Verifica que existe β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 2.2. CONVERSIΓ“N A PDF β”‚ β”‚ β”‚ β”‚ Intenta mΓ©todos en orden: β”‚ β”‚ β”‚ β”‚ 1. markdown2pdf (si disponible) β”‚ β”‚ β”‚ β”‚ 2. markdown + weasyprint (si disponible) β”‚ β”‚ β”‚ β”‚ 3. markdown + reportlab (si disponible) β”‚ β”‚ β”‚ β”‚ 4. pandoc (si estΓ‘ instalado) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ 2.3. GUARDADO DEL PDF β”‚ β”‚ β”‚ β”‚ - Guarda en: docs/informes/ β”‚ β”‚ β”‚ β”‚ - Nombre: INFORME_SEGURIDAD_YYYYMMDD.pdf β”‚ β”‚ β”‚ β”‚ - Ejemplo: INFORME_SEGURIDAD_20251203.pdf β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό βœ… PDF GENERADO ``` ## πŸ” Detalle del Proceso ### Fase 1: AnΓ‘lisis de CΓ³digo (`analyze_code()`) El script analiza los archivos fuente buscando patrones especΓ­ficos: #### Archivos Python analizados: - **`app/routes.py`**: Busca endpoints API, validaciones, manejo de errores - **`app/helpers.py`**: Busca funciones de validaciΓ³n y sanitizaciΓ³n - **`app/storage.py`**: Busca manejo de datos - **`app/config.py`**: Detecta configuraciΓ³n centralizada #### Archivos JavaScript analizados: - **`app/static/js/main.js`**: Busca validaciones frontend - **`app/static/js/storage.js`**: Busca manejo de datos en cliente - **`app/static/js/validation.js`**: Busca funciones de validaciΓ³n #### Patrones detectados: ```python # Ejemplo de detecciΓ³n en Python if 'validate' in content.lower() or 'sanitize' in content.lower(): code_analysis['validation'].append(filename) if 'try:' in content and 'except' in content: code_analysis['error_handling'].append(filename) if 'X-Frame-Options' in content or 'CSP' in content: code_analysis['security_headers'].append(filename) if '@api.route' in content: code_analysis['api_rest'] = True ``` ```javascript // Ejemplo de detecciΓ³n en JavaScript if ('validate' in content || 'parseFloat' in content): code_analysis['frontend_validation'].append(filename) if ('sanitize' in content || 'trim' in content): code_analysis['frontend_sanitization'].append(filename) ``` ### Fase 2: VerificaciΓ³n ASVS 4.0.3 (`check_asvs_requirements()`) Para cada categorΓ­a V1-V14, el script verifica el cumplimiento: #### Ejemplo: V5 (Validation, Sanitization and Encoding) ```python def _check_v5(self): compliant = [] partial = [] # V5.1: ValidaciΓ³n en todas las fuentes if 'validation' in code_analysis and 'frontend_validation' in code_analysis: compliant.append('V5.1') # βœ… CUMPLE elif 'validation' in code_analysis: partial.append('V5.1') # ⚠️ PARCIAL # V5.2: ValidaciΓ³n de tipos if 'validation' in code_analysis: compliant.append('V5.2') # βœ… CUMPLE # V5.3: SanitizaciΓ³n if 'frontend_sanitization' in code_analysis: compliant.append('V5.3') # βœ… CUMPLE else: partial.append('V5.3') # ⚠️ PARCIAL # V5.4: ValidaciΓ³n NaN/Infinity (siempre parcial por defecto) partial.append('V5.4') # ⚠️ PARCIAL # Resultado final if len(partial) > 0: findings['partial'].append({'category': 'V5', ...}) else: findings['compliant'].append('V5') ``` #### CategorΓ­as No Aplicables: ```python # V2, V3, V4, V6: No aplicable para aplicaciΓ³n monousuario findings['non_applicable'].append({ 'category': 'V2', 'reason': 'AplicaciΓ³n monousuario sin autenticaciΓ³n compleja' }) ``` ### Fase 3: GeneraciΓ³n del Informe (`generate_report()`) El generador crea el Markdown estructurado: #### Estructura del Informe: 1. **Encabezado**: Fecha, versiΓ³n ASVS 4.0.3, enlaces a GitHub 2. **SecciΓ³n 1**: DescripciΓ³n de la aplicaciΓ³n (texto fijo) 3. **SecciΓ³n 2**: MetodologΓ­a de anΓ‘lisis (texto fijo) 4. **SecciΓ³n 3**: Debilidades identificadas (texto fijo) 5. **SecciΓ³n 4**: Nivel ASVS y requisitos (generado dinΓ‘micamente) - Para cada V1-V14: - Estado basado en `findings` - Requisitos cumplidos/parciales - Justificaciones 6. **SecciΓ³n 5**: Recomendaciones (texto fijo) 7. **Referencias**: Enlaces a ASVS 4.0.3 en GitHub #### Ejemplo de generaciΓ³n dinΓ‘mica: ```python def _generate_section4(self): for code, name in ASVS_403_CATEGORIES.items(): if code in findings['compliant']: # Genera: βœ… CUMPLE elif code in [f['category'] for f in findings['partial']]: # Genera: ⚠️ PARCIAL elif code in [f['category'] for f in findings['non_applicable']]: # Genera: ⚠️ No aplicable ``` ### Fase 4: ConversiΓ³n a PDF (`generate_pdf_report()`) El script de conversiΓ³n: 1. **Lee el Markdown** generado 2. **Intenta convertir** usando mΓΊltiples mΓ©todos: - `markdown2pdf` (preferido) - `weasyprint` (alternativa) - `reportlab` (alternativa) - `pandoc` (ΓΊltimo recurso) 3. **Guarda el PDF** con fecha en el nombre ## πŸ“‹ Datos Utilizados ### Fuentes de Datos: 1. **Estructura ASVS 4.0.3** (hardcoded en el script): ```python ASVS_403_CATEGORIES = { 'V1': 'Architecture, Design and Threat Modeling', 'V2': 'Authentication', # ... 14 categorΓ­as } ``` 2. **CΓ³digo fuente de la aplicaciΓ³n**: - Archivos Python en `app/` - Archivos JavaScript en `app/static/js/` - Archivos de configuraciΓ³n 3. **AnΓ‘lisis de patrones**: - BΓΊsqueda de palabras clave - DetecciΓ³n de estructuras de cΓ³digo - VerificaciΓ³n de existencia de archivos ### Limitaciones del AnΓ‘lisis AutomΓ‘tico: - **AnΓ‘lisis estΓ‘tico bΓ‘sico**: No ejecuta el cΓ³digo, solo lo lee - **Patrones simples**: Busca palabras clave y estructuras bΓ‘sicas - **No verifica lΓ³gica compleja**: No analiza la implementaciΓ³n detallada - **Requiere validaciΓ³n manual**: El informe generado debe revisarse ## πŸ”„ Flujo Completo Resumido ``` Usuario ejecuta: make pdf_report β”‚ β”œβ”€β–Ί Paso 1: generate_asvs_report.py β”‚ β”‚ β”‚ β”œβ”€β–Ί Analiza cΓ³digo fuente (Python + JavaScript) β”‚ β”‚ └─► Detecta: validaciones, headers, API, etc. β”‚ β”‚ β”‚ β”œβ”€β–Ί Verifica requisitos ASVS 4.0.3 Nivel 2 β”‚ β”‚ └─► Compara cΓ³digo con 14 categorΓ­as (V1-V14) β”‚ β”‚ β”‚ └─► Genera Markdown β”‚ └─► Guarda: docs/INFORME_SEGURIDAD.md β”‚ └─► Paso 2: generate_pdf_report.py β”‚ β”œβ”€β–Ί Lee Markdown generado β”‚ β”œβ”€β–Ί Convierte a PDF (mΓΊltiples mΓ©todos) β”‚ └─► Guarda PDF └─► docs/informes/INFORME_SEGURIDAD_YYYYMMDD.pdf ``` ## 🎯 Puntos Clave 1. **ASVS 4.0.3 estΓ‘ hardcoded** en el script (estructura de categorΓ­as) 2. **No descarga datos de GitHub** - usa estructura local 3. **AnΓ‘lisis estΓ‘tico** - lee cΓ³digo, no lo ejecuta 4. **GeneraciΓ³n automΓ‘tica** - crea el informe completo desde cero 5. **Dos scripts separados**: - `generate_asvs_report.py`: Genera el contenido (Markdown) - `generate_pdf_report.py`: Convierte a PDF ## πŸ”— RelaciΓ³n entre ASVS y DefectDojo ### Estado Actual **IMPORTANTE**: En el proyecto actual, **ASVS y DefectDojo NO estΓ‘n integrados directamente**. - **El informe ASVS** se genera analizando el cΓ³digo fuente directamente - **DefectDojo** se usa para gestionar findings/vulnerabilidades (CWE-699, etc.) - **No hay conexiΓ³n** entre el informe ASVS y los benchmarks de DefectDojo ### Funcionalidad de DefectDojo con ASVS DefectDojo **SÍ tiene funcionalidad de benchmarks ASVS**, pero **NO se estΓ‘ usando** en este proyecto: - DefectDojo permite configurar **benchmarks ASVS** para productos - Los benchmarks permiten evaluar el cumplimiento de ASVS basΓ‘ndose en findings - Se puede ver el puntaje ASVS en la vista del producto - DefectDojo soporta ASVS v3.1 (no v4.0.3 directamente) ### Diferencia con el Enfoque Actual **Enfoque actual (implementado)**: ``` CΓ³digo fuente β†’ AnΓ‘lisis estΓ‘tico β†’ Informe ASVS ``` **Enfoque con DefectDojo (no implementado)**: ``` Findings en DefectDojo β†’ Benchmarks ASVS β†’ Puntaje ASVS ``` ### Posible IntegraciΓ³n Futura Se podrΓ­a mejorar el informe ASVS integrando con DefectDojo: 1. **Obtener findings de DefectDojo** relacionados con ASVS 2. **Usar benchmarks ASVS de DefectDojo** para evaluar cumplimiento 3. **Combinar anΓ‘lisis de cΓ³digo + findings de DefectDojo** para un informe mΓ‘s completo 4. **Sincronizar** el informe ASVS con el estado real de findings en DefectDojo ## πŸ’‘ Mejoras Futuras Posibles 1. **Descargar ASVS 4.0.3 desde GitHub** automΓ‘ticamente 2. **AnΓ‘lisis mΓ‘s profundo** del cΓ³digo (AST parsing) 3. **IntegraciΓ³n con DefectDojo** para obtener findings reales y usar benchmarks ASVS 4. **AnΓ‘lisis dinΓ‘mico** ejecutando tests de seguridad 5. **GeneraciΓ³n de evidencias** con ejemplos de cΓ³digo 6. **SincronizaciΓ³n con benchmarks ASVS de DefectDojo** para evaluaciΓ³n mΓ‘s precisa