Skip to content

fix(bin): host-check the seat board so a DNS-rebinding page cannot read it - #28

Merged
max-metaplanet merged 3 commits into
mainfrom
fm/seat-board-dns-rebinding
Oct 6, 2026
Merged

max-metaplanet merged 3 commits into
mainfrom
fm/seat-board-dns-rebinding

Conversation

@max-metaplanet

Copy link
Copy Markdown
Owner

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.1 on 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

  • Adds bin/fm-seat-board-server.py, which replaces python3 -m http.server for bin/fm-seat-board.sh serve. It still binds 127.0.0.1, and now also:
    • answers only when the Host header is exactly 127.0.0.1:<port> or localhost:<port>, and returns a 403 with no page content for anything else;
    • serves the page only under a random path token generated for each run (any other path gets a 404);
    • serves that one page and nothing else, over GET and HEAD only.
  • fm-seat-board.sh serve now 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 0 lets the kernel pick one. docs/claude-seats.md and the script header now describe this rebinding defence.
  • tests/fm-seat-board.test.sh gains 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.sh now 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 serve on 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 an unbound variable message that base f8c8cf0 also prints. Overall: pass.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Operator runs serve and opens the printed URL: board renders with seat email, quota and extra-usage spend ✅ pass live board-printed-url-200.png; live-host-check-transcript.txt (200 for 127.0.0.1:<port>, localhost:<port> and LOCALHOST:<port>)
Rebinding page: browser on a foreign domain that resolves to 127.0.0.1 loads and fetches the board, gets 403 and no seat data ✅ pass live board-rebinding-origin-403.png (127.0.0.1.nip.io, fetch status 403, contains seat email: false); curl --resolve attacker.example → 403 in live-host-check-transcript.txt
Adversarial Host values (no port, :80, wrong port, rebinding-service name, empty Host, HEAD with a foreign Host) are all refused ✅ pass live live-host-check-transcript.txt: every case 403
Per-run token: the root path, /index.html, a guessed token and path traversal return 404 even with a loopback Host ✅ pass live live-host-check-transcript.txt: 404 for each
Server listens on loopback only ✅ pass live lsof in live-host-check-transcript.txt: TCP 127.0.0.1:<port> (LISTEN)
Ctrl-C stops the server, frees the port and removes the scratch page directory ✅ pass live live-ctrl-c-shutdown.txt: no listener, docroot removed (the stderr unbound-variable message also appears on base)

Board served at the printed tokenised URL (200)

Evidence: Live curl transcript: Host check, path token, methods, bind address

Source: Live curl transcript: Host check, path token, methods, bind address

\### printed URL: http://127.0.0.1:58527/UyZjl892838GS2dKGsZ1m9RO/
\### GET http://127.0.0.1:58527/UyZjl892838GS2dKGsZ1m9RO/
200
\### GET http://localhost:58527/UyZjl892838GS2dKGsZ1m9RO/
200
\### GET http://LOCALHOST:58527/UyZjl892838GS2dKGsZ1m9RO/
200
\### body contains seat email via printed URL?
[email protected]
\### DNS rebinding: attacker.example resolved to 127.0.0.1 (curl --resolve), same port+token
HTTP/1.0 403 Forbidden
Server: fm-seat-board 
Date: Tue, 06 Oct 2026 11:30:10 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 55
Cache-Control: no-store
X-Content-Type-Options: nosniff

Host not allowed: this board answers on loopback only.

\### Host header 127.0.0.1 without port
HTTP/1.0 403 Forbidden
Server: fm-seat-board 
Date: Tue, 06 Oct 2026 11:30:10 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 55
Cache-Control: no-store
X-Content-Type-Options: nosniff

Host not allowed: this board answers on loopback only.

\### Host header localhost:80
403
\### Host 127.0.0.1 with wrong port
403
\### Host 127.0.0.1.nip.io:58527 (rebinding service style)
403
\### Missing Host header (HTTP/1.0)
403
\### Right host, root path
HTTP/1.0 404 Not Found
Server: fm-seat-board 
Date: Tue, 06 Oct 2026 11:30:10 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 59
Cache-Control: no-store
X-Content-Type-Options: nosniff

Not found: open the URL fm-seat-board.sh printed on start.

\### Right host, /index.html
404
\### Right host, guessed token
404
\### Path traversal
404
\### Token with query string
200
\### POST to token
501
\### HEAD with right host
HTTP/1.0 200 OK
Server: fm-seat-board 
Date: Tue, 06 Oct 2026 11:30:10 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1262
Cache-Control: no-store
X-Content-Type-Options: nosniff

\### HEAD with rebinding host
HTTP/1.0 403 Forbidden
Server: fm-seat-board 
Date: Tue, 06 Oct 2026 11:30:10 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 55
Cache-Control: no-store
X-Content-Type-Options: nosniff

\### Remote interface: bind check
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Python  44513  max    3u  IPv4 0x714ee4693f3f41c6      0t0  TCP 127.0.0.1:58527 (LISTEN)
Evidence: Ctrl-C shutdown transcript

Source: Ctrl-C shutdown transcript

before: docroot=/var/folders/1l/gg6b5zsx0qn753wwhcmmq8cr0000gn/T//fm-seat-board.UiQmOB exists=yes
  PID COMMAND
44395 bash bin/fm-seat-board.sh serve --port 0
44512 bash bin/fm-seat-board.sh serve --port 0
44513 /opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/Resources/Python.app/Contents/MacOS/Python ~/.no-mistakes/worktrees/61c6dd39b831/01M48FCYNPB66EXBQ9XRAFCDC7/bin/fm-seat-board-server.py 0 /var/folders/1l/gg6b5zsx0qn753wwhcmmq8cr0000gn/T//fm-seat-board.UiQmOB/index.html
44514 sleep 60
\### kill -INT -44395 (Ctrl-C to the foreground process group)
\### processes in group after:
  PID COMMAND
44514 sleep 60
\### listener on 58527 after:
(none)
\### docroot exists after: no
\### serve.log:
Seat board: http://127.0.0.1:58527/UyZjl892838GS2dKGsZ1m9RO/
Ctrl-C to stop.
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 200 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 200 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 200 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 200 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.0" 403 -
fm-seat-board: "GET / HTTP/1.1" 404 -
fm-seat-board: "GET /index.html HTTP/1.1" 404 -
fm-seat-board: "GET /AAAAAAAAAAAAAAAAAAAAAAAA/ HTTP/1.1" 404 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO//../../etc/passwd HTTP/1.1" 404 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/?x=1 HTTP/1.1" 200 -
fm-seat-board: code 501, message Unsupported method ('POST')
fm-seat-board: "POST /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 501 -
fm-seat-board: "HEAD /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 200 -
fm-seat-board: "HEAD /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 200 -
fm-seat-board: "GET /favicon.ico HTTP/1.1" 404 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
fm-seat-board: "GET /favicon.ico HTTP/1.1" 403 -
fm-seat-board: "GET /UyZjl892838GS2dKGsZ1m9RO/ HTTP/1.1" 403 -
bin/fm-seat-board.sh: line 368: docroot: unbound variable
Evidence: Targeted fm-seat-board test run

Source: Targeted fm-seat-board test run

ok - render shows the default seat and marks it active
ok - render lists a named seat with its windows and extra-usage spend
ok - render shows an attention line for a seat that is not logged in
ok - render shows a rate-limited seat's error as-is
ok - a reload within the cache window does not read quota-axi again
ok - render reads quota-axi without refreshing or prompting for credentials
ok - the cache is scoped to each seat's config dir, not its name
ok - render escapes markup in quota-axi text
ok - serve rejects a missing or non-numeric port
ok - json reports every seat with its own cache age and the window those ages are judged against
ok - json marks the active seat, the live seat, and a seat held out of automatic rotation
ok - json reports a seat with no usable report as absent rather than as a zero
ok - json --cached-only reports an empty cache as no data and never reads quota-axi
ok - json --cached-only serves an expired cached report with its real age, so a reader can call it stale
ok - json rejects an unknown flag
ok - serve answers a loopback Host and refuses a rebinding page's foreign Host
ok - serve serves the board only under the per-run path token it printed
ok - stopping serve leaves nothing listening on its port
# all fm-seat-board tests passed
- Outcome: ⚠️ 1 info across 1 run (2m34s)

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_hosts also accepts a bare 127.0.0.1 or localhost Host header when the port is 80. The intent asks for 127.0.0.1 or localhost with 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 exact host:port match only: drop the if port == 80 branch.
  • ℹ️ 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 its except KeyboardInterrupt branch never runs on this path. Shutdown still works, because bash's trap cleanup INT interrupts wait and sends SIGTERM to srv_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.

⚠️ **Test** - 1 info
  • ℹ️ bin/fm-seat-board.sh:368 - Ctrl-C on fm-seat-board.sh serve still prints docroot: unbound variable on stderr. The EXIT trap runs cleanup after cmd_serve returns, and by then its local docroot is 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. The sleep child of the regenerate loop also outlives the run until its 60s timer ends, which is also unchanged from base.
  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Operator runs serve and opens the printed URL: board renders with seat email, quota and extra-usage spend ✅ pass live board-printed-url-200.png; live-host-check-transcript.txt (200 for 127.0.0.1:<port>, localhost:<port> and LOCALHOST:<port>)
Rebinding page: browser on a foreign domain that resolves to 127.0.0.1 loads and fetches the board, gets 403 and no seat data ✅ pass live board-rebinding-origin-403.png (127.0.0.1.nip.io, fetch status 403, contains seat email: false); curl --resolve attacker.example → 403 in live-host-check-transcript.txt
Adversarial Host values (no port, :80, wrong port, rebinding-service name, empty Host, HEAD with a foreign Host) are all refused ✅ pass live live-host-check-transcript.txt: every case 403
Per-run token: the root path, /index.html, a guessed token and path traversal return 404 even with a loopback Host ✅ pass live live-host-check-transcript.txt: 404 for each
Server listens on loopback only ✅ pass live lsof in live-host-check-transcript.txt: TCP 127.0.0.1:<port> (LISTEN)
Ctrl-C stops the server, frees the port and removes the scratch page directory ✅ pass live live-ctrl-c-shutdown.txt: no listener, docroot removed (the stderr unbound-variable message also appears on base)
  • bash tests/fm-seat-board.test.sh (targeted file, including the new real-server host-check, path-token and stop tests)
  • Live bin/fm-seat-board.sh serve --port 0 with a fake quota-axi on PATH, in its own process group
  • curl against the printed URL with Host 127.0.0.1:<port>, localhost:<port> and LOCALHOST:<port>
  • curl --resolve attacker.example:&lt;port&gt;:127.0.0.1 rebinding 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 Host
  • curl 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)
  • lsof check that the server binds 127.0.0.1 only
  • Playwright 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 dir
  • The 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.

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.
@max-metaplanet
max-metaplanet merged commit b0b1915 into main Oct 6, 2026
21 checks passed
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.

1 participant