Skip to content

fix: handle wildcard and boolean values in CORS origin configuration#90

Merged
heitorrsdev merged 2 commits intomainfrom
fix/cors-allowed-origins
Apr 20, 2026
Merged

fix: handle wildcard and boolean values in CORS origin configuration#90
heitorrsdev merged 2 commits intomainfrom
fix/cors-allowed-origins

Conversation

@heitorrsdev
Copy link
Copy Markdown
Owner

Description

Fixes the CORS configuration logic to correctly handle the ALLOWED_ORIGINS environment variable when set to "true" or "*", while maintaining support for comma-separated lists.

What was done

  • Added parseAllowedOrigins helper in src/app.config.ts.
  • Implemented logic to return true if ALLOWED_ORIGINS is "true" or "*".
  • Implemented logic to return false if ALLOWED_ORIGINS is undefined.
  • Retained comma-separated list parsing for other values.
  • Updated test/cors.e2e.spec.ts with comprehensive scenarios covering all these cases.

Why

The previous implementation incorrectly parsed "true" as ["true"], which caused CORS to reject requests and return HTTP 400 in deployment environments (like Render) that use this convention for public access. The new approach correctly maps these strings to the boolean true expected by NestJS's CORS middleware.

@heitorrsdev heitorrsdev merged commit 031006a into main Apr 20, 2026
1 check passed
@heitorrsdev heitorrsdev deleted the fix/cors-allowed-origins branch April 20, 2026 21:26
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.

1 participant