Skip to content
Smuggling / CRLF Disclosed report Intermediate

CRLF Injection in Nodejs ‘undici’ via host

The undici library did not sanitise the host header, allowing CRLF injection via undici.request.

timon8 Follow

Originally disclosed on HackerOne

Medium 4.6 View original
  • Triaged in 48 hours
  • Fixed in 45 days
  • Disclosed after 50 days

Summary: undici library should be protects HTTP headers from CRLF injection vulnerabilities. However, CRLF injection exists in the ‘host’ header of undici.request api.

Description: like https://hackerone.com/reports/1664019 Source code: lib/core/request.js:296

JavaScript
function processHeader (request, key, val) {
  if (val && (typeof val === 'object' && !Array.isArray(val))) {
    throw new InvalidArgumentError(`invalid ${key} header`)
  } else if (val === undefined) {
    return
  }

  if (
    request.host === null &&
    key.length === 4 &&
    key.toLowerCase() === 'host'
  ) {
    // Consumed by Client
    request.host = val // without headerCharRegex.exec(val)
  } else if (
    request.contentLength === null &&
...

Example:

JavaScript
import { request } from 'undici'

const unsanitizedContentTypeInput =  '12 \r\n\r\naaa:aaa'

const {
    statusCode,
    headers,
    trailers,
    body
} = await request('http://127.0.0.1:23333', {
    method: 'GET',
    headers: {
        'content-type': 'application/json',
        'host': unsanitizedContentTypeInput
    }
})

console.log('response received', statusCode)
console.log('headers', headers)

for await (const data of body) {
    console.log('data', data)
}

console.log('trailers', trailers)

image.png
image.png From the original on HackerOne

Impact:

<[email protected]

Impact

<[email protected]

The original report as published on HackerOne, by timon8. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the host header value was assigned directly without running the header character validation regex.

Impact

CRLF injection in the host header affects versions up to 5.14.0; the text does not detail further impact.

What the attacker needed

Attacker controls host header value; application uses undici.request

How it was found

  1. Import the request function from undici.
  2. Create a host header value containing carriage return and line feed characters followed by an extra header.
  3. Call request with a local URL and pass the malicious host header.
  4. Log the response status, headers and body.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

HTTP headers are lines of text separated by special newline characters. If a program puts user input into a header without removing those newline characters, an attacker can add extra headers or even a second request. This report shows that the host header in undici was not checked for such characters.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

More by timon8

View all

2 more disclosed reports, best first.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.