Skip to content

Commit 9cf998d

Browse files
Reject encoded delimiters in base URL hosts
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent ba99b76 commit 9cf998d

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎hyperbrowser/config.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def normalize_base_url(base_url: str) -> str:
103103
for character in decoded_base_netloc
104104
):
105105
raise HyperbrowserError("base_url host must not contain control characters")
106+
if any(character in {"?", "#", "/"} for character in decoded_base_netloc):
107+
raise HyperbrowserError(
108+
"base_url host must not contain encoded delimiter characters"
109+
)
106110
return normalized_base_url
107111

108112
@classmethod

‎tests/test_config.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ def test_client_config_normalize_base_url_validates_and_normalizes():
405405
HyperbrowserError, match="base_url host must not contain control characters"
406406
):
407407
ClientConfig.normalize_base_url("https://example.local%2500")
408+
with pytest.raises(
409+
HyperbrowserError,
410+
match="base_url host must not contain encoded delimiter characters",
411+
):
412+
ClientConfig.normalize_base_url("https://example.local%252Fapi")
408413
with pytest.raises(
409414
HyperbrowserError,
410415
match="base_url path must not contain encoded query or fragment delimiters",

‎tests/test_url_building.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ def test_client_build_url_rejects_runtime_invalid_base_url_changes():
136136
):
137137
client._build_url("/session")
138138

139+
client.config.base_url = "https://example.local%2Fapi"
140+
with pytest.raises(
141+
HyperbrowserError,
142+
match="base_url host must not contain encoded delimiter characters",
143+
):
144+
client._build_url("/session")
145+
139146
client.config.base_url = "https://user:pass@example.local"
140147
with pytest.raises(
141148
HyperbrowserError, match="base_url must not include user credentials"

0 commit comments

Comments
 (0)