Skip to content

fix(cors): throw hard error in production when CORS_ORIGIN is unset#1072

Merged
aaight merged 1 commit intodevfrom
fix/cors-origin-hard-error-production
Apr 2, 2026
Merged

fix(cors): throw hard error in production when CORS_ORIGIN is unset#1072
aaight merged 1 commit intodevfrom
fix/cors-origin-hard-error-production

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Apr 2, 2026

Summary

  • Throws at startup in production when CORS_ORIGIN is not set, replacing the previous warn() + empty origin list behavior that caused silent frontend failures
  • Updates buildCorsMiddleware() in src/utils/corsConfig.ts to throw an Error with a clear, actionable message instead of logging a warning
  • Removes the now-unused warn parameter from the function destructuring (kept in interface for backward compatibility)
  • Updates tests/unit/utils/corsConfig.test.ts to assert the throw behavior instead of the old warning + blocking tests

Trello card: https://trello.com/c/c2mjMUXE/575-8-cors-origin-warning-should-be-a-hard-error-in-production-src-utils-corsconfigts50-56-missing-corsorigin-in-production-logs-a-w

Test plan

  • buildCorsMiddleware({ corsOriginEnv: undefined, isProduction: true }) throws Error matching /CORS_ORIGIN is not set/
  • Error message is actionable: matches /Set CORS_ORIGIN to your frontend URL/
  • All existing non-production paths unchanged (dev default, single origin, multi-origin, whitespace trimming)
  • TypeScript type check passes with zero errors
  • Biome lint passes with zero errors
  • All 10 unit tests pass

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — Fail-fast at startup is the correct pattern for a required production config. The previous behavior (warn + empty origin list) silently broke all frontend CORS requests, which is worse than crashing. The implementation is clean: single call site in dashboard.ts, clear actionable error message, and tests properly assert the throw. Keeping warn? in the interface for backward compat is a reasonable choice since existing callers passing it won't break.

🕵️ claude-code · claude-opus-4-6 · run details

@aaight aaight merged commit fc828a3 into dev Apr 2, 2026
9 checks passed
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.

2 participants