Skip to content

Commit 6711ce3

Browse files
Validate decoded base URL components are strings
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 487da30 commit 6711ce3

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

hyperbrowser/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ def _decode_url_component_with_limit(value: str, *, component_label: str) -> str
6060
@staticmethod
6161
def _safe_unquote(value: str, *, component_label: str) -> str:
6262
try:
63-
return unquote(value)
63+
decoded_value = unquote(value)
64+
if not isinstance(decoded_value, str):
65+
raise TypeError("decoded URL component must be a string")
66+
return decoded_value
6467
except HyperbrowserError:
6568
raise
6669
except Exception as exc:

tests/test_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,20 @@ def _raise_hyperbrowser_error(_value: str) -> str:
503503
assert exc_info.value.original_error is None
504504

505505

506+
def test_client_config_normalize_base_url_wraps_non_string_decode_results(
507+
monkeypatch: pytest.MonkeyPatch,
508+
):
509+
def _return_bytes(_value: str) -> bytes:
510+
return b"/api"
511+
512+
monkeypatch.setattr(config_module, "unquote", _return_bytes)
513+
514+
with pytest.raises(HyperbrowserError, match="Failed to decode base_url path") as exc_info:
515+
ClientConfig.normalize_base_url("https://example.local/api")
516+
517+
assert exc_info.value.original_error is not None
518+
519+
506520
def test_client_config_normalize_base_url_preserves_invalid_port_original_error():
507521
with pytest.raises(
508522
HyperbrowserError, match="base_url must contain a valid port number"

0 commit comments

Comments
 (0)