Repository navigation
fix(bin): host-check the seat board so a DNS-rebinding page cannot read it - #28
Merged
Merged
Conversation
The board served its page with `python3 -m http.server --bind 127.0.0.1`, and that module validates no Host header. Binding loopback stops a remote connection but not DNS rebinding: a hostile page whose own domain is re-pointed at 127.0.0.1 is same-origin to the browser, so it could read a board that shows every seat's account email, quota windows, extra-usage spend and which seat is active. bin/fm-seat-board-server.py replaces that invocation. It answers only when the request's Host header is exactly 127.0.0.1 or localhost with its own port, refusing anything else with 403 and no page content, and serves the page only under a random per-run path segment named in the URL it prints. It serves that one page under GET and HEAD alone, so there is no path translation and no second file to reach. The loopback bind, the read-only behaviour, the printed output and the --port flag are unchanged; --port 0 now takes a free port from the kernel and names it in that URL, which is what lets the tests drive a real server. Stopping the board now also stops that server, instead of orphaning it on the port.
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.
Intent
Fix seat-board-dns-rebinding as a security ship on the fork: bind and host-check the seat board so a rebinding page cannot read it - for example, reject requests whose Host header is not 127.0.0.1 or localhost with the board's port - plus a per-run token if cheap.
Full pipeline, merge when green.
Independent of the upstream sync; land it before or re-pick it into the sync branch.
The finding: bin/fm-seat-board.sh serves its page with
python3 -m http.server "$port" --bind 127.0.0.1on default port 4405 until Ctrl-C, and python's http.server validates no Host header.Binding loopback stops remote connections but not DNS rebinding: a hostile page whose domain is re-pointed at 127.0.0.1 is same-origin to the browser and can read the board, which shows each seat's account email, quota windows, extra-usage spend and which seat is active.
No credential or token is served; the board is opt-in, started by hand and short-lived; severity is low.
What Changed
bin/fm-seat-board-server.py, which replacespython3 -m http.serverforbin/fm-seat-board.sh serve. It still binds 127.0.0.1, and now also:Hostheader is exactly127.0.0.1:<port>orlocalhost:<port>, and returns a 403 with no page content for anything else;fm-seat-board.sh servenow starts this server in the background and stops it from the Ctrl-C cleanup trap. The server prints the URL to open, including the token and the real port when--port 0lets the kernel pick one.docs/claude-seats.mdand the script header now describe this rebinding defence.tests/fm-seat-board.test.shgains three tests: a loopback Host is accepted and a rebinding Host is refused, the board is served only under the printed token, and nothing is left listening on the port after serve stops.bin/fm-test-run.shnow runs that test file when the new server script changes.Risk Assessment
✅ Low: This is a small, opt-in loopback server that does what the intent asks: it requires an exact Host of 127.0.0.1 or localhost with its own port and serves only under a random per-run path. Both earlier findings are fixed in the current code (the port-80 bare-host branch is gone and the Ctrl-C comment is now accurate), and the new tests exercise a real server process instead of matching source text.
Testing
I ran the targeted seat-board test file (all pass) and then started a real
fm-seat-board.sh serveon a kernel-chosen port with a fake quota-axi. The printed URL served the board with 200 in curl and in a real browser (screenshot), for both 127.0.0.1 and localhost Hosts. Every foreign or malformed Host got 403 with no page content: a curl --resolve rebinding request, a missing port, port 80, the wrong port, a nip.io name and an empty Host. In Chromium, a page on 127.0.0.1.nip.io (a public name that resolves to loopback) got 403 on both load and a same-origin fetch, with no seat email returned (screenshot). Without the token, the root path, /index.html and a guessed token all got 404, and path traversal got 404 too. Ctrl-C stopped the server, closed the port and removed the scratch directory. The only stderr noise was anunbound variablemessage that base f8c8cf0 also prints. Overall: pass.Evidence: Live curl transcript: Host check, path token, methods, bind address
Source: Live curl transcript: Host check, path token, methods, bind address
Evidence: Ctrl-C shutdown transcript
Source: Ctrl-C shutdown transcript
Evidence: Targeted fm-seat-board test run
Source: Targeted fm-seat-board test run
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
bin/fm-seat-board-server.py:53-allowed_hostsalso accepts a bare127.0.0.1orlocalhostHost header when the port is 80. The intent asks for127.0.0.1orlocalhostwith the board's port, so this second, port-less way to match goes further than required. The port is 4405 by default or kernel-chosen in the tests, and binding port 80 needs root, so this path is almost never reached. The narrower form is the exacthost:portmatch only: drop theif port == 80branch.bin/fm-seat-board.sh:381- The comment says Ctrl-C still reaches the backgrounded server directly, which is wrong. A non-interactive bash without job control starts background commands with SIGINT ignored. Python sees that at startup and does not install its KeyboardInterrupt handler, so the server ignores Ctrl-C and itsexcept KeyboardInterruptbranch never runs on this path. Shutdown still works, because bash'strap cleanup INTinterruptswaitand sends SIGTERM tosrv_pid. Fix the comment to say Ctrl-C is handled by the INT trap, which stops the server.🔧 Fix applied.
✅ Re-checked - no issues remain.
bin/fm-seat-board.sh:368- Ctrl-C onfm-seat-board.sh servestill printsdocroot: unbound variableon stderr. The EXIT trap runscleanupaftercmd_servereturns, and by then its localdocrootis gone. The base commit f8c8cf0 prints the same message, so this change did not cause it, and shutdown still works: the server stops, the port closes and the scratch directory is removed. Thesleepchild of the regenerate loop also outlives the run until its 60s timer ends, which is also unchanged from base.bash tests/fm-seat-board.test.sh(targeted file, including the new real-server host-check, path-token and stop tests)Livebin/fm-seat-board.sh serve --port 0with a fake quota-axi on PATH, in its own process groupcurl against the printed URL with Host 127.0.0.1:<port>, localhost:<port> and LOCALHOST:<port>curl --resolve attacker.example:<port>:127.0.0.1rebinding shape, plus the Host values 127.0.0.1 (no port), localhost:80, wrong port, 127.0.0.1.nip.io:<port> and an empty Hostcurl to the root path, /index.html, a guessed token and a path-traversal attempt; also a query string, POST and HEAD (right and foreign Host)lsofcheck that the server binds 127.0.0.1 onlyPlaywright Chromium opening the printed URL (screenshot) and http://127.0.0.1.nip.io:<port>/<token>/ with a same-origin fetch (screenshot)SIGINT to the serve process group (as Ctrl-C does), then checked processes, listener and scratch dirThe same Ctrl-C on base f8c8cf0 to compare the stderr message✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.