A missing asset is a 404, only a read serves a file, and web-root containment is a boundary (#1311) #1312
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!1312
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/static-surface"
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?
A missing asset is a 404, only a read serves a file, and web-root containment is a boundary.
Fixes #1311.
Pointing at the static server with the request-level lens used for #1307 and #1309. Three defects — and one of them
was pinned by a test that asserted the wrong thing.
1. A missing file was answered with the app
serveStatic()fell back toindex.htmlfor anything it could not read. This app has no client-side routes — onepage with tabs — so the fallback served no deep link that matters and instead hid every wrong filename: the
browser's only report is
Uncaught SyntaxError: Unexpected token '<', in a file the reader can no longer identify.2. The method was ignored
A client that POSTs could conclude its write landed.
HEADreturned a body too, including on the gzip branch.3. Containment was a string prefix, not a path boundary
indexOf(WEB_DIR) === 0also accepts…/web-backup/…, a sibling whose name merely starts withweb. Nothingexploits it today — the URL parser collapses
..before the path is joined — but a check that is only safe becauseanother component happens to clean up first is not a check, and the next directory added beside
web/inherits it.A test was pinning the defect
test/server-static-cache.test.jsasserted:The behaviour was not merely untested, it was specified in the wrong direction — which is why it survived. Those
two assertions are corrected rather than deleted, so the change of intent is visible in the diff.
Fixes
A path with an extension that does not exist →
404 text/plain; a path with no extension → still opens the app;POST/PUT/DELETE/PATCH→405withAllow: GET, HEAD;HEAD→ no body on every branch including gzip;containment →
filePath === WEB_DIR || filePath.startsWith(WEB_DIR + path.sep).Evidence
test/static-surface.test.js— 19 checks over real HTTP:.jsand.css;..,%2e%2e,..%2f,//, mixed separators,package.json, engine source) allfail to return server or engine source;
405withAllow;HEADhas no body and the length aGETwould send, including withAccept-Encoding: gzip;If-Modified-Sincestill revalidate to an empty304, while a stale tag still gets the bytes;With
server/index.jsreverted, 4 of the 19 fail —/nope.js → 200 text/html, both boundary checks, andPOST → 200with noAllowheader.docs/ARCHITECTURE.md: "What the static server answers" — the table, and why the second row mattered.Suite: 171 suites, 6,897 assertions, 0 failed.