Skip to content

chore(web): restrict the dev Vite server's CORS to the configured origins - #2789

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/chore/2752-dev-vite-cors
Oct 25, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/chore/2752-dev-vite-cors

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2752

In --dev mode Vite used its default server.cors, which reflects any localhost / 127.0.0.1 / [::1] origin on any port. This sets it from the same allowedOrigins the backend's origin guard enforces.

  • server/vite-base-config.ts — new getViteDevCors(allowedOrigins) helper, shared because the in-process starter can't load vite.config.ts.
  • vite.config.ts — server.cors from devConfig.allowedOrigins when serving; Vite's default for build/vitest, which have no devConfig.
  • server/start-vite-dev-server.ts — the same, from config.allowedOrigins.
  • Unit tests for the helper in src/test/integration/server/vite-base-config.test.ts.

Vite installs its CORS middleware ahead of every configureServer middleware, so it also answers /api/* before the Hono plugin; using one list keeps the two consistent.

Verified by hand against vite on CLIENT_PORT=6391:

Origin GET /src/main.tsx ACAO OPTIONS /api/config ACAO
http://localhost:6391 (configured) reflected reflected
http://localhost:5555 (other loopback port) absent (was reflected) absent

npm run local:gate green. Dev-only; the published app is unaffected.

🤖 Generated with Claude Code

…gins (#2752)

Vite's default server.cors reflects any localhost / 127.0.0.1 / [::1]
origin on any port. Set it from the same allowedOrigins the backend's
origin guard enforces, in both vite.config.ts and the in-process
start-vite-dev-server.ts, via a shared getViteDevCors helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Oct 25, 2026
@cliffhall
cliffhall requested a balanced review from Copilot October 25, 2026 01:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Both development entry points consistently apply the configured origin list, with focused tests and no identified blocking issues.

No open issues 🎉

What changed in this PR

Restricts the web client's development-server CORS policy to Inspector’s configured origins, addressing #2752 without changing the published app.

Changes:

  • Applies the same origin allow-list to both Vite development startup paths.
  • Adds a shared helper that defensively copies the configured origins.
  • Adds unit tests for the returned CORS configuration and copy isolation.
File Description
clients/​web/​vite.config.ts Sets CORS from configured origins during development serving.
clients/​web/​src/​test/​integration/​server/​vite-base-config.test.ts Tests the origin configuration and defensive copy.
clients/​web/​server/​vite-base-config.ts Adds the shared development CORS helper.
clients/​web/​server/​start-vite-dev-server.ts Applies the same CORS policy to in-process development startup.

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 1 was clean (approval recommended, no inline comments, nothing suppressed), so no further round was requested.

@cliffhall
cliffhall merged commit 8bc3362 into v2/main Oct 25, 2026
11 checks passed
@cliffhall
cliffhall deleted the v2/chore/2752-dev-vite-cors branch October 25, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restrict the dev Vite server's CORS to the Inspector's configured origins

2 participants