CVE-2021-32640

CVE-2021-32640 is a medium-severity uncontrolled resource consumption vulnerability in ws (npm), affecting versions >= 7.0.0, < 7.4.6. It is fixed in 7.4.6, 6.2.2, 5.2.3.

Summary

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);
}

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.

Impact

A specially crafted value of the Sec-Websocket-Protocol header can be used to significantly slow down a ws server.

Crafted input forces the application to consume excessive CPU, memory, or other resources, degrading or denying service. Typical impact: denial of service.

CVE-2021-32640 has a CVSS score of 5.3 (Medium). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (7.4.6, 6.2.2, 5.2.3); upgrading removes the vulnerable code path.

Affected versions

ws (>= 7.0.0, < 7.4.6) ws (>= 6.0.0, < 6.2.2) ws (>= 5.0.0, < 5.2.3)

Security releases

ws → 7.4.6 (npm) ws → 6.2.2 (npm) ws → 5.2.3 (npm)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

See it in your environment

Remediation advice

The vulnerability was fixed in [email protected] (https://github.com/websockets/ws/commit/00c425ec77993773d823f018f64a5c44e17023ff) and backported to [email protected] (https://github.com/websockets/ws/commit/78c676d2a1acefbc05292e9f7ea0a9457704bf1b) and [email protected] (https://github.com/websockets/ws/commit/76d47c1479002022a3e4357b3c9f0e23a68d4cd2).

Frequently Asked Questions

  1. What is CVE-2021-32640? CVE-2021-32640 is a medium-severity uncontrolled resource consumption vulnerability in ws (npm), affecting versions >= 7.0.0, < 7.4.6. It is fixed in 7.4.6, 6.2.2, 5.2.3. Crafted input forces the application to consume excessive CPU, memory, or other resources, degrading or denying service.
  2. How severe is CVE-2021-32640? CVE-2021-32640 has a CVSS score of 5.3 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
  3. Which versions of ws are affected by CVE-2021-32640? ws (npm) versions >= 7.0.0, < 7.4.6 is affected.
  4. Is there a fix for CVE-2021-32640? Yes. CVE-2021-32640 is fixed in 7.4.6, 6.2.2, 5.2.3. Upgrade to this version or later.
  5. Is CVE-2021-32640 exploitable, and should I be worried? Whether CVE-2021-32640 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  6. What actually determines whether CVE-2021-32640 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  7. How do I fix CVE-2021-32640?
    • Upgrade ws to 7.4.6 or later
    • Upgrade ws to 6.2.2 or later
    • Upgrade ws to 5.2.3 or later

Other vulnerabilities in ws

CVE-2026-45736CVE-2024-37890CVE-2020-35896CVE-2021-32640CVE-2016-10542

Stop the waste.
Protect your environment with Kodem.