Skip to content

gh-103204: http.server - Enforce that HTTP version numbers must consist only of digits #103205

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

Merged
merged 10 commits into from
May 12, 2023
Merged

gh-103204: http.server - Enforce that HTTP version numbers must consist only of digits #103205

merged 10 commits into from
May 12, 2023

Conversation

kenballus
Copy link
Contributor

@kenballus kenballus commented Apr 3, 2023

gh-103204: Enforce that HTTP version numbers must consist only of digits

Currently, http.server accepts requests with version numbers preceded with '+' or '-', as well as those with '_' between digits. I am not aware of any other HTTP server that accepts such requests. This PR makes it reject those requests.

Fixes #103204.

@kenballus kenballus changed the title gh-103204: Enforce that HTTP version numbers must consist only of digits gh-103204: http.server - Enforce that HTTP version numbers must consist only of digits Apr 3, 2023
@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Apr 3, 2023
@JelleZijlstra
Copy link
Member

Could you add a unit test?

kenballus and others added 2 commits May 12, 2023 11:56
@arhadthedev
Copy link
Member

@gpshead (as a more-than-twice committer into Lib/http/server.py)

@gpshead gpshead added the needs backport to 3.11 only security fixes label May 12, 2023
@gpshead gpshead self-assigned this May 12, 2023
@gpshead
Copy link
Member

gpshead commented May 12, 2023

From a protocol standpoint this PR is pedantically correct, we shouldn't have accepted other values. Not that anyone is ever going to send them. I've also added to this PR a length constraint on the values accepted for good measure.

@JelleZijlstra
Copy link
Member

.isdigit() allows any Unicode digit, so I was worried we could get into some shenanigans with weird non-ASCII digits. But it seems that the way we get this version string, that's not possible.

@gpshead gpshead merged commit cf720ac into python:main May 12, 2023
@miss-islington
Copy link
Contributor

Thanks @kenballus for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-104438 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 12, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 12, 2023
…st consist only of digits (pythonGH-103205)

Reject HTTP requests with invalid http/x.y version numbers: x or y being non-digits or too-long.

---------

(cherry picked from commit cf720ac)

Co-authored-by: Ben Kallus <49924171+kenballus@users.noreply.github.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
gpshead added a commit that referenced this pull request May 12, 2023
…ust consist only of digits (GH-103205) (#104438)

gh-103204: `http.server` - Enforce that HTTP version numbers must consist only of digits (GH-103205)

Reject HTTP requests with invalid http/x.y version numbers: x or y being non-digits or too-long.

---------

(cherry picked from commit cf720ac)

Co-authored-by: Ben Kallus <49924171+kenballus@users.noreply.github.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
@kenballus kenballus deleted the restrict-http-version-number-parsing branch October 25, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http.server parses HTTP version numbers too permissively.
6 participants