Vulnerabilities in pkg:npm/ansi-regex
PACKAGECVE-2021-3807 is a HIGH (CVSS 7.5) inefficient regular expression complexity vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting Ansi regex libraries in the npm ecosystem. The issue involves inefficient regular expression complexity in chalk/ansi-regex. Remediation is available by upgrading affected packages to version 6.0.1, 5.0.1, 4.1.1, 3.0.1.
pkg:npm/ansi-regex
Vulnerability advisories affecting package pkg:npm/ansi-regex. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-93q8-gq69-wqmw | CVE-2021-3807 | HIGH | Inefficient Regular Expression Complexity in chalk/ansi-regex |
CVE-2021-3807 at a Glance
Security Impact
CVSS: 7.5
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).
How to Fix CVE-2021-3807
To remediate this vulnerability, upgrade all affected Ansi regex dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install ansi-regex@6.0.1
npm install ansi-regex@5.0.1
npm install ansi-regex@4.1.1
npm install ansi-regex@3.0.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls ansi-regex
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2021-3807, inspect your project dependencies using npm:
npm ls ansi-regex
Analyze the terminal output to locate any version of Ansi regex in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.0.1), your application is affected.
Note: The npm ls ansi-regex command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-1333: Inefficient Regular Expression Complexity, where the product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential. In Ansi regex, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2021-3807 Affected Ansi regex Versions
4 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
ansi-regex
|
npm |
≥ 6.0.0
< 6.0.1
|
6.0.1
|
|
ansi-regex
|
npm |
≥ 5.0.0
< 5.0.1
|
5.0.1
|
|
ansi-regex
|
npm |
≥ 4.0.0
< 4.1.1
|
4.1.1
|
|
ansi-regex
|
npm |
≥ 3.0.0
< 3.0.1
|
3.0.1
|
References
Frequently Asked Questions
What is CVE-2021-3807?
Which Ansi regex versions are affected?
What version fixes CVE-2021-3807?
Is ansi-regex affected?
What is the CVSS score of CVE-2021-3807?
What CWE is associated with CVE-2021-3807?
How can I check npm dependencies for CVE-2021-3807?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-93q8-gq69-wqmw",
"modified" : "2023-09-11T16:42:11Z",
"published" : "2021-09-20T20:20:09Z",
"aliases" : [ "CVE-2021-3807" ],
"summary" : "Inefficient Regular Expression Complexity in chalk/ansi-regex",
"details" : "ansi-regex is vulnerable to Inefficient Regular Expression Complexity which could lead to a denial of service when parsing invalid ANSI escape codes.\n\n**Proof of Concept**\n```js\nimport ansiRegex from 'ansi-regex';\nfor(var i = 1; i <= 50000; i++) {\n var time = Date.now();\n var attack_str = \"\\u001B[\"+\";\".repeat(i*10000);\n ansiRegex().test(attack_str)\n var time_cost = Date.now() - time;\n console.log(\"attack_str.length: \" + attack_str.length + \": \" + time_cost+\" ms\")\n}\n```\nThe ReDOS is mainly due to the sub-patterns `[[\\\\]()#;?]*` and `(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]*)*`",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "ansi-regex"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.0.0"
}, {
"fixed" : "6.0.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "ansi-regex"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "5.0.0"
}, {
"fixed" : "5.0.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "ansi-regex"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "4.0.0"
}, {
"fixed" : "4.1.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "ansi-regex"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "3.0.0"
}, {
"fixed" : "3.0.1"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-3807"
}, {
"type" : "WEB",
"url" : "https://github.com/chalk/ansi-regex/issues/38#issuecomment-924086311"
}, {
"type" : "WEB",
"url" : "https://github.com/chalk/ansi-regex/issues/38#issuecomment-925924774"
}, {
"type" : "WEB",
"url" : "https://github.com/chalk/ansi-regex/commit/419250fa510bf31b4cc672e76537a64f9332e1f1"
}, {
"type" : "WEB",
"url" : "https://github.com/chalk/ansi-regex/commit/75a657da7af875b2e2724fd6331bf0a4b23d3c9a"
}, {
"type" : "WEB",
"url" : "https://github.com/chalk/ansi-regex/commit/8d1d7cdb586269882c4bdc1b7325d0c58c8f76f9"
}, {
"type" : "WEB",
"url" : "https://github.com/chalk/ansi-regex/commit/c3c0b3f2736b9c01feec0fef33980c43720dcde8"
}, {
"type" : "WEB",
"url" : "https://app.snyk.io/vuln/SNYK-JS-ANSIREGEX-1583908"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/chalk/ansi-regex"
}, {
"type" : "WEB",
"url" : "https://github.com/chalk/ansi-regex/releases/tag/v6.0.1"
}, {
"type" : "WEB",
"url" : "https://huntr.dev/bounties/5b3cf33b-ede0-4398-9974-800876dfd994"
}, {
"type" : "WEB",
"url" : "https://security.netapp.com/advisory/ntap-20221014-0002"
}, {
"type" : "WEB",
"url" : "https://www.oracle.com/security-alerts/cpuapr2022.html"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-1333", "CWE-697" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2021-09-20T18:56:22Z",
"nvd_published_at" : "2021-09-17T07:15:00Z"
}
}