Skip to content

Commit 414a14e

Browse files
Harden URL path checks against deeply encoded payloads
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 09038ee commit 414a14e

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎hyperbrowser/client/base.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _build_url(self, path: str) -> str:
9191
f"?{normalized_parts.query}" if normalized_parts.query else ""
9292
)
9393
decoded_path = normalized_path_only
94-
for _ in range(3):
94+
for _ in range(10):
9595
next_decoded_path = unquote(decoded_path)
9696
if next_decoded_path == decoded_path:
9797
break

‎tests/test_url_building.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
176176
HyperbrowserError, match="path must not contain relative path segments"
177177
):
178178
client._build_url("/%252e%252e/session")
179+
with pytest.raises(
180+
HyperbrowserError, match="path must not contain relative path segments"
181+
):
182+
client._build_url("/%2525252e%2525252e/session")
179183
with pytest.raises(
180184
HyperbrowserError, match="path must not contain backslashes"
181185
):
@@ -184,6 +188,10 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
184188
HyperbrowserError, match="path must not contain backslashes"
185189
):
186190
client._build_url("/api/%255Csession")
191+
with pytest.raises(
192+
HyperbrowserError, match="path must not contain backslashes"
193+
):
194+
client._build_url("/api/%2525255Csession")
187195
with pytest.raises(
188196
HyperbrowserError, match="path must not contain newline characters"
189197
):

0 commit comments

Comments
 (0)