GHSA-6fc8-4gx4-v693 CVE-2021-32640
ReDoS in Sec-Websocket-Protocol header
- Severity
- 5.3 / 10
- Medium · CVSS 3.1
- Exploit chance (EPSS)
- 2.82%
- Chance of exploitation in the next 30 days. Higher than 86.58% of scored vulnerabilities.
- Known exploited
- No
- Not in CISA's catalog
- Weakness
- CWE-345 Insufficient Verification of Data Authenticity
- CWE-400 Uncontrolled Resource Consumption
- Fix
7.4.6- Upgrade ws to this version or later
Description
Impact
A specially crafted value of the Sec-Websocket-Protocol header can be used to significantly slow down a ws server.
Proof of concept
for (const length of [1000, 2000, 4000, 8000, 16000, 32000]) {
const value = 'b' + ' '.repeat(length) + 'x';
const start = process.hrtime.bigint();
value.trim().split(/ *, */);
const end = process.hrtime.bigint();
console.log('length = %d, time = %f ns', length, end - start);
}
Patches
The vulnerability was fixed in ws@7.4.6 (https://github.com/websockets/ws/commit/00c425ec77993773d823f018f64a5c44e17023ff) and backported to ws@6.2.2 (https://github.com/websockets/ws/commit/78c676d2a1acefbc05292e9f7ea0a9457704bf1b) and ws@5.2.3 (https://github.com/websockets/ws/commit/76d47c1479002022a3e4357b3c9f0e23a68d4cd2).
Workarounds
In vulnerable versions of ws, the issue can be mitigated by reducing the maximum allowed length of the request headers using the --max-http-header-size=size and/or the maxHeaderSize options.
Credits
The vulnerability was responsibly disclosed along with a fix in private by Robert McLaughlin from University of California, Santa Barbara.
Affected versions
npm
| Package | Vulnerable | Fixed in |
|---|---|---|
| ws | >= 7.0.0, < 7.4.6 |
7.4.6 |
| ws | >= 6.0.0, < 6.2.2 |
6.2.2 |
| ws | >= 5.0.0, < 5.2.3 |
5.2.3 |
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 → 7.4.6
- npm
npm install ws@7.4.6- yarn
yarn add ws@7.4.6- pnpm
pnpm add ws@7.4.6
Severity breakdown
CVSS 3.1 5.3
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
- Attack vector
- Network
- Attack complexity
- Low
- Privileges required
- None
- User interaction
- None
- Scope
- Unchanged
- Confidentiality
- None
- Integrity
- None
- Availability
- Low
Weakness
CWE-345: Insufficient Verification of Data Authenticity
The product does not sufficiently verify the origin or authenticity of data, in a way that causes it to accept invalid data.
CWE-400: Uncontrolled Resource Consumption
The product does not properly control the allocation and maintenance of a limited resource.
How to prevent it
- Architecture and Design: Design throttling mechanisms into the system architecture. The best protection is to limit the amount of resources that an unauthorized user can cause to be expended. A strong authentication and access control model will help prevent such attacks from occurring in the first place. The login application should be protected against DoS attacks as much as possible. Limiting the database access, perhaps by caching result sets, can help minimize the resources expended. To further limit the potential for a DoS attack, consider tracking the rate of requests received from users and blocking requests that exceed a defined rate threshold.
- Architecture and Design: Mitigation of resource exhaustion attacks requires that the target system either: recognizes the attack and denies that user further access for a given amount of time, or uniformly throttles all requests in order to make it more difficult to consume resources more quickly than they can again be freed. The first of these solutions is an issue in itself though, since it may allow attackers to prevent the use of the system by a particular valid user. If the attacker impersonates the valid user, they may be able to prevent the user from accessing the server in question. The second solution is simply difficult to effectively institute -- and even when properly done, it does not provide a full solution. It simply makes the attack require more resources on the part of the attacker.
- Architecture and Design: Ensure that protocols have specific limits of scale placed on them.
- Implementation: Ensure that all failures in resource allocation place the system into a safe posture.
References
Advisories
Packages
Other links
- github.com/websockets/ws/security/advisories/GHSA-6fc8-4gx4-v693
- github.com/websockets/ws/issues/1895
- github.com/websockets/ws/commit/00c425ec77993773d823f018f64a5c44e17023ff
- lists.apache.org/thread.html/rdfa7b6253c4d6271e31566ecd5f30b7ce1b8fb2c89d52b8c4e0f4e3…
- security.netapp.com/advisory/ntap-20210706-0005
- lists.apache.org/thread.html/rdfa7b6253c4d6271e31566ecd5f30b7ce1b8fb2c89d52b8c4e0f4e3…
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-3h5v-q93c-6h6q ws affected by a DoS when handling a request with many HTTP headers | High | 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-rfpc-qcw5-3pc4 filelock: SoftFileLock removes a live holder's marker when another user forges the PID in a writable marker | Medium | Same weakness, CWE-345 |
| GHSA-7hp6-4w63-5g45 LiteLLM: Privilege Escalation to Proxy Admin via Cross-Domain Reuse of the Salt Key | Critical | Same weakness, CWE-345 |
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