CVE-2022-31150: CRLF injection in request headers in undici
Summary
CVE-2022-31150: undici before v5.8.0 vulnerable to CRLF injection in request headers. Affects undici versions < 5.8.0. Fixed in 5.8.0. How to fix ↓
Also tracked for
- node-undici · Debian:12
The same CVE-2022-31150 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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
Undici is an HTTP/1.1 client library for Node.js. It provides a high-performance, low-memory footprint alternative to the built-in http module. Undici is widely used for making HTTP requests in Node.js applications. However, versions prior to v5.8.0 are vulnerable to CRLF injection in request headers. This vulnerability allows an attacker to inject CRLF sequences into request headers, potentially leading to various security issues.
Vulnerability Detail
The vulnerability in undici allows an attacker to inject CRLF sequences into request headers. This can be exploited by crafting malicious headers that include CRLF sequences, which can lead to various security issues such as HTTP response splitting, cache poisoning, and cross-site scripting (XSS) attacks. An example of a vulnerable code snippet is as follows:
const undici = require('undici')
const response = undici.request("http://127.0.0.1:1000", {
headers: {'a': "\r\nb"}
})
To mitigate this vulnerability, it is recommended to update undici to v5.8.0 or later.
How To Fix
Latest published version: 8.12.3 as of 22 Oct 2026
npm install undici@8.12.3
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
5.8.0
This is the first release that contains the fix.
npm install undici@5.8.0
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If updating undici is not immediately feasible, a workaround is to sanitize all HTTP headers from untrusted sources to eliminate CRLF sequences. This can be done by removing any occurrences of \r\n in the headers before passing them to undici. Here's an example of how to sanitize headers:
const sanitizeHeaders = (headers) => {
for (const key in headers) {
if (typeof headers[key] === 'string') {
headers[key] = headers[key].replace(/\r\n/g, '');
}
}
};
const undici = require('undici');
const headers = {'a': "\r\nb"};
sanitizeHeaders(headers);
const response = undici.request("http://127.0.0.1:1000", {
headers
});
Conclusion
Undici versions prior to v5.8.0 are vulnerable to CRLF injection in request headers. This vulnerability can be exploited to perform various attacks, including HTTP response splitting, cache poisoning, and cross-site scripting (XSS) attacks. To mitigate the vulnerability, it is recommended to update undici to v5.8.0 or later. If updating is not immediately feasible, sanitize all HTTP headers from untrusted sources to eliminate CRLF sequences. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for undici →
FAQ
Undici is an HTTP/1.1 client library for Node.js, providing a high-performance alternative to the built-in http module.
CRLF injection is a vulnerability that allows an attacker to inject CRLF sequences (carriage return and line feed) into input data, such as HTTP headers. This can lead to various security issues, including HTTP response splitting, cache poisoning, and cross-site scripting (XSS) attacks.
The CRLF injection vulnerability in undici can be exploited to perform HTTP response splitting attacks, cache poisoning, and cross-site scripting (XSS) attacks. These attacks can lead to unauthorized access, data leakage, and manipulation of web content.
To fix the vulnerability, update undici to v5.8.0 or later. This can be done by running the command npm install undici@5.8.0 in your Node.js project.
Yes, if updating undici is not immediately feasible, you can sanitize all HTTP headers from untrusted sources to eliminate CRLF sequences. This can be done by removing any occurrences of \r\n in the headers before passing them to undici.
References
Related vulnerabilities
Recent vulnerabilities recorded for undici.