CVE-2022-31150: CRLF injection in request headers in undici

undici Updated 02 Oct 2025

Summary

21/07/2022
Yes i
Moderate
5.3

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

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.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

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 →

Share this vulnerability

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.

Related vulnerabilities

Recent vulnerabilities recorded for undici.

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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback