GHSA-7v5p-43qr-wch5: @hono/node-server: WebSocket upgrade request-target starting with `//` replaces the host in `c.req.url`, bypassing `Origin` checks
@hono/node-server allows running the Hono application on Node.js. From 2.0.0 until 2.1.6, the WebSocket upgrade path resolves a raw request-target beginning with // against a base URL built from the Host header, causing the WHATWG URL parser to treat the request-target as a network-path reference and replace the host in c.req.url. Routing still uses the local WebSocket path, so an application that compares the Origin header with the origin of c.req.url, including checks implemented with csrf(), compares an attacker's origin with itself and accepts the connection. A page on another site can consequently open a WebSocket with the victim's cookies and read and send messages when the application uses upgradeWebSocket and trusts the host in c.req.url. Ordinary HTTP requests are not affected. This issue is fixed in version 2.1.6.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
@hono/node-serverto a version that resolves this vulnerability.Fixed in 2.1.6
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Deployments using @hono/node-server versions 2.0.0 through 2.1.5 are affected if they expose WebSocket endpoints through upgradeWebSocket and use c.req.url as the trusted origin when validating the Origin header. Ordinary HTTP request handling is not affected.
What must an attacker do to exploit the issue?
An attacker must induce a victim to visit an attacker-controlled page that opens a WebSocket to the vulnerable application using a request-target beginning with //. The vulnerable origin validation must compare Origin against the origin derived from c.req.url, allowing the attacker-controlled host to replace that origin.
Are applications using csrf() affected?
They can be affected when csrf() is used to validate WebSocket upgrade requests through an origin comparison based on c.req.url. In that case, the malformed WebSocket request-target can cause the check to compare the attacker's origin with itself.
What should be done to remediate the issue?
Upgrade @hono/node-server to version 2.1.6, which fixes the issue. Until upgrading, avoid trusting the host-derived origin in c.req.url for WebSocket Origin validation.