Bytes >=0x80
are stripped from the beginnings and ends of header values #8893
Open
Description
opened on Feb 14, 2024
What version of Bun is running?
1.0.26-debug+7405c5a61
What platform is your computer?
Linux 6.7.2-arch1-2 x86_64 x86_64
What steps can reproduce the bug?
- Start a Bun web server that shows you each received request's message body, e.g. by running this script.
- Send it a request containing bytes greater than or equal to
0x80
on either side of a header value:
printf 'GET / HTTP/1.1\r\nHost: whatever\r\nKey: \xffvalue\xff\r\n\r\n' | nc localhost 80
What is the expected behavior?
Bun should provide a response indicating that it received a header with the name Key
(case-insensitive), and the value \xffvalue\xff
.
What do you see instead?
Bun's response indicates that it stripped the \xff
bytes from the header value. To see this for yourself, run the reproduction steps, and then run the following command:
printf 'GET / HTTP/1.1\r\nHost: whatever\r\nKey: \xffvalue\xff\r\n\r\n' | nc localhost 80 | tail -n 1 | jq '.["headers"][1][1]' | sed 's/"//g' | base64 -d | hexdump -C
You should see output that looks like this:
00000000 76 61 6c 75 65 |value|
00000005
This demonstrates that the \xff
bytes have been stripped.
Additional information
It is very likely that this bug can be used to execute request smuggling attacks when Bun is deployed behind certain HTTP gateway servers by sending Transfer-Encoding: \xffchunked\xff
headers.
Activity