Repository navigation
fix(security): keep the local dev profile reachable from this machine only - #236
Merged
Merged
Conversation
… only The Vite dev server of `npm run dev:full` listened on all interfaces (`server.host: true`) and proxied /api and /ws to the loopback-only backend, which runs sketches as native processes in local mode. Vite admits every IP Host header, and the local WebSocket verifier accepted an Origin equal to Host and any upgrade without Origin, so a LAN client could start native sketch execution on the developer's machine. The backend checked no Host header at all, so a DNS rebinding page whose host name resolves to 127.0.0.1 could do the same from any website. - Vite listens on 127.0.0.1 only. - In local mode the backend accepts HTTP requests and WebSocket upgrades only for Host `localhost` or a numeric loopback address. - A WebSocket upgrade without Origin is accepted only from a loopback peer. - UNOSIM_UNSAFE_ALLOW_EXTERNAL_LOCAL_BIND keeps its explicit meaning and lifts these checks; gateway mode and the Docker profile are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
In the local dev profile (
npm run dev:full), sketches run as native processes on the developer's machine. Two paths let other clients reach that:server.host: true) and proxied/apiand/wsto the loopback-only backend. Vite accepts every IPHostheader. The local WebSocket verifier accepted anOriginequal toHost, and also any upgrade withoutOrigin.Hostheader. A page whose host name resolves to127.0.0.1could therefore use the backend on port 3000 from any website.Change
vite.config.ts:server.host: "127.0.0.1".createLocalHostGuardruns before every route and static file. It accepts onlyHost: localhostor a numeric loopback address (any port); everything else gets 403.Originis accepted only from a loopback peer.UNOSIM_UNSAFE_ALLOW_EXTERNAL_LOCAL_BIND=truekeeps its explicit meaning and also lifts these checks.docs/SECURITY.mdanddocs/INSTALL_LOCAL.md.Tests
tests/server/security/access-control.test.ts:Origin.Origin/Hostpair is allowed.tests/server/vite-config.test.ts: Vite binds loopback.Verification
npm run check,npm run test:unit(3045 passed),npm run check:docs, knip,git diff --check,./run-tests.sh(11/11 incl. Docker, E2E, Sonar gate) all pass.npm run dev:full:127.0.0.1only; the LAN IP refuses connections.evil.exampleand the LAN IP: HTTP and WS get 403.localhostbrowser path via the Vite proxy (HTTP + WS) works.🤖 Generated with Claude Code