Skip to content

Commit 700d894

Browse files
Reject backslashes in internal URL path inputs
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent c39280d commit 700d894

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

hyperbrowser/client/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def _build_url(self, path: str) -> str:
7272
stripped_path = path.strip()
7373
if not stripped_path:
7474
raise HyperbrowserError("path must not be empty")
75+
if "\\" in stripped_path:
76+
raise HyperbrowserError("path must not contain backslashes")
7577
parsed_path = urlparse(stripped_path)
7678
if parsed_path.scheme and parsed_path.netloc:
7779
raise HyperbrowserError("path must be a relative API path")

tests/test_url_building.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
4949
client._build_url(" ")
5050
with pytest.raises(HyperbrowserError, match="path must be a string"):
5151
client._build_url(123) # type: ignore[arg-type]
52+
with pytest.raises(
53+
HyperbrowserError, match="path must not contain backslashes"
54+
):
55+
client._build_url(r"\\session")
5256
with pytest.raises(HyperbrowserError, match="path must be a relative API path"):
5357
client._build_url("https://api.hyperbrowser.ai/session")
5458
finally:

0 commit comments

Comments
 (0)