Skip to content

fix(http): stop malformed requests from crashing the server - #13

Merged
autoantohaki merged 1 commit into
mainfrom
fix/http-malformed-request-crash
Oct 22, 2026
Merged

autoantohaki merged 1 commit into
mainfrom
fix/http-malformed-request-crash

Conversation

@autoantohaki

Copy link
Copy Markdown
Member

Requested by mau

Summary

Before: the HTTP server built its request URL from the client-supplied Host header inside a promise that nothing awaited. A single request like Host: a b (or an absolute request target such as GET http://[) made new URL() throw, the rejection went unhandled, and Node terminated the whole server.

After: routing uses the request path with a fixed base. An unparseable request target gets a 400 {"error":"invalid_request_target"}, and any other handler failure is logged and answered with 500 {"error":"internal_error"}. The server keeps serving in every case.

How: src/http.ts stops reading Host for URL parsing, guards the parse, and attaches a .catch to the per-request promise. New tests send raw malformed requests over a socket and check that the server is still healthy afterwards. A mocked failing handler covers the 500 path. Both malformed-request tests fail on main with unhandled rejections.

Verification

  • npm run verify
  • Documentation updated (CHANGELOG)
  • No credentials or machine-specific paths added

The request URL was built from the client-supplied Host header, so a
request such as "Host: a b" made new URL() throw inside a promise that
nothing awaited. The unhandled rejection terminates Node, taking the
server down with a single request.

Route on the request path with a fixed base, answer 400 for an
unparseable request target, and turn any other handler failure into a
logged 500 instead of an unhandled rejection.
@autoantohaki
autoantohaki merged commit c8498d1 into main Oct 22, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant