Skip to content

fix(node-ws): harden the upgrade listener against malformed requests - #2263

Merged
yusukebe merged 2 commits into
mainfrom
fix/node-ws-upgrade
Nov 20, 2026
Merged

yusukebe merged 2 commits into
mainfrom
fix/node-ws-upgrade

Conversation

@yusukebe

Copy link
Copy Markdown
Member

The upgrade listener built the URL with new URL(request.url, baseUrl), so a request-target like //[ threw and crashed the process with an unhandled rejection. The same listener also let //host/path replace the host, normalized backslashes into path separators, had no error listener on the socket, and handled non-WebSocket upgrades.

This aligns it with @hono/node-server:

  • reject non-WebSocket upgrades with 400
  • attach an error listener and release the waiter when the socket closes
  • build the URL from the socket protocol and the Host header, rejecting backslashes, request-targets that do not start with /, and malformed Host headers
  • catch errors from the app and the aborted handshake

Note: without baseUrl, c.req.url now uses the Host header instead of http://localhost.

Reported by @samuel871211

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ae89130

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/node-ws Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@yusukebe
yusukebe merged commit b712a5e into main Nov 20, 2026
6 checks passed
@yusukebe
yusukebe deleted the fix/node-ws-upgrade branch November 20, 2026 08:51
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
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