🎓 Initial commit: Math2 Platform - Plataforma de Álgebra Lineal PRO
✨ Características: - 45 ejercicios universitarios (Basic → Advanced) - Renderizado LaTeX profesional - IA generativa (Z.ai/DashScope) - Docker 9 servicios - Tests 123/123 pasando - Seguridad enterprise (JWT, XSS, Rate limiting) 🐳 Infraestructura: - Next.js 14 + Node.js 20 - PostgreSQL 15 + Redis 7 - Docker Compose completo - Nginx + SSL ready 📚 Documentación: - 5 informes técnicos completos - README profesional - Scripts de deployment automatizados Estado: Producción lista ✅
This commit is contained in:
199
docs/current/SECURITY.md
Normal file
199
docs/current/SECURITY.md
Normal file
@@ -0,0 +1,199 @@
|
||||
# Security Policy - Estado Actual
|
||||
|
||||
> **Última verificación:** 2026-03-30
|
||||
> **Estado:** PARCIALMENTE IMPLEMENTADO
|
||||
> **Disclaimer:** Este documento lista solo los controles de seguridad REALMENTE implementados y verificados en el código.
|
||||
|
||||
---
|
||||
|
||||
## Implemented (Verificado)
|
||||
|
||||
### Authentication & Authorization
|
||||
|
||||
- ✅ **JWT con HS256 explícito**
|
||||
- Ubicación: `backend/src/shared/middleware/auth.middleware.ts`
|
||||
- Verificación: `algorithm: ['HS256']` explícito
|
||||
|
||||
- ✅ **Refresh tokens con blacklist (Redis)**
|
||||
- Fail-closed: Si Redis falla, bloquea requests
|
||||
- Retry automático implementado
|
||||
- Ubicación: `backend/src/shared/database/redis.client.ts`
|
||||
|
||||
- ✅ **Password hashing con bcrypt**
|
||||
- Cost factor: 12
|
||||
- Ubicación: `backend/src/modules/auth/auth.service.ts`
|
||||
|
||||
- ✅ **Rate limiting en login**
|
||||
- 5 intentos por 15 minutos
|
||||
- Express-rate-limit + Redis store
|
||||
- Ubicación: `backend/src/shared/middleware/rate-limit.middleware.ts`
|
||||
|
||||
- ✅ **Admin route protection**
|
||||
- Middleware `authenticate` + `requireAdmin`
|
||||
- Zod validation con `.strict()`
|
||||
- Ubicación: `backend/src/modules/admin/admin.routes.ts`
|
||||
|
||||
### XSS Protection
|
||||
|
||||
- ✅ **KaTeX configuración segura**
|
||||
- `trust: false` - No permite HTML
|
||||
- `strict: true` - Modo estricto
|
||||
- `maxSize: 500` - Límite de tamaño
|
||||
- `maxExpand: 1000` - Límite de expansión
|
||||
- Fórmulas limitadas a 5000 caracteres
|
||||
- Bloqueo de comandos peligrosos: \href, \url, \input, \includegraphics, etc.
|
||||
- Ubicación: `frontend/src/components/math/MathFormula.tsx`
|
||||
|
||||
### Infrastructure Security
|
||||
|
||||
- ✅ **Security headers (Helmet.js)**
|
||||
- CSP configurado
|
||||
- X-Frame-Options: DENY
|
||||
- HSTS habilitado
|
||||
- X-Content-Type-Options: nosniff
|
||||
- Ubicación: `backend/src/server.ts`
|
||||
|
||||
- ✅ **CORS configurado**
|
||||
- Orígenes explícitos
|
||||
- Credentials habilitados
|
||||
|
||||
- ✅ **Docker hardening**
|
||||
- Non-root users
|
||||
- Multi-stage builds
|
||||
- Resource limits
|
||||
|
||||
### Data Protection
|
||||
|
||||
- ✅ **Input validation con Zod**
|
||||
- Todos los endpoints validados
|
||||
- Esquemas `.strict()` para prevenir mass assignment
|
||||
- Ubicación: `backend/src/modules/admin/dtos/admin.dto.ts`
|
||||
|
||||
- ✅ **SQL Injection prevention**
|
||||
- Prisma ORM (sin raw queries)
|
||||
- Parameterized queries
|
||||
|
||||
- ✅ **SystemConfig encryption**
|
||||
- AES-256 para valores sensibles
|
||||
- Audit history de cambios
|
||||
- Ubicación: `backend/src/modules/system-config/system-config.service.ts`
|
||||
|
||||
---
|
||||
|
||||
## Planned/Pending (No Implementado)
|
||||
|
||||
### Authentication
|
||||
|
||||
- ❌ **Account lockout**
|
||||
- No hay bloqueo de cuenta después de múltiples intentos fallidos
|
||||
- Status: Pendiente
|
||||
|
||||
- ❌ **API key authentication**
|
||||
- No implementado para servicios
|
||||
- Status: Pendiente
|
||||
|
||||
- ❌ **2FA / MFA**
|
||||
- No implementado
|
||||
- Status: Planeado para futuro
|
||||
|
||||
### Web Protection
|
||||
|
||||
- ❌ **CSRF tokens**
|
||||
- No hay implementación actual de CSRF tokens
|
||||
- No hay validación de Origin en forms
|
||||
- Status: Pendiente
|
||||
|
||||
- ❌ **DOMPurify**
|
||||
- NO se usa DOMPurify en el proyecto
|
||||
- XSS protection se hace via KaTeX trust:false
|
||||
- Status: No aplica
|
||||
|
||||
### Compliance
|
||||
|
||||
- ❌ **GDPR /api/user/export**
|
||||
- Endpoint de exportación de datos no existe
|
||||
- Status: Pendiente
|
||||
|
||||
- ❌ **Right to erasure**
|
||||
- Eliminación de cuenta no implementada
|
||||
- Status: Pendiente
|
||||
|
||||
### Infrastructure
|
||||
|
||||
- ❌ **Secrets management (Vault)**
|
||||
- Variables en archivos .env (no Vault)
|
||||
- Status: Pendiente
|
||||
|
||||
- ❌ **WAF (Web Application Firewall)**
|
||||
- No implementado
|
||||
- Status: Planeado
|
||||
|
||||
---
|
||||
|
||||
## Verificación de Claims Anteriores
|
||||
|
||||
Claims que fueron **eliminados** de documentación anterior porque no están implementados:
|
||||
|
||||
| Claim Anterior | Estado Real | Notas |
|
||||
|----------------|-------------|-------|
|
||||
| Account lockout | ❌ No existe | Pendiente implementación |
|
||||
| API key authentication | ❌ No existe | Pendiente implementación |
|
||||
| DOMPurify | ❌ No se usa | Usamos KaTeX trust:false |
|
||||
| CSRF tokens | ❌ No implementado | Pendiente |
|
||||
| /api/user/export | ❌ No existe | Pendiente GDPR |
|
||||
| Vault usage | ❌ No existe | Secrets en .env |
|
||||
| No secrets in code | ⚠️ Parcial | Secrets aún en .env files |
|
||||
|
||||
---
|
||||
|
||||
## Compliance OWASP Top 10
|
||||
|
||||
| Risk | Estado | Implementación |
|
||||
|------|--------|----------------|
|
||||
| A01: Broken Access Control | ⚠️ Parcial | JWT + admin middleware ✅, pero falta 2FA |
|
||||
| A02: Cryptographic Failures | ⚠️ Parcial | bcrypt cost 12 ✅, pero secrets en archivos |
|
||||
| A03: Injection | ✅ Mitigado | Prisma ORM + Zod validation |
|
||||
| A04: Insecure Design | ⚠️ Parcial | Clean Architecture parcial |
|
||||
| A05: Security Misconfiguration | ⚠️ Parcial | Docker hardening ✅, falta WAF |
|
||||
| A06: Vulnerable Components | ⚠️ Parcial | npm audit disponible |
|
||||
| A07: Auth Failures | ⚠️ Parcial | JWT correcto ✅, falta lockout |
|
||||
| A08: Software Integrity | ⚠️ Parcial | Docker builds ✅ |
|
||||
| A09: Logging Failures | ✅ Mitigado | Winston JSON logging |
|
||||
| A10: SSRF | ⚠️ Parcial | Input validation básica |
|
||||
|
||||
---
|
||||
|
||||
## Vulnerability Reporting
|
||||
|
||||
Si descubres una vulnerabilidad de seguridad:
|
||||
|
||||
1. **NO abras un issue público**
|
||||
2. Envía email a: security@mathplatform.com
|
||||
3. Incluye pasos para reproducir
|
||||
4. Proporciona evaluación de impacto
|
||||
5. Respuesta inicial en 48 horas
|
||||
|
||||
---
|
||||
|
||||
## Comandos de Verificación
|
||||
|
||||
```bash
|
||||
# Verificar JWT configuration
|
||||
grep -n "algorithm" backend/src/shared/middleware/auth.middleware.ts
|
||||
|
||||
# Verificar XSS protection (KaTeX)
|
||||
grep -n "trust: false" frontend/src/components/math/MathFormula.tsx
|
||||
|
||||
# Verificar rate limiting
|
||||
grep -n "rateLimit" backend/src/shared/middleware/rate-limit.middleware.ts
|
||||
|
||||
# Verificar admin protection
|
||||
grep -n "requireAdmin" backend/src/modules/admin/admin.routes.ts
|
||||
|
||||
# Verificar Zod strict
|
||||
grep -n "\.strict()" backend/src/modules/admin/dtos/admin.dto.ts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Nota:** Esta es la única documentación de seguridad actualizada. Los documentos anteriores (`docs/SECURITY.md` raíz) contienen información obsoleta e inflada.
|
||||
Reference in New Issue
Block a user