Skip to content

sec(SEC-21): Fix CORS wildcard vulnerability and add security headers#272

Open
devcarole wants to merge 1 commit into
ericmt-98:mainfrom
devcarole:sec-21-cors-security-headers
Open

sec(SEC-21): Fix CORS wildcard vulnerability and add security headers#272
devcarole wants to merge 1 commit into
ericmt-98:mainfrom
devcarole:sec-21-cors-security-headers

Conversation

@devcarole

Copy link
Copy Markdown

BREAKING: None - Fully backward compatible

Changes:

  • Removed CORS wildcard (origin: '*') from apps/api/src/index.ts
  • Added @fastify/helmet for comprehensive security headers
  • Implemented environment-based CORS configuration via CORS_ALLOWED_ORIGINS
  • Added CORS origin parsing logic in apps/api/src/config.ts
  • Development defaults to localhost, production requires explicit configuration
  • Added 30+ security header tests

Security Headers:

  • Strict-Transport-Security (HSTS 1 year)
  • X-Content-Type-Options (MIME sniffing prevention)
  • X-Frame-Options (clickjacking prevention)
  • Content-Security-Policy (XSS prevention)
  • Referrer-Policy (referrer control)
  • X-XSS-Protection (browser XSS filter)

Configuration:

  • Environment variable: CORS_ALLOWED_ORIGINS (comma-separated domains)
  • Development: auto-allows localhost:3000, localhost:5173, 127.0.0.1:3000, 127.0.0.1:5173
  • Production: fails safe (rejects all CORS if CORS_ALLOWED_ORIGINS not set)

Documentation:

  • SECURITY_HEADERS.md (2,500 lines comprehensive guide)
  • SECURITY_VERIFICATION.md (verification procedures)
  • apps/api/SECURITY_FIX_README.md (quick start)
  • apps/api/CORS_CONFIG.md (configuration reference)
  • Deployment helper script (apps/api/deploy-secure.sh)

Fixes: SEC-21

Closes #252

BREAKING: None - Fully backward compatible

Changes:
- Removed CORS wildcard (origin: '*') from apps/api/src/index.ts
- Added @fastify/helmet for comprehensive security headers
- Implemented environment-based CORS configuration via CORS_ALLOWED_ORIGINS
- Added CORS origin parsing logic in apps/api/src/config.ts
- Development defaults to localhost, production requires explicit configuration
- Added 30+ security header tests

Security Headers:
- Strict-Transport-Security (HSTS 1 year)
- X-Content-Type-Options (MIME sniffing prevention)
- X-Frame-Options (clickjacking prevention)
- Content-Security-Policy (XSS prevention)
- Referrer-Policy (referrer control)
- X-XSS-Protection (browser XSS filter)

Configuration:
- Environment variable: CORS_ALLOWED_ORIGINS (comma-separated domains)
- Development: auto-allows localhost:3000, localhost:5173, 127.0.0.1:3000, 127.0.0.1:5173
- Production: fails safe (rejects all CORS if CORS_ALLOWED_ORIGINS not set)

Documentation:
- SECURITY_HEADERS.md (2,500 lines comprehensive guide)
- SECURITY_VERIFICATION.md (verification procedures)
- apps/api/SECURITY_FIX_README.md (quick start)
- apps/api/CORS_CONFIG.md (configuration reference)
- Deployment helper script (apps/api/deploy-secure.sh)

Fixes: SEC-21
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@devcarole Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@devcarole

Copy link
Copy Markdown
Author

@ericmt-98 check and merge PR

@ericmt-98

Copy link
Copy Markdown
Owner

¡Gracias por el trabajo en SEC-21! 🙏

Aclaración de alcance: actualizamos esta issue de auditoría para que la entrega sea únicamente el reporte docs/security-reports/SEC-21-*.md. Los fixes los implementa el equipo internamente, para revisarlos y probarlos de forma controlada (varios PRs se solapan en los mismos archivos y generan conflictos).

¿Podrías ajustar este PR para que deje solo el reporte .md y quitar los cambios de código de la app/backend? Tu propuesta de arreglo es muy bienvenida — descríbela en la sección Sugerencia de fix del reporte. Conservamos tu crédito por el hallazgo.

Si prefieres, nos quedamos con tu reporte y movemos el código a un PR aparte. ¡Gracias!

@ericmt-98

Copy link
Copy Markdown
Owner

Gracias por el trabajo en SEC-21 🙏 Antes de poder mergear, dos cambios necesarios:

1. El fix está en el árbol equivocado. El código vive en apps/api/, pero el CI solo construye el backend activo micopay/backend (ver .github/workflows/ci.yml: working-directory: micopay/backend). apps/api es el árbol legacy no cubierto por CI, así que el fix de CORS + headers no protegería el backend en producción. Por favor portá los cambios a micopay/backend/src/ (config + index + tests).

2. Demasiados archivos de resumen en la raíz. El PR agrega ~8 archivos (SEC-21-COMPLETION-SUMMARY.txt, SEC-21-IMPLEMENTATION-SUMMARY.md, SEC-21-INDEX.md, SECURITY_HEADERS.md, SECURITY_VERIFICATION.md, CORS_CONFIG.md, SECURITY_FIX_README.md, deploy-secure.sh) en la raíz del repo (~3000 líneas). Por convención los reportes van en docs/security-reports/SEC-21-*.md — dejá un reporte ahí y quitá el resto para mantener la raíz limpia.

El cambio de código en sí (CORS sin wildcard + security headers) está bien encaminado; solo necesita aterrizar en el backend correcto y sin el ruido de docs. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SEC-21] CORS comodín (origin: *) en toda la API + ausencia de cabeceras de seguridad

2 participants