CVE-2021-23424: Uncontrolled Resource Consumption in ansi-html
Summary
CVE-2021-23424: Uncontrolled Resource Consumption in ansi-html. Affects ansi-html versions < 0.0.8. Fixed in 0.0.8. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The package under scrutiny is ansi-html, an npm package. It is responsible for converting ANSI escape codes into HTML. This package is widely used in various applications and libraries to display colored and formatted text in the terminal. The vulnerability identified in ansi-html allows an attacker to provide a malicious string that can cause the package to consume excessive resources, leading to a denial-of-service (DoS) condition. This vulnerability affects all versions of the package up to and including 0.0.7.
Vulnerability Detail
The vulnerability arises from ansi-html's inability to handle malicious input strings efficiently. When an attacker supplies a specially crafted string, the package gets stuck processing the input for an extended period, resulting in uncontrolled resource consumption. This can lead to a significant impact on the availability and performance of the affected system. The Common Vulnerabilities and Exposures (CVE) identifier for this vulnerability is CVE-2021-23424. The vulnerability has a CVSS v3 score of 7.5, indicating a high severity level.
How To Fix
Latest published version: 0.0.9 as of 22 Oct 2026
npm install ansi-html@0.0.9
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
0.0.8
This is the first release that contains the fix.
npm install ansi-html@0.0.8
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, if updating the package is not immediately feasible, developers can consider implementing input validation and sanitization mechanisms in their code to filter out potentially malicious input strings. By carefully validating and sanitizing user-supplied input, the risk of triggering the vulnerability can be reduced. Here is an example of how input validation can be performed in JavaScript:
const ansiHTML = require('ansi-html');
function sanitizeInput(input) {
// Perform input validation and sanitization
// ... your code here ...
return input;
}
const maliciousString = '...';
const sanitizedString = sanitizeInput(maliciousString);
const htmlOutput = ansiHTML.ansiHTML(sanitizedString);
It is important to note that this workaround is not a complete solution and should be considered temporary until the package is updated.
Conclusion
In conclusion, the ansi-html package is vulnerable to uncontrolled resource consumption, which can be exploited by providing a malicious string. This can lead to a denial-of-service (DoS) condition. It is crucial to update the package to version 0.0.8 or later to mitigate this vulnerability. In the meantime, implementing input validation and sanitization mechanisms can serve as a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for ansi-html →
FAQ
ansi-html is an npm package that converts ANSI escape codes into HTML. It is commonly used to display colored and formatted text in the terminal.
The vulnerability allows an attacker to cause uncontrolled resource consumption in the ansi-html package, leading to a denial-of-service (DoS) condition. This can impact the availability and performance of the affected system.
All versions of ansi-html up to and including 0.0.7 are affected by this vulnerability.
The CVSS v3 score of this vulnerability is 7.5, indicating a high severity level.
To fix this vulnerability, it is recommended to update the ansi-html package to version 0.0.8 or later. This update includes the necessary fixes to prevent uncontrolled resource consumption.