security: a malformed upgrade path crashes the Node process #104

Closed
opened 2026-09-25 14:02:12 +00:00 by chrnx · 1 comment
Owner

Kept internal under SECURITY.md: this one is exploitable. The GitHub advisory goes out with the fix.

The Node upgrade listener (src/http/ws.ts:104) matches WebSocket routes with no error boundary. A request for /bad% with an upgrade header, against any WS route that has a parameter (/ws/:id), throws URIError from decodeSegment (src/http/router.ts:294) inside an event listener. That is an uncaught exception, and the process exits. One unauthenticated request takes down every connection.

Fix: normalize and validate the path with normalizeRequestPath, which also fixes GitHub #42. Wrap matching in try/catch, and answer 400 and destroy the socket on failure. Test: an upgrade to /ws/bad% gets a 400 and the server keeps serving.

Kept internal under SECURITY.md: this one is exploitable. The GitHub advisory goes out with the fix. The Node `upgrade` listener (src/http/ws.ts:104) matches WebSocket routes with no error boundary. A request for `/bad%` with an upgrade header, against any WS route that has a parameter (`/ws/:id`), throws `URIError` from `decodeSegment` (src/http/router.ts:294) inside an event listener. That is an uncaught exception, and the process exits. One unauthenticated request takes down every connection. **Fix:** normalize and validate the path with `normalizeRequestPath`, which also fixes [GitHub #42](https://github.com/Expressive-Tea/green-tea/issues/42). Wrap matching in try/catch, and answer `400` and destroy the socket on failure. **Test:** an upgrade to `/ws/bad%` gets a 400 and the server keeps serving.
chrnx added the bugsecurity labels 2026-09-25 16:06:52 +00:00
Author
Owner

Fixed in 26.11.0-rc.1 (59763c9). From the changelog:

  • A malformed WebSocket upgrade no longer takes a Node server down (#104). The upgrade path never ran the request-path normalization HTTP runs, so a bad percent escape in a param segment (/room/%E0%A4%A) threw out of the 'upgrade' listener as an uncaught exception, and one request was enough to end the process. Upgrades now go through the same normalization: a malformed escape or a repeated slash gets a 400, an unknown route a written 404 instead of a silent disconnect, and anything else that throws in the listener a 500. //rt//echo used to match /rt/echo on upgrade while HTTP refused it; both refuse it now. On Deno, Bun and the edge the same paths close with 1008 invalid request path rather than 1011 internal error, and on Deno a 1008 sent before the socket finished opening now reaches the client instead of leaving it hanging.
Fixed in **26.11.0-rc.1** (`59763c9`). From the changelog: - **A malformed WebSocket upgrade no longer takes a Node server down** (#104). The upgrade path never ran the request-path normalization HTTP runs, so a bad percent escape in a param segment (`/room/%E0%A4%A`) threw out of the `'upgrade'` listener as an uncaught exception, and one request was enough to end the process. Upgrades now go through the same normalization: a malformed escape or a repeated slash gets a `400`, an unknown route a written `404` instead of a silent disconnect, and anything else that throws in the listener a `500`. `//rt//echo` used to match `/rt/echo` on upgrade while HTTP refused it; both refuse it now. On Deno, Bun and the edge the same paths close with `1008 invalid request path` rather than `1011 internal error`, and on Deno a `1008` sent before the socket finished opening now reaches the client instead of leaving it hanging.
chrnx closed this issue 2026-11-18 01:03:58 +00:00
Sign in to join this conversation.