server: the REST API stops handing the board to any page that asks (#1527) #1644
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!1644
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/1116-0905"
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?
Fixes #1527 (items 1, 2, and the HTTP half of item 2). Step 3 of
docs/plans/server-exposure.md, landed in its own commit so a broken Origin rule and a broken CORS rule stay distinguishable in a bisect.What was wrong
The WebSocket upgrade refuses a page from another origin (step 2,
test/ws-origin.test.js), and every JSON answer still carriedAccess-Control-Allow-Origin: *. So the page that had just been refused a socket could callfetch('/api/topologies/default')and read the whole board over HTTP - a cheaper door than the one the issue named. SECURITY.md admitted this in a sentence ("that is the next change").What changed
allowedOriginHeader()asks the sameallowOrigin()the upgrade uses and returns the caller's ownOriginonly when that check accepts it (same host and port asHost, or listed inPF_ALLOWED_ORIGINS).sendJSONechoes that origin; when it refuses, the answer carries noAccess-Control-Allow-Originat all, so the browser withholds the body.Vary: Origin, Accept-Encoding: an answer that depends onOriginmust not be handed from one page's cache to another.OPTIONSpreflight follows the same rule instead of naming methods for an answer the caller cannot read./api/catalogand/api/mediakeep the wildcard (sendImmutableJSON). Fixed hardware catalogues, no board, read from other origins deliberately.Tests
test/server-cors.test.js(new, 23 assertions) against a real server: same-origin echo,Vary, foreign origin gets no header on two board routes,Origin: null, a non-URL origin, absentOriginunaffected, both catalogues still wildcard, preflight both ways,PF_ALLOWED_ORIGINSadmitting exactly what it names, and the server still answering afterwards.Before the fix: 10 passed / 13 failed. After: 23 passed / 0 failed.
Gates
node scripts/syntax-check.js- 347 files, all OKnode scripts/check-control-bytes.js- cleannode scripts/check-doc-citations.js- unchanged (the same 7 pre-existing suspects)npm test- 277 suites / 9902 assertions / 0 failedFor Jay
Anyone reading
/api/topologies/*from another origin loses that path. That is the point of step 3, but it is a behaviour change for third-party consumers, not just a header nit. The bearer-token item of #1527 stays open on purpose: there is no credential surface to guard yet.12f2525211ad3c898d62