Repository navigation
chore(web): restrict the dev Vite server's CORS to the configured origins - #2789
Merged
Merged
Conversation
…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]>
There was a problem hiding this comment.
🟢 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
Member
Author
|
Copilot review loop closed: round 1 was clean (approval recommended, no inline comments, nothing suppressed), so no further round was requested. |
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.
Closes #2752
In
--devmode Vite used its defaultserver.cors, which reflects anylocalhost/127.0.0.1/[::1]origin on any port. This sets it from the sameallowedOriginsthe backend's origin guard enforces.server/vite-base-config.ts— newgetViteDevCors(allowedOrigins)helper, shared because the in-process starter can't loadvite.config.ts.vite.config.ts—server.corsfromdevConfig.allowedOriginswhen serving; Vite's default for build/vitest, which have nodevConfig.server/start-vite-dev-server.ts— the same, fromconfig.allowedOrigins.src/test/integration/server/vite-base-config.test.ts.Vite installs its CORS middleware ahead of every
configureServermiddleware, so it also answers/api/*before the Hono plugin; using one list keeps the two consistent.Verified by hand against
viteon CLIENT_PORT=6391:GET /src/main.tsxACAOOPTIONS /api/configACAOhttp://localhost:6391(configured)http://localhost:5555(other loopback port)npm run local:gategreen. Dev-only; the published app is unaffected.🤖 Generated with Claude Code