the server binds every interface, has no auth, and its WebSocket answers any Origin #1527

Closed
opened 2026-11-15 18:01:16 +00:00 by jaylouisw · 2 comments
Owner

Verified today, and recorded as a precondition rather than a surprise:

  • server/index.js:765 calls server.listen(PORT) with no host, so Node binds all interfaces.
  • A grep for authoriz|authenticat|api_key|passw|secret|token across server/ and engine/ returns no security-related hits.
  • The WebSocket is attached with server.on('upgrade') at server/index.js:715, calls wss.handleUpgrade, and immediately pushes full topology state - with no Origin check, no Host check and no token. So any LAN host, and any web page Jay visits, can open it and read the whole object graph.

This is a deliberate, documented posture for a simulator of fictional devices, and README.md / ARCHITECTURE.md / PUBLIC-ACCESS.md say so. It stops being acceptable the moment the process holds real device credentials, which is next.

Requested: before any credential is stored, (1) default the bind to loopback with an explicit --host opt-out, (2) validate Origin on the WebSocket upgrade, and (3) put the credential-handling surface behind a bearer token. The public demo can keep its own posture via configuration.

Filed because the credential store design (w9) names this as its precondition, not because the current behaviour was unintended.

Verified today, and recorded as a precondition rather than a surprise: * `server/index.js:765` calls `server.listen(PORT)` with no host, so Node binds all interfaces. * A grep for `authoriz|authenticat|api_key|passw|secret|token` across `server/` and `engine/` returns no security-related hits. * The WebSocket is attached with `server.on('upgrade')` at `server/index.js:715`, calls `wss.handleUpgrade`, and immediately pushes full topology state - with no Origin check, no Host check and no token. So any LAN host, **and any web page Jay visits**, can open it and read the whole object graph. This is a deliberate, documented posture for a simulator of fictional devices, and `README.md` / `ARCHITECTURE.md` / `PUBLIC-ACCESS.md` say so. It stops being acceptable the moment the process holds real device credentials, which is next. **Requested:** before any credential is stored, (1) default the bind to loopback with an explicit `--host` opt-out, (2) validate `Origin` on the WebSocket upgrade, and (3) put the credential-handling surface behind a bearer token. The public demo can keep its own posture via configuration. Filed because the credential store design (w9) names this as its precondition, not because the current behaviour was unintended.
Author
Owner

Item 1 of this issue - the bind - is up as PR #1639, branch fix/1116-0835 @ 64e2fa86.

What landed: PF_HOST, default 127.0.0.1; the banner prints what server.address() reports and whether the socket is on this machine only or reachable from other hosts (it used to print localhost whatever had been bound); Dockerfile sets PF_HOST=0.0.0.0 so docker run -p 8000:8000 keeps working. A PF_HOST this machine does not own now exits 1 naming that value and the variable - the old EADDRNOTAVAIL text blamed PORT and advised leaving it "unset to listen on all interfaces", which was false on both counts.

Evidence: test/server-bind.test.js (23 assertions) spawns the real server four ways - default answers on 127.0.0.1 and nothing accepts on the machine's first non-loopback IPv4; 0.0.0.0 does accept there; 192.0.2.123 (TEST-NET-1) exits 1 with a message naming it and no stack trace; 127.0.0.1:<port> is named as the copied-from-a-URL mistake. npm test at the committed tree: 276 suites, 9873 assertions, 0 failed. Syntax check 346 files.

Still open, deliberately: item 2 (WebSocket Origin) landed in #1629. Item 3 - the bearer token - is not in this PR and not in the plan: there is no credential store to guard yet (grep -ri credential engine/ server/ finds nothing), so a token today would protect nothing and would have to be redone once the store exists. It needs its own plan and a decision from Jay on how the UI authenticates. Steps 3-5 of docs/plans/server-exposure.md (narrow CORS, drop the unsolicited board push, docs) are also still a plan.

Item 1 of this issue - the bind - is up as PR #1639, branch `fix/1116-0835` @ `64e2fa86`. **What landed:** `PF_HOST`, default `127.0.0.1`; the banner prints what `server.address()` reports and whether the socket is on this machine only or reachable from other hosts (it used to print `localhost` whatever had been bound); `Dockerfile` sets `PF_HOST=0.0.0.0` so `docker run -p 8000:8000` keeps working. A `PF_HOST` this machine does not own now exits 1 naming that value and the variable - the old `EADDRNOTAVAIL` text blamed `PORT` and advised leaving it "unset to listen on all interfaces", which was false on both counts. **Evidence:** `test/server-bind.test.js` (23 assertions) spawns the real server four ways - default answers on 127.0.0.1 and *nothing accepts* on the machine's first non-loopback IPv4; `0.0.0.0` does accept there; `192.0.2.123` (TEST-NET-1) exits 1 with a message naming it and no stack trace; `127.0.0.1:<port>` is named as the copied-from-a-URL mistake. `npm test` at the committed tree: 276 suites, 9873 assertions, 0 failed. Syntax check 346 files. **Still open, deliberately:** item 2 (WebSocket `Origin`) landed in #1629. Item 3 - the bearer token - is not in this PR and not in the plan: there is no credential store to guard yet (`grep -ri credential engine/ server/` finds nothing), so a token today would protect nothing and would have to be redone once the store exists. It needs its own plan and a decision from Jay on how the UI authenticates. Steps 3-5 of `docs/plans/server-exposure.md` (narrow CORS, drop the unsolicited board push, docs) are also still a plan.
Author
Owner

Item 2 of this issue is up as PR #1644, branch fix/1116-0905 @ 12f25252 - and it closes the door item 2 alone did not.

What was still open. The upgrade check landed and every JSON answer still carried Access-Control-Allow-Origin: *. So a page the socket had just refused could call

await fetch('http://127.0.0.1:8000/api/topologies/default').then(r => r.json());

and read every device, cable and CLI transcript over HTTP. The Origin check was true of the socket and false of the server. SECURITY.md said so in a sentence, which is the right thing to say and the wrong thing to leave standing - this run reproduced it as 13 failing assertions before touching the code.

What landed. allowedOriginHeader() asks the same allowOrigin() the upgrade uses; sendJSON echoes the caller's own Origin only when that check accepts it and sends no Access-Control-Allow-Origin at all otherwise, so the browser withholds the body; both answer paths now say Vary: Origin, Accept-Encoding; the OPTIONS preflight follows the same rule. /api/catalog and /api/media keep the wildcard - sendImmutableJSON, fixed catalogues, no board, read from other origins on purpose.

test/server-cors.test.js (23 assertions, real server): 10 passed / 13 failed before, 23 / 0 after. Full npm test: 277 suites, 9902 assertions, 0 failed. syntax-check 347 files OK, control bytes clean, doc citations unchanged.

The token item stays open exactly as planned: grep -ri credential engine/ server/ still finds nothing to guard, so a bearer token today would protect an empty set. That waits for the credential store (w9) and Jay's approval, per docs/plans/server-exposure.md.

Item 2 of this issue is up as PR #1644, branch `fix/1116-0905` @ `12f25252` - and it closes the door item 2 alone did not. **What was still open.** The upgrade check landed and every JSON answer still carried `Access-Control-Allow-Origin: *`. So a page the socket had just refused could call ```js await fetch('http://127.0.0.1:8000/api/topologies/default').then(r => r.json()); ``` and read every device, cable and CLI transcript over HTTP. The Origin check was true of the socket and false of the server. `SECURITY.md` said so in a sentence, which is the right thing to say and the wrong thing to leave standing - this run reproduced it as 13 failing assertions before touching the code. **What landed.** `allowedOriginHeader()` asks the same `allowOrigin()` the upgrade uses; `sendJSON` echoes the caller's own `Origin` only when that check accepts it and sends no `Access-Control-Allow-Origin` at all otherwise, so the browser withholds the body; both answer paths now say `Vary: Origin, Accept-Encoding`; the `OPTIONS` preflight follows the same rule. `/api/catalog` and `/api/media` keep the wildcard - `sendImmutableJSON`, fixed catalogues, no board, read from other origins on purpose. `test/server-cors.test.js` (23 assertions, real server): 10 passed / 13 failed before, 23 / 0 after. Full `npm test`: **277 suites, 9902 assertions, 0 failed**. `syntax-check` 347 files OK, control bytes clean, doc citations unchanged. The token item stays open exactly as planned: `grep -ri credential engine/ server/` still finds nothing to guard, so a bearer token today would protect an empty set. That waits for the credential store (w9) and Jay's approval, per `docs/plans/server-exposure.md`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge#1527
No description provided.