Skip to content

Commit 41a1b0f

Browse files
authored
Merge pull request #135 from athrael-soju/alert-autofix-6
Potential fix for code scanning alert no. 6: Uncontrolled data used in path expression
2 parents d79e4ea + bc6f47d commit 41a1b0f

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎backend/clients/local_storage_utils.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ def resolve_storage_path(bucket: str, relative_path: str) -> Path:
5353
if bucket != bucket_name:
5454
raise InvalidBucketError(f"Invalid bucket: {bucket}")
5555

56-
# Construct file path
57-
file_path = storage_base / bucket / relative_path
56+
# Construct file path rooted in the configured bucket directory
57+
bucket_base = storage_base / bucket_name
58+
file_path = bucket_base / relative_path
5859
resolved_path = file_path.resolve()
59-
storage_resolved = storage_base.resolve()
60+
bucket_resolved = bucket_base.resolve()
6061

61-
# Security: ensure path stays within storage directory
62-
if not resolved_path.is_relative_to(storage_resolved):
62+
# Security: ensure path stays within the bucket directory
63+
if not resolved_path.is_relative_to(bucket_resolved):
6364
logger.warning(f"Path traversal attempt detected: {relative_path}")
6465
raise PathTraversalError("Path traversal detected")
6566

0 commit comments

Comments
 (0)