Skip to content

Commit bf7d760

Browse files
Reject unencoded whitespace and control chars in URL queries
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 5fd7798 commit bf7d760

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

hyperbrowser/client/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ def _build_url(self, path: str) -> str:
8888
raise HyperbrowserError("path must be a relative API path")
8989
if parsed_path.fragment:
9090
raise HyperbrowserError("path must not include URL fragments")
91+
if any(
92+
character.isspace() or ord(character) < 32 or ord(character) == 127
93+
for character in parsed_path.query
94+
):
95+
raise HyperbrowserError(
96+
"path query must not contain unencoded whitespace or control characters"
97+
)
9198
normalized_path = f"/{stripped_path.lstrip('/')}"
9299
normalized_parts = urlparse(normalized_path)
93100
normalized_path_only = normalized_parts.path

tests/test_url_building.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
321321
HyperbrowserError, match="path must not contain encoded fragment delimiters"
322322
):
323323
client._build_url("/api/%23segment")
324+
with pytest.raises(
325+
HyperbrowserError,
326+
match="path query must not contain unencoded whitespace or control characters",
327+
):
328+
client._build_url("/session?foo=bar baz")
329+
with pytest.raises(
330+
HyperbrowserError,
331+
match="path query must not contain unencoded whitespace or control characters",
332+
):
333+
client._build_url("/session?foo=bar\x00baz")
324334
nested_encoded_segment = "%2e"
325335
for _ in range(11):
326336
nested_encoded_segment = quote(nested_encoded_segment, safe="")

0 commit comments

Comments
 (0)