lpereira / lwan

Experimental, scalable, high performance HTTP server
https://lwan.ws
GNU General Public License v2.0
5.94k stars 548 forks source link

Lwan truncates header lines on `\rX`, where `X` can be anything #368

Closed kenballus closed 3 months ago

kenballus commented 3 months ago

The bug

HTTP/1.1 header field lines must be terminated with either CRLF or bare LF. Lwan terminates header field lines with CR followed by anything. This is usable for request smuggling when Lwan is deployed behind a reverse proxy that forwards bare CR in header field lines.

For example, Lwan sees one request in the following payload, where it should either see two requests or reject the message:

POST / HTTP/1.1\r\n
Host: a\rX
Content-Length: 31\r\n
\r\n
GET /evil HTTP/1.1\r\n
Host: a\r\n
\r\n

What other servers do

Respond 400:

See two requests:

Close the connection without responding:

lpereira commented 3 months ago

Thanks for the bug report! It's a simple fix, and I'll send a patch this week.

lpereira commented 3 months ago

Fixed, thank you!