fix(dashboard): add CORS origin validation in production#976
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
nhopeatall
approved these changes
Mar 22, 2026
Collaborator
nhopeatall
left a comment
There was a problem hiding this comment.
Summary
LGTM — Clean security fix that closes an open CORS policy. The implementation is correct, well-tested, and the extraction to a dedicated utility improves testability.
Notes
- Unused export:
CorsConfiginterface (lines 18–23 incorsConfig.ts) is exported but never imported anywhere. Minor dead code — not blocking. - Credential behavior change: The old fallback
cors()did not setcredentials: true; the new code always does. This is the correct behavior for the dashboard (session cookies requirecredentials: true), but worth noting as an intentional semantic change beyond what the PR description calls out. - Test coverage: 11 tests cover all three environment scenarios thoroughly. The tests correctly validate actual CORS header behavior via Hono's request helper rather than just testing config object shapes. The
warncallback injection makes the production warning testable without console mocks. - Empty-string edge case:
CORS_ORIGIN=""correctly falls through to the production/dev default (.filter(Boolean)strips the empty string) — good.
🕵️ claude-code · claude-opus-4-6 · run details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cors()allowed all origins whenCORS_ORIGINwas unset. This replaces it with a safe default.CORS_ORIGINis unset andNODE_ENV=production, the dashboard now logs a warning at startup and uses an empty origin list (blocking all cross-origin requests).CORS_ORIGINis unset outside production, CORS defaults tohttp://localhost:5173(withcredentials: true) for localnpm run dev:webusage.src/utils/corsConfig.ts(buildCorsMiddleware) for testability and clarity.Closes: https://trello.com/c/msVjZYft/497-as-a-developer-i-want-cors-origin-validation-in-production-so-that-the-dashboard-is-not-vulnerable-to-cross-origin-attacks
Changes
src/utils/corsConfig.ts— New helperbuildCorsMiddleware({ corsOriginEnv, isProduction, warn })with all three-scenario logicsrc/dashboard.ts— UsesbuildCorsMiddlewareinstead of inlinecors()call; removes unusedcorsimporttests/unit/utils/corsConfig.test.ts— 11 unit tests covering all three scenariosTest plan
CORS_ORIGINis set, only those origins are allowed (comma-separated, whitespace-trimmed)CORS_ORIGINis set, non-listed origins are blockedCORS_ORIGINis unset in production: warning is logged at startupCORS_ORIGINis unset in production: all cross-origin requests blocked (including localhost:5173)CORS_ORIGINis unset outside production: defaults tohttp://localhost:5173with credentialsCORS_ORIGINis unset outside production: other origins are still blockedCORS_ORIGINis unset🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details