Potential fix for code scanning alert no. 6: Uncontrolled data used in path expression #135
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/athrael-soju/Snappy/security/code-scanning/6
General fix approach: When constructing filesystem paths from user input, anchor them to a known-safe base and enforce that the resolved path remains within that base. In this case, we should (1) treat the bucket as configuration once it’s validated, not as part of the untrusted path, and (2) ensure that the security check compares against the bucket’s directory (e.g.,
<storage_base>/<bucket_name>) instead of just the broad storage base. The rest of the code can remain the same.Concrete changes in
backend/clients/local_storage_utils.py:resolve_storage_path, after validating the bucket value, derive abucket_basedirectory using the configured bucket name, not the user-provided argument.file_pathusingbucket_base / relative_pathinstead ofstorage_base / bucket / relative_path.bucket_resolved = bucket_base.resolve()and then useresolved_path.is_relative_to(bucket_resolved)instead of checking only againststorage_base.This preserves existing behavior (only the configured bucket is allowed; files must exist; traversal is blocked) while tightening the root against which traversal is enforced. No new methods or imports are needed; we only adjust the path construction and comparison logic in the shown function. This single change also safely handles calls from
files.pyand from_load_image_from_urlininterpretability.pythat flow throughparse_files_urland intoresolve_storage_path.Suggested fixes powered by Copilot Autofix. Review carefully before merging.