Skip to content

Commit 801f3fd

Browse files
Reject URL fragments in internal path builder
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 9493d97 commit 801f3fd

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
@@ -77,6 +77,8 @@ def _build_url(self, path: str) -> str:
7777
parsed_path = urlparse(stripped_path)
7878
if parsed_path.scheme:
7979
raise HyperbrowserError("path must be a relative API path")
80+
if parsed_path.fragment:
81+
raise HyperbrowserError("path must not include URL fragments")
8082
normalized_path = f"/{stripped_path.lstrip('/')}"
8183
base_has_api_suffix = (
8284
urlparse(self.config.base_url).path.rstrip("/").endswith("/api")

tests/test_url_building.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
9797
client._build_url("mailto:ops@hyperbrowser.ai")
9898
with pytest.raises(HyperbrowserError, match="path must be a relative API path"):
9999
client._build_url("http:example.com")
100+
with pytest.raises(
101+
HyperbrowserError, match="path must not include URL fragments"
102+
):
103+
client._build_url("/session#fragment")
100104
finally:
101105
client.close()
102106

0 commit comments

Comments
 (0)