Skip to content

Commit f71b71c

Browse files
Reject encoded backslashes and newlines in API paths
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 34fa8aa commit f71b71c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

hyperbrowser/client/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def _build_url(self, path: str) -> str:
9191
f"?{normalized_parts.query}" if normalized_parts.query else ""
9292
)
9393
decoded_path = unquote(normalized_path_only)
94+
if "\\" in decoded_path:
95+
raise HyperbrowserError("path must not contain backslashes")
96+
if "\n" in decoded_path or "\r" in decoded_path:
97+
raise HyperbrowserError("path must not contain newline characters")
9498
normalized_segments = [
9599
segment for segment in decoded_path.split("/") if segment
96100
]

tests/test_url_building.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
156156
HyperbrowserError, match="path must not contain relative path segments"
157157
):
158158
client._build_url("/api/%2E/session")
159+
with pytest.raises(
160+
HyperbrowserError, match="path must not contain backslashes"
161+
):
162+
client._build_url("/api/%5Csession")
163+
with pytest.raises(
164+
HyperbrowserError, match="path must not contain newline characters"
165+
):
166+
client._build_url("/api/%0Asegment")
159167
finally:
160168
client.close()
161169

0 commit comments

Comments
 (0)