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

Improper Content-Length Parsing #2716

Closed
kenballus opened this issue Jun 1, 2023 · 1 comment
Closed

Improper Content-Length Parsing #2716

kenballus opened this issue Jun 1, 2023 · 1 comment
Milestone

Comments

@kenballus
Copy link

Description

werkzeug currently parses Content-Length using int. This causes problems because int accepts a lot more than should be acceptable in that field. The biggest problem characters are, '-', '+', and '_'.

Examples

HTTP requests in which werkzeug misinterprets content-length (assume all newlines are CRLF):

Underscore between digits

GET / HTTP/1.1
Connection: close
Host: whatever
Content-Length: 0_1


Plus sign prefix

GET / HTTP/1.1
Connection: close
Host: whatever
Content-Length: +1


Solution

The set of things you want to accept in a Content-Length header is not equal to the set of things that can get through int without error. During Content-Length parsing, check that the value is all ASCII digits before accepting. A more principled approach would reject all invalid Content-Length fields instead of just ignoring them. This is the approach taken by a large majority of other HTTP servers.

Versions

CPython version: 3.10.11
werkzeug version: main

@davidism
Copy link
Member

davidism commented Jun 7, 2023

That's annoying, int parses all of +123, 1_23, and ١٢٣ as 123, as does float. This feels vaguely security related, although I can't tell how. In the future, please draft a GitHub security advisory https://github.com/pallets/werkzeug/security/advisories to report issues like this.

@davidism davidism added this to the 2.3.5 milestone Jun 7, 2023
@davidism davidism closed this as completed Jun 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants