Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP server does not validate Host header is present #26554

Open
uNetworkingAB opened this issue Oct 25, 2024 · 4 comments
Open

HTTP server does not validate Host header is present #26554

uNetworkingAB opened this issue Oct 25, 2024 · 4 comments
Labels
bug Something isn't working correctly

Comments

@uNetworkingAB
Copy link

Version: Deno 2.0.0

I made a quick and simple standards test and found that Deno does not properly check for Content-Length vs. Transfer-Encoding. It must close the connection with error if both headers are present.

Also, the Host header is not checked.

Screenshot 2024-10-25 222602

@bartlomieju bartlomieju added the bug Something isn't working correctly label Oct 26, 2024
@littledivy
Copy link
Member

re request smuggling the spec says:

https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.3

If a message is received with both a Transfer-Encoding and a Content-Length header field, the Transfer-Encoding overrides the Content-Length. Such a message might indicate an attempt to perform request smuggling (Section 9.5) or response splitting (Section 9.4) and ought to be handled as an error. A sender MUST remove the received Content-Length field prior to forwarding such a message downstream.

Deno correctly overrides the Content-Length header field when calling the request handler.

Deno.serve((req) => {
    console.log(req.headers)
})
Headers { host: "example.com", "transfer-encoding": "chunked" }

Although I don't really like this and it should just close connection with error.

@uNetworkingAB
Copy link
Author

Ah, fair enough.

But Host is missing:

A server MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message that lacks a Host header field [...]

@littledivy
Copy link
Member

Opened hyperium/hyper#3777

@uNetworkingAB
Copy link
Author

You're right, Deno does override Content-Length properly now that I updated the test. The only failure is re. Host header now.

✅ Overflowing negative Content-Length header: Response Status Code 400, Expected ranges: [[400,499]]
✅ Conflicting Transfer-Encoding and Content-Length in varying case: Response Status Code 200, Expected ranges: [[400,499],[200,299]]
✅ Request without HTTP version: Response Status Code 400, Expected ranges: [[400,599]]
✅ Invalid header characters: Response Status Code 400, Expected ranges: [[400,499]]
✅ Negative Content-Length header: Response Status Code 400, Expected ranges: [[400,499]]
✅ Non-numeric Content-Length header: Response Status Code 400, Expected ranges: [[400,499]]
✅ Header containing invalid control character: Response Status Code 400, Expected ranges: [[400,499]]
✅ Invalid HTTP version: Response Status Code 400, Expected ranges: [[400,499],[500,599]]
✅ Invalid prefix of request: Response Status Code 400, Expected ranges: [[400,499],[500,599]]
✅ Invalid line ending: Response Status Code 400, Expected ranges: [[400,499]]
✅ Request with Expect header: Response Status Code 200, Expected ranges: [[100,100],[200,299]]
✅ Valid GET request: Response Status Code 200, Expected ranges: [[200,299]]
✅ Valid GET request with edge cases: Response Status Code 200, Expected ranges: [[200,299]]
❌ Missing Host header: Response Status Code 200, Expected ranges: [[400,499]]
❌ Multiple Host headers: Response Status Code 200, Expected ranges: [[400,499]]
✅ Empty header value: Response Status Code 200, Expected ranges: [[200,299]]
✅ Valid POST request with body: Response Status Code 200, Expected ranges: [[200,299],[404,404]]
✅ Chunked Transfer-Encoding: Response Status Code 200, Expected ranges: [[200,299]]
✅ Fragmented HTTP version: Server waited successfully
✅ Fragmented field value 1: Server waited successfully
✅ Fragmented method: Server waited successfully
✅ Fragmented URL 1: Server waited successfully
✅ Fragmented URL 2: Server waited successfully
✅ Fragmented URL 3: Server waited successfully
✅ Fragmented request line: Server waited successfully
✅ Fragmented request line newline 1: Server waited successfully
✅ Fragmented request line newline 2: Server waited successfully
✅ Fragmented field name: Server waited successfully
✅ Fragmented field value 2: Server waited successfully
✅ Fragmented field value 3: Server waited successfully
✅ Fragmented field value 4: Server waited successfully
✅ Fragmented request: Server waited successfully
✅ Fragmented request termination: Server waited successfully

31 out of 33 tests passed.

@lucacasonato lucacasonato changed the title Request smuggling check missing HTTP server does not validate Host header is present Oct 28, 2024
@littledivy littledivy removed their assignment Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

3 participants