A missing asset is answered with the app, any method serves a file, and web-root containment is a string prefix #1311
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge#1311
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Found by pointing at the static server the same 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 is answered with the app
serveStatic()falls back toindex.htmlfor anything it cannot read. This app has no client-side routes - itis one page with tabs - so the fallback serves no deep link that matters and instead hides every wrong filename.
In a browser the only report is
Uncaught SyntaxError: Unexpected token '<', in a file the reader can no longeridentify. A missing
favicon.icoreads as a broken app.2. The method is ignored
A client that POSTs can conclude its write landed.
HEADreturns a body as well, including on the gzip branchwhere
res.end(gz)writes the compressed bytes.3. Containment is 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 thehole.
A test was pinning the defect
test/server-static-cache.test.jsasserted:So the behaviour was not merely untested, it was specified, in the wrong direction. That is why it survived.
What must be true instead
404 text/plain, and never the document; a path with noextension still opens the app (deep links keep working);
POST/PUT/DELETE/PATCHon a static path is405withAllow: GET, HEAD;HEADreturns the headers aGETwould send and no body, on every branch including gzip;filePath === WEB_DIR || filePath.startsWith(WEB_DIR + path.sep);