Skip to content

fix(#231): consolidate CORS to a single same-origin-default policy#236

Open
husamql3 wants to merge 1 commit into
stagefrom
fix/#231-consolidate-cors
Open

fix(#231): consolidate CORS to a single same-origin-default policy#236
husamql3 wants to merge 1 commit into
stagefrom
fix/#231-consolidate-cors

Conversation

@husamql3

@husamql3 husamql3 commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Collapsed two overlapping CORS mechanisms into one — the server called Hono's cors() and then a second middleware that hard-set Access-Control-Allow-Origin: * on every response. Two mechanisms is a correctness hazard and the wildcard grants cross-origin access the app never needs (the SPA is served same-origin as the API).
  • Default is now same-origin; cross-origin is opt-in via ALLOWED_ORIGINS — with no allowlist configured, no allow-origin header is emitted for cross-origin requests. Deployments serving the SPA from a different origin set ALLOWED_ORIGINS to an explicit comma-separated list (never *).
  • Updated CORS test assertions to the new policy — 12 server test files asserted the old wildcard; they now assert no allow-origin for a disallowed/no-origin request, plus new preflight (OPTIONS) coverage and a disallowed-cross-origin case.

Testing

  1. cd packages/server && bun run test → 998 tests pass
  2. bun run typecheck, bun run format, bun run build → pass

Closes #231

Glossary

Term Definition
CORS Browser mechanism controlling which origins may read cross-origin responses.
Same-origin default Emitting no allow-origin header so only the same-origin page can call the API.
ALLOWED_ORIGINS New env var: comma-separated explicit origins permitted cross-origin access.

- Remove the manual "*"-echoing CORS middleware; keep one mechanism
- Configure hono/cors with an empty-by-default origin allowlist
  (ALLOWED_ORIGINS env, comma-separated) so cross-origin requests get
  no Access-Control-Allow-Origin header -> same-origin only
- Prevents drive-by-localhost: any other browser tab can no longer
  issue cross-origin reads/edits/drops against the user's DB
- Update server CORS tests to assert the new policy (no allow-origin
  for a cross-origin/no-origin request; methods/headers advertised on
  preflight)
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@husamql3, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 905426bb-0f12-4bfa-a002-b84175eb8249

📥 Commits

Reviewing files that changed from the base of the PR and between b86b1de and e7d44f1.

📒 Files selected for processing (13)
  • packages/server/src/utils/create-server.ts
  • packages/server/tests/routes/databases.routes.test.ts
  • packages/server/tests/routes/mongodb/databases.routes.mongodb.test.ts
  • packages/server/tests/routes/mssql/databases.routes.mssql.test.ts
  • packages/server/tests/routes/mssql/tables.routes.mssql.test.ts
  • packages/server/tests/routes/mysql/databases.routes.mysql.test.ts
  • packages/server/tests/routes/mysql/query.routes.mysql.test.ts
  • packages/server/tests/routes/mysql/records.routes.mysql.test.ts
  • packages/server/tests/routes/mysql/tables.routes.mysql.test.ts
  • packages/server/tests/routes/query.routes.test.ts
  • packages/server/tests/routes/records.routes.test.ts
  • packages/server/tests/routes/tables.routes.test.ts
  • packages/server/tests/utils/create-server.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/#231-consolidate-cors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Bundle Size

packages/server/dist788K

File breakdown
172K	packages/server/dist/index.js
612K	packages/server/dist/index.js.map

packages/web/dist64M

File breakdown
56K	packages/web/dist/assets/_pathlessLayout-BByrt-IV.js
1.2M	packages/web/dist/assets/_pathlessLayout-BByrt-IV.js.map
4.0K	packages/web/dist/assets/_pathlessLayout-BULBsQ9r.js
4.0K	packages/web/dist/assets/_pathlessLayout-BULBsQ9r.js.map
4.0K	packages/web/dist/assets/_queryId-cyxa5wMS.js
4.0K	packages/web/dist/assets/_queryId-cyxa5wMS.js.map
4.0K	packages/web/dist/assets/_table-B0yPxctF.js
4.0K	packages/web/dist/assets/_table-B0yPxctF.js.map
4.0K	packages/web/dist/assets/_table-DwIZYs3U.js
4.0K	packages/web/dist/assets/_table-DwIZYs3U.js.map
28K	packages/web/dist/assets/bundle-mjs-BC_8HrWA.js
140K	packages/web/dist/assets/bundle-mjs-BC_8HrWA.js.map
444K	packages/web/dist/assets/chunk-BO2N2NFS-D1cKzRy7.js
1.7M	packages/web/dist/assets/chunk-BO2N2NFS-D1cKzRy7.js.map
8.0K	packages/web/dist/assets/code-editor-D1LiAEIU.js
20K	packages/web/dist/assets/code-editor-D1LiAEIU.js.map
120K	packages/web/dist/assets/codicon-ngg6Pgfi.ttf
1.3M	packages/web/dist/assets/css.worker-A3810hic.js
3.2M	packages/web/dist/assets/css.worker-A3810hic.js.map
36K	packages/web/dist/assets/dist-m8A6NETj.js
88K	packages/web/dist/assets/dist-m8A6NETj.js.map
56K	packages/web/dist/assets/format-cell-value-BDLw73u3.js
232K	packages/web/dist/assets/format-cell-value-BDLw73u3.js.map
4.0K	packages/web/dist/assets/highlighted-body-OFNGDK62-NogKB3ej.js
4.0K	packages/web/dist/assets/highlighted-body-OFNGDK62-NogKB3ej.js.map
860K	packages/web/dist/assets/html.worker-DUbSWKmN.js
2.2M	packages/web/dist/assets/html.worker-DUbSWKmN.js.map
20K	packages/web/dist/assets/icons-B5bSDd0r.js
88K	packages/web/dist/assets/icons-B5bSDd0r.js.map
124K	packages/web/dist/assets/index-B-VrElCM.css
460K	packages/web/dist/assets/index-DRNEODC_.js
1.9M	packages/web/dist/assets/index-DRNEODC_.js.map
4.0K	packages/web/dist/assets/indexes-CBb_pYf_.js
4.0K	packages/web/dist/assets/indexes-CBb_pYf_.js.map
12K	packages/web/dist/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2
12K	packages/web/dist/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2
16K	packages/web/dist/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2
40K	packages/web/dist/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2
8.0K	packages/web/dist/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2
516K	packages/web/dist/assets/json.worker-qcFW0tBA.js
1.7M	packages/web/dist/assets/json.worker-qcFW0tBA.js.map
4.0K	packages/web/dist/assets/logs-BDeicfXz.js
4.0K	packages/web/dist/assets/logs-BDeicfXz.js.map
4.0K	packages/web/dist/assets/mermaid-GHXKKRXX-kUDCGRaV.js
4.1M	packages/web/dist/assets/monaco-editor-DJLWokZr.js
15M	packages/web/dist/assets/monaco-editor-DJLWokZr.js.map
140K	packages/web/dist/assets/monaco-editor-DVSAlpqy.css
200K	packages/web/dist/assets/monitoring-Dw3KwoPJ.js
512K	packages/web/dist/assets/monitoring-Dw3KwoPJ.js.map
4.0K	packages/web/dist/assets/queries.store-DvaENLe7.js
8.0K	packages/web/dist/assets/queries.store-DvaENLe7.js.map
12K	packages/web/dist/assets/query-runner-D4jp77L6.js
32K	packages/web/dist/assets/query-runner-D4jp77L6.js.map
148K	packages/web/dist/assets/radix-ui-DS4zDRqg.js
672K	packages/web/dist/assets/radix-ui-DS4zDRqg.js.map
176K	packages/web/dist/assets/react-dom-DafrnciU.js
784K	packages/web/dist/assets/react-dom-DafrnciU.js.map
4.0K	packages/web/dist/assets/rolldown-runtime-b3L32Ng1.js
4.0K	packages/web/dist/assets/runner-EqOuNKQH.js
4.0K	packages/web/dist/assets/runner-EqOuNKQH.js.map
4.0K	packages/web/dist/assets/schema-4dGwYfjY.js
4.0K	packages/web/dist/assets/schema-4dGwYfjY.js.map
4.0K	packages/web/dist/assets/table-voW5jQda.js
4.0K	packages/web/dist/assets/table-voW5jQda.js.map
276K	packages/web/dist/assets/tanstack-BfO3BbGk.js
1.1M	packages/web/dist/assets/tanstack-BfO3BbGk.js.map
7.8M	packages/web/dist/assets/ts.worker-BmSK7P1D.js
17M	packages/web/dist/assets/ts.worker-BmSK7P1D.js.map
4.0K	packages/web/dist/assets/visualizer-s3AQxGwZ.js
4.0K	packages/web/dist/assets/visualizer-s3AQxGwZ.js.map
104K	packages/web/dist/image.png
4.0K	packages/web/dist/index.html

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.

fix(server): consolidate CORS to a single same-origin-default policy

1 participant