Skip to content

Commit d1b916b

Browse files
Reject whitespace inside normalized base URLs
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 66c2939 commit d1b916b

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

hyperbrowser/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def normalize_base_url(base_url: str) -> str:
3636
raise HyperbrowserError("base_url must not be empty")
3737
if "\n" in normalized_base_url or "\r" in normalized_base_url:
3838
raise HyperbrowserError("base_url must not contain newline characters")
39+
if any(character.isspace() for character in normalized_base_url):
40+
raise HyperbrowserError("base_url must not contain whitespace characters")
3941

4042
parsed_base_url = urlparse(normalized_base_url)
4143
if (

tests/test_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ def test_client_config_rejects_empty_or_invalid_base_url():
214214
):
215215
ClientConfig(api_key="test-key", base_url="https://example.local/\napi")
216216

217+
with pytest.raises(
218+
HyperbrowserError, match="base_url must not contain whitespace characters"
219+
):
220+
ClientConfig(api_key="test-key", base_url="https://example .local")
221+
217222

218223
def test_client_config_normalizes_headers_to_internal_copy():
219224
headers = {"X-Correlation-Id": "abc123"}
@@ -323,3 +328,8 @@ def test_client_config_normalize_base_url_validates_and_normalizes():
323328
HyperbrowserError, match="base_url must not contain newline characters"
324329
):
325330
ClientConfig.normalize_base_url("https://example.local/\napi")
331+
332+
with pytest.raises(
333+
HyperbrowserError, match="base_url must not contain whitespace characters"
334+
):
335+
ClientConfig.normalize_base_url("https://example.local/\tapi")

tests/test_url_building.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ def test_client_build_url_rejects_runtime_invalid_base_url_changes():
104104
):
105105
client._build_url("/session")
106106

107+
client.config.base_url = "https://example .local"
108+
with pytest.raises(
109+
HyperbrowserError, match="base_url must not contain whitespace characters"
110+
):
111+
client._build_url("/session")
112+
107113
client.config.base_url = " "
108114
with pytest.raises(HyperbrowserError, match="base_url must not be empty"):
109115
client._build_url("/session")

0 commit comments

Comments
 (0)