Skip to content

Commit af36070

Browse files
Reject base URLs with query strings or fragments
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent c73613d commit af36070

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

hyperbrowser/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def __post_init__(self) -> None:
3636
raise HyperbrowserError(
3737
"base_url must start with 'https://' or 'http://' and include a host"
3838
)
39+
if parsed_base_url.query or parsed_base_url.fragment:
40+
raise HyperbrowserError(
41+
"base_url must not include query parameters or fragments"
42+
)
3943
self.headers = normalize_headers(
4044
self.headers,
4145
mapping_error_message="headers must be a mapping of string pairs",

tests/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def test_client_config_from_env_rejects_base_url_without_host(monkeypatch):
125125
ClientConfig.from_env()
126126

127127

128+
def test_client_config_from_env_rejects_base_url_query_or_fragment(monkeypatch):
129+
monkeypatch.setenv("HYPERBROWSER_API_KEY", "test-key")
130+
monkeypatch.setenv("HYPERBROWSER_BASE_URL", "https://example.local?x=1")
131+
132+
with pytest.raises(HyperbrowserError, match="must not include query parameters"):
133+
ClientConfig.from_env()
134+
135+
128136
def test_client_config_normalizes_whitespace_and_trailing_slash():
129137
config = ClientConfig(api_key=" test-key ", base_url=" https://example.local/ ")
130138

@@ -156,6 +164,9 @@ def test_client_config_rejects_empty_or_invalid_base_url():
156164
with pytest.raises(HyperbrowserError, match="include a host"):
157165
ClientConfig(api_key="test-key", base_url="http://")
158166

167+
with pytest.raises(HyperbrowserError, match="must not include query parameters"):
168+
ClientConfig(api_key="test-key", base_url="https://example.local#frag")
169+
159170

160171
def test_client_config_normalizes_headers_to_internal_copy():
161172
headers = {"X-Correlation-Id": "abc123"}

0 commit comments

Comments
 (0)