ws: refuse an upgrade whose Origin is not the Host it was addressed to (#1527) #1629
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!1629
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/1116-0735"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #1527 - the WebSocket item. The bind default and the bearer token are not here, so the issue stays open. Step 2 of
docs/plans/server-exposure.md.What was wrong.
server/index.jspassed every upgrade request straight towss.handleUpgrade, which readsec-websocket-keyand nothing else, and on success immediately pushed the wholedefaultboard. A WebSocket handshake is not subject to the same-origin policy, so any page Jay visited could openws://127.0.0.1:8000/and read every device, cable and CLI transcript on the board. RFC 6455 10.2 asks a server to compareOriginwithHostfor exactly this reason.What changed.
server/ws.js:allowOrigin(req, extra)- absentOriginallowed (curl, native clients, every suite intest/); a presentOriginallowed only when it names the same host and port asHost, or is listed inextra.file:,data:and the literalnullthat a sandboxed iframe sends are refused, because they name no host.handleUpgrade(req, socket, { allowOrigin })asks it before the101and answers403(newrefuseUpgrade()) with a body naming both headers and the remedy, then destroys the socket.server/index.js:PF_ALLOWED_ORIGINS(comma list) is the way to admit a page served from somewhere else; empty unless asked for. The UI is served by this process, so its own page is same-origin and needs no entry.docs/plans/server-exposure.mdmarks step 2 landed and corrects its shifted line citations;SECURITY.mdstates the new rule and says plainly that the wildcard CORS header still lets a page read a board over HTTP;docs/ARCHITECTURE.mdgains the rule in the WebSocket section.Test. New
test/ws-origin.test.js, 16 assertions driving a raw socket against a real server: noOrigingives 101 and the board; same-origin gives 101;http://evil.examplegives 403 with no101and no board frame; the same host on another port gives 403;Origin: nullgives 403; a non-URL gives 403; the server is still answering afterwards;PF_ALLOWED_ORIGINSadmits the origin it names, refuses another, and leaves same-origin working.Totals.
node scripts/syntax-check.js: 343 files OK. Fullnpm test: 273 suites, 9813 assertions, 0 failed.Not here (one PR each, per the plan): the loopback bind default with a host opt-out (step 1), narrowing the wildcard
Access-Control-Allow-Originon topology data (step 3), dropping the unsolicited board push (step 4), and the bearer token for the credential surface, which needs a credential store to protect and needs Jay's approval. Until step 1 lands the socket is still reachable from the LAN; a web page can no longer reach it.probe: should not be createdto ws: refuse an upgrade whose Origin is not the Host it was addressed to (#1527)dffb57cfe8cc67f4618f