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

Cheroot responds to incomplete requests when the connection is half-closed #732

Open
kenballus opened this issue Jul 23, 2024 · 0 comments
Labels
bug Something is broken triage

Comments

@kenballus
Copy link

Description of the bug

From RFC 9112:

If a valid Content-Length header field is present without Transfer-Encoding, its decimal value defines the expected message body length in octets. If the sender closes the connection or the recipient times out before the indicated number of octets are received, the recipient MUST consider the message to be incomplete and close the connection.

Cheroot does not enforce this rule. When it receives a request, and the sender half-closes the connection, Cheroot responds regardless of whether the request's body has been fully received.

To reproduce

  1. Start a Cheroot-based HTTP server that echos the message body. (e.g., something like this)
  2. Send it a request with an incomplete message body, followed by half-closing the socket, and observe that it still responds:
printf 'GET / HTTP/1.1\r\nHost: a\r\nContent-Length: 10\r\n\r\nA' | nc localhost 80
HTTP/1.1 200 OK
Content-type: application/json
Content-Length: 133
Date: Tue, 23 Jul 2024 01:28:24 GMT
Server: Cheroot/10.0.2.dev71+g1ff20b18

{"headers":[["SE9TVA==","YQ=="],["Q09OVEVOVF9MRU5HVEg=","MTA="]],"body":"QQ==","version":"SFRUUC8xLjE=","uri":"Lw==","method":"R0VU"}
  1. Decode the response to see that it accepted the incomplete message body:
printf '{"headers":[["SE9TVA==","YQ=="],["Q09OVEVOVF9MRU5HVEg=","MTA="]],"body":"QQ==","version":"SFRUUC8xLjE=","uri":"Lw==","method":"R0VU"}' \
    | jq '.["body"]' \
    | xargs echo \
    | base64 -d \
    | xxd
00000000: 41                                       A
@kenballus kenballus added bug Something is broken triage labels Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken triage
Projects
None yet
Development

No branches or pull requests

1 participant