Skip to content

Commit 34fa8aa

Browse files
Block percent-encoded path traversal segments
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 2830501 commit 34fa8aa

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

hyperbrowser/client/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from urllib.parse import urlparse
2+
from urllib.parse import unquote, urlparse
33
from typing import Mapping, Optional, Type, Union
44

55
from hyperbrowser.exceptions import HyperbrowserError
@@ -90,8 +90,9 @@ def _build_url(self, path: str) -> str:
9090
normalized_query_suffix = (
9191
f"?{normalized_parts.query}" if normalized_parts.query else ""
9292
)
93+
decoded_path = unquote(normalized_path_only)
9394
normalized_segments = [
94-
segment for segment in normalized_path_only.split("/") if segment
95+
segment for segment in decoded_path.split("/") if segment
9596
]
9697
if any(segment in {".", ".."} for segment in normalized_segments):
9798
raise HyperbrowserError("path must not contain relative path segments")

tests/test_url_building.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
148148
HyperbrowserError, match="path must not contain relative path segments"
149149
):
150150
client._build_url("/api/./session")
151+
with pytest.raises(
152+
HyperbrowserError, match="path must not contain relative path segments"
153+
):
154+
client._build_url("/%2e%2e/session")
155+
with pytest.raises(
156+
HyperbrowserError, match="path must not contain relative path segments"
157+
):
158+
client._build_url("/api/%2E/session")
151159
finally:
152160
client.close()
153161

0 commit comments

Comments
 (0)