Skip to content

Commit

Permalink
Add check to validate absolute URIs (#7713)
Browse files Browse the repository at this point in the history
(cherry picked from commit d697d42)
  • Loading branch information
kenballus authored and patchback[bot] committed Oct 16, 2023
1 parent f61a4e7 commit cee0222
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 @@ -585,10 +586,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)

Check warning on line 591 in aiohttp/http_parser.py

View check run for this annotation

Codecov / codecov/patch

aiohttp/http_parser.py#L591

Added line #L591 was not covered by tests
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 @@ -741,6 +741,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, size) -> None:
path = b"t" * (size - 5)
Expand Down

0 comments on commit cee0222

Please sign in to comment.