Repository navigation
fix(viewer): guarded URL parse + nosniff/CSP (closes #12) - #27
Merged
Merged
Conversation
… CSP new URL(req.url) ran BEFORE rejectRequest: a malformed Host header threw and Bun answered with its dev error page — stack, source excerpts and absolute plugin paths, pre-auth to any local process (issue #12). The parse now has its own 400, ahead of every other step. Also adds defense-in-depth headers on all responses: x-content-type-options: nosniff, and a CSP that keeps a stored-XSS payload (issue #11) from exfiltrating or framing even if an injection ever lands (the page needs only inline script/style and same-origin fetch). Reproduced pre-fix on main 286d2ba: Host 'exa mple' -> 500 with the DevErrorPage body; now 400 with only the error JSON.
|
🎉 This PR is included in version 0.3.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
abogartz
added a commit
to WhollyMindless/opencode-self-improvement
that referenced
this pull request
Oct 21, 2026
main merged abogartz#27 (guarded URL parse + nosniff/CSP) while this PR was open, resolving the same throw. Kept: - main's 400 message and comment in the try/catch (this PR's raw-socket test asserts toContain("malformed request"), which main's message satisfies); - this PR's serve() error handler — defense-in-depth beyond abogartz#27: ANY uncaught handler throw now answers plain JSON 500 instead of Bun's dev error page, stack to the terminal only; - this PR's raw-socket test (Hosts fetch() refuses to send) ALONGSIDE main's fetch-based repro and the CSP/header tests. Combined suite: 206 pass / 4 skip / 0 fail; tsc clean; biome lint exit 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12. Review finding F5, reproduced on
main286d2ba:Host: exa mple→ 500 + Bun dev error page (stack, source excerpt, absolute paths of the plugin) becausenew URL(req.url)throws beforerejectRequestgets to answer. The newa malformed Host fails closed with 400test drives the real socket with the same wire-level repro and fails onmain.Two changes in
src/viewer/server.ts:try/catch→400 malformed request URL, placed ahead of every other step.x-content-type-options: nosniff+ CSP on every response (default-src 'none', inline script/style andconnect-src 'self'only — exactly what the viewer page uses). This is the header half of the viewer: escape ts and superseded_by cells in page.html (stored-XSS defense-in-depth) #11 defense: even if the unescapedts/superseded_bycells (PR to follow) were exploited, the payload gains no exfil channel, no navigation, no framing.Full gate on this branch: 196 tests / 0 fail,
tsc --noEmitclean. Stacks cleanly with the restore-containment PR (both touchserver.ts, disjoint regions).