Skip to content

Commit 18c541b

Browse files
Reject control characters in API paths
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 414a14e commit 18c541b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

hyperbrowser/client/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ def _build_url(self, path: str) -> str:
102102
raise HyperbrowserError("path must not contain newline characters")
103103
if any(character.isspace() for character in decoded_path):
104104
raise HyperbrowserError("path must not contain whitespace characters")
105+
if any(
106+
ord(character) < 32 or ord(character) == 127 for character in decoded_path
107+
):
108+
raise HyperbrowserError("path must not contain control characters")
105109
normalized_segments = [
106110
segment for segment in decoded_path.split("/") if segment
107111
]

tests/test_url_building.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
146146
HyperbrowserError, match="path must not contain whitespace characters"
147147
):
148148
client._build_url("/session name")
149+
with pytest.raises(
150+
HyperbrowserError, match="path must not contain control characters"
151+
):
152+
client._build_url("/session\x00name")
149153
with pytest.raises(HyperbrowserError, match="path must be a relative API path"):
150154
client._build_url("https://api.hyperbrowser.ai/session")
151155
with pytest.raises(HyperbrowserError, match="path must be a relative API path"):
@@ -208,6 +212,10 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
208212
HyperbrowserError, match="path must not contain whitespace characters"
209213
):
210214
client._build_url("/api/%09segment")
215+
with pytest.raises(
216+
HyperbrowserError, match="path must not contain control characters"
217+
):
218+
client._build_url("/api/%00segment")
211219
finally:
212220
client.close()
213221

0 commit comments

Comments
 (0)