Repository navigation
fix(viewer): answer a malformed Host with 400 instead of Bun's error page - #18
Merged
abogartz merged 2 commits intoOct 21, 2026
Merged
Conversation
…page Bun builds req.url from the Host header, so a Host such as `127.0.0.1.8787` or `127.0.0.1:99999` made `new URL(req.url)` throw before the request checks ran, and Bun answered with its development error page (stack trace and local file paths). Parse defensively and refuse with 400, and add a server error handler so any other uncaught throw gets a plain 500. Closes abogartz#12 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Owner
|
Merge conflict resolved — merged current
Verified on the merged head: |
|
🎉 This PR is included in version 0.3.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Bun builds
req.urlfrom the request's Host header, so a Host it can't parse (127.0.0.1.8787,127.0.0.1:99999,[::1) madenew URL(req.url)throw beforerejectRequestran. Bun then answered with its development error page: about 67 KB of HTML with the stack trace and local file paths.Change (
src/viewer/server.ts)tryand answer400 malformed requestwhen it fails. This is the fix from the issue.errorhandler toserve()that returns a plain500 internal error, so any other uncaught throw also never shows the debug page. It logs the error withconsole.error, because once a handler is set, Bun stops printing uncaught errors itself.Test (
test/viewer.test.ts)fetch()won't send a Host it can't parse, so the new test writes a raw HTTP request over a socket. For three malformed Hosts it checks for a short400 Bad Requestthat contains no store data.Checks:
bun test195 tests, 0 fail, 4 skip.tsc --noEmitis clean.biome lintreports no new findings in the touched files. Only standard Bun andnode:netAPIs are used, so it behaves the same on macOS.🤖 Generated with Claude Code