CVE-2022-2596: node-fetch Inefficient Regular Expression Complexity
Summary
CVE-2022-2596: node-fetch Inefficient Regular Expression Complexity. Affects node-fetch versions >= 3.0.0, < 3.2.10. Fixed in 3.2.10. 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
node-fetch is a lightweight module that brings window.fetch to node.js. It allows developers to make HTTP requests in a simple and efficient manner. However, versions of node-fetch prior to 3.2.10 are vulnerable to a Regular Expression Denial of Service (ReDoS) issue. This vulnerability exists in the isOriginPotentiallyTrustworthy() function in referrer.js. When processing a URL string with alternating letters and periods, such as 'http://' + 'a.a.'.repeat(i) + 'a', the regular expression used in the function exhibits inefficient complexity, making it susceptible to ReDoS attacks.
Vulnerability Detail
The vulnerability in node-fetch arises due to inefficient regular expression complexity. An attacker can exploit this vulnerability by sending a specially crafted URL string that triggers the inefficient regular expression, causing the application to enter into a high-complexity loop. This can lead to a Denial of Service (DoS) condition, where the application becomes unresponsive or crashes. The impact of this vulnerability can vary depending on the application's usage of node-fetch and the attacker's ability to send malicious requests.
How To Fix
Latest published version: 3.3.2 as of 22 Oct 2026
npm install node-fetch@3.3.2
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
3.2.10
This is the first release that contains the fix.
npm install node-fetch@3.2.10
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading to the latest version is not feasible, a possible workaround is to validate and sanitize user input before passing it to node-fetch. By ensuring that the URL strings are properly formatted and do not contain any malicious patterns, the risk of triggering the inefficient regular expression can be mitigated. Here is an example of how to sanitize a URL string in JavaScript:
const sanitizeUrl = (url) => {
const sanitizedUrl = url.replace(/[^a-zA-Z0-9-._~:/?#[\]@!$&'()*+,;=]/g, '');
return sanitizedUrl;
};
Conclusion
In conclusion, node-fetch versions prior to 3.2.10 are vulnerable to a Regular Expression Denial of Service (ReDoS) issue. This vulnerability can be exploited by sending a specially crafted URL string, leading to a Denial of Service (DoS) condition. It is recommended to upgrade to node-fetch version 3.2.10 or later to mitigate this vulnerability. If upgrading is not feasible, developers should validate and sanitize user input before passing it to node-fetch. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for node-fetch →
FAQ
node-fetch is a lightweight module that brings window.fetch to node.js. It allows developers to make HTTP requests in a simple and efficient manner.
Regular Expression Denial of Service (ReDoS) is a type of vulnerability where a maliciously crafted input can cause a regular expression pattern to take an excessive amount of time to evaluate. This can lead to a Denial of Service (DoS) condition, where the application becomes unresponsive or crashes.
An attacker can exploit this vulnerability by sending a specially crafted URL string that triggers the inefficient regular expression in node-fetch. This can cause the application to enter into a high-complexity loop, leading to a Denial of Service (DoS) condition.
The impact of this vulnerability can vary depending on the application's usage of node-fetch and the attacker's ability to send malicious requests. In some cases, it can lead to a Denial of Service (DoS) condition, where the application becomes unresponsive or crashes.
To fix this vulnerability, it is recommended to upgrade to node-fetch version 3.2.10 or later. This version includes a fix for the inefficient regular expression complexity issue. Developers can update the package by running the following command in their project directory: npm install node-fetch@3.2.10.
References
Related vulnerabilities
Recent vulnerabilities recorded for node-fetch.