Skip to content

Commit

Permalink
Merge pull request #3255 from pajod/patch-refuse-empty-request-target
Browse files Browse the repository at this point in the history
refuse empty request-target in HTTP request
  • Loading branch information
benoitc authored Aug 6, 2024
2 parents 26c22af + 9ca4f1f commit 5c0e157
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gunicorn/http/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,17 @@ def parse_request_line(self, line_bytes):
# URI
self.uri = bits[1]

# Python stdlib explicitly tells us it will not perform validation.
# https://docs.python.org/3/library/urllib.parse.html#url-parsing-security
# There are *four* `request-target` forms in rfc9112, none of them can be empty:
# 1. origin-form, which starts with a slash
# 2. absolute-form, which starts with a non-empty scheme
# 3. authority-form, (for CONNECT) which contains a colon after the host
# 4. asterisk-form, which is an asterisk (`\x2A`)
# => manually reject one always invalid URI: empty
if len(self.uri) == 0:
raise InvalidRequestLine(bytes_to_str(line_bytes))

try:
parts = split_request_uri(self.uri)
except ValueError:
Expand Down

0 comments on commit 5c0e157

Please sign in to comment.