Skip to content

Commit

Permalink
Add check to validate absolute URIs (#7713)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenballus authored Oct 16, 2023
1 parent 5c3adc4 commit d697d42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/7712.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add check to validate that absolute URIs have schemes.
7 changes: 7 additions & 0 deletions aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ContentEncodingError,
ContentLengthError,
InvalidHeader,
InvalidURLError,
LineTooLong,
TransferEncodingError,
)
Expand Down Expand Up @@ -578,10 +579,16 @@ def parse_message(self, lines: List[bytes]) -> RawRequestMessage:
fragment=url_fragment,
encoded=True,
)
elif path == "*" and method == "OPTIONS":
# asterisk-form,
url = URL(path, encoded=True)
else:
# absolute-form for proxy maybe,
# https://datatracker.ietf.org/doc/html/rfc7230#section-5.3.2
url = URL(path, encoded=True)
if url.scheme == "":
# not absolute-form
raise InvalidURLError(line)

# read headers
(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,11 @@ def test_http_request_parser_bad_version_number(parser: Any) -> None:
parser.feed_data(b"GET /test HTTP/1.32\r\n\r\n")


def test_http_request_parser_bad_uri(parser: Any) -> None:
with pytest.raises(http_exceptions.InvalidURLError):
parser.feed_data(b"GET ! HTTP/1.1\r\n\r\n")


@pytest.mark.parametrize("size", [40965, 8191])
def test_http_request_max_status_line(parser: Any, size: Any) -> None:
path = b"t" * (size - 5)
Expand Down

0 comments on commit d697d42

Please sign in to comment.