Skip to content

Bytes >=0x80 are stripped from the beginnings and ends of header values #8893

Open
@kenballus

Description

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?

  1. Start a Bun web server that shows you each received request's message body, e.g. by running this script.
  2. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbun.jsSomething to do with a Bun-specific API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions