Skip to content

http.server parses HTTP version numbers too permissively. #103204

Closed

Description

@kenballus

http.server parses HTTP version numbers too permissively.

http.server accepts request lines with HTTP version numbers that have '_', '+', and '-'.

Reproduction steps:

(Requires netcat)

python3 -m http.server --bind 127.0.0.1
printf 'GET / HTTP/-9_9_9.+9_9_9\r\n\r\n' | nc 127.0.0.1 8000

Justification

Here are the HTTP-version definitions from each of the three HTTP RFCs:

  • RFC 2616:
HTTP-Version   = "HTTP" "/" 1*DIGIT "." 1*DIGIT
  • RFC 7230:
HTTP-version  = HTTP-name "/" DIGIT "." DIGIT
HTTP-name     = %x48.54.54.50 ; "HTTP", case-sensitive
  • RFC 9112:
HTTP-version  = HTTP-name "/" DIGIT "." DIGIT
HTTP-name     = %s"HTTP"

I understand allowing multiple digits for backwards-compatibility with RFC 2616, but I don't think it makes sense to let the specifics of int leak out into the world. We should at least ensure that only digits are permitted in HTTP version numbers.

My environment

  • CPython 3.12.0a6+
  • Operating system and architecture: Arch Linux on x86_64

Linked PRs

Activity

  1. added
    type-bug
    on Apr 3, 2023
  2. added
    stdlib
    on Apr 3, 2023
  3. self-assigned this
    on May 12, 2023
  4. added a commit that references this issue on May 12, 2023
  5. added a commit that references this issue on May 12, 2023
  6. added a commit that references this issue on May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibtype-bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions