Enforce env-driven CORS origin allow-list on /graphql, /graphql/stream, and /export - #25
Merged
Merged
Conversation
Co-authored-by: charles2ke <6725706+charles2ke@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix CORS middleware configuration for security
Enforce env-driven CORS origin allow-list on /graphql, /graphql/stream, and /export
Sep 16, 2026
charles2ke
approved these changes
Sep 16, 2026
There was a problem hiding this comment.
🟡 Changes recommended
Production-route integration coverage and wildcard rejection remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Enforces an environment-driven, deny-by-default CORS allow-list across the public HTTP mounts.
Changes:
- Adds reusable CORS option parsing.
- Applies CORS to
/export,/graphql/stream, and/graphql. - Updates documentation and adds CORS tests.
File summaries
| File | Summary | Review findings |
|---|---|---|
test/cors.test.js |
Tests parsing and origin behavior. | Moderate: add integration coverage for allowed and denied origins on all three production mounts (2 votes). |
src/index.js |
Applies shared CORS configuration to all three mounts. | Moderate: test the production app or an extracted app factory to prevent middleware regressions (1 vote). |
src/config/cors.js |
Builds deny-by-default CORS options. | Nit: reject wildcard entries and add a regression test (1 vote). |
README.md |
Documents configuration and defaults. | No findings. |
Review details
Suppressed comments (2)
src/config/cors.js:13
- Filtering only blanks leaves
*as a permitted entry. WithCORS_ALLOWED_ORIGINS='*'and anOrigin: *request, the callback returns['*'], which thecorsmiddleware treats as a matching origin and can emitAccess-Control-Allow-Origin: *, contradicting the documented invariant that the wildcard is never emitted. Reject wildcard entries and add a regression test for this configuration.
.filter(Boolean);
src/index.js:49
- The new test exercises
loadCorsOptionsonly on a throwaway/probeapp; it never starts the application wired insrc/index.js. Reverting any of these three mounts to barecors()would therefore leave the tests green while reintroducing the vulnerability. Please add an integration test around the production app (or an extracted app factory) that checks allowed and denied origins on/graphql,/graphql/stream, and/export.
cors(corsOptions),
createExportRouter({ store, finance: financeService, logger })
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: charles2ke <6725706+charles2ke@users.noreply.github.com>
Co-authored-by: charles2ke <6725706+charles2ke@users.noreply.github.com>
Co-authored-by: charles2ke <6725706+charles2ke@users.noreply.github.com>
…sert status Co-authored-by: charles2ke <6725706+charles2ke@users.noreply.github.com>
…igin header Co-authored-by: charles2ke <6725706+charles2ke@users.noreply.github.com>
charles2ke
approved these changes
Sep 16, 2026
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.
All three HTTP mounts used bare
cors(), emittingAccess-Control-Allow-Origin: *. Combined withGET /graphql/streamtakingqueryfrom the query string — a CORS "simple" request with no preflight — any page could read GraphQL results from a reachable instance. The allow-list was only documented in the README, never enforced.Changes
src/config/cors.js(new) —loadCorsOptions(env)builds thecors()options fromCORS_ALLOWED_ORIGINS(comma-separated). An allowedOriginis echoed back verbatim; anything else gets no CORS headers, so the browser blocks the response. The wildcard is never emitted.Originheader (curl, server-to-server) pass through untouched.src/index.js— builds the options once and applies them to/export,/graphql/stream, and/graphql.README.md— CORS section now documents the actual mechanism (env var + wiring) instead of stating an expectation;CORS_ALLOWED_ORIGINSadded to the config table.test/cors.test.js(new) — allow-list parsing, allowed vs. denied origin headers, missingOrigin, and the deny-all default.Note the deny-by-default is a behavior change for any existing browser client relying on the previous wildcard; those origins need to be listed explicitly.