Security: Path traversal in file_writer.py write_file method#9417
Open
tuanaiseo wants to merge 2 commits into
Open
Security: Path traversal in file_writer.py write_file method#9417tuanaiseo wants to merge 2 commits into
tuanaiseo wants to merge 2 commits into
Conversation
The `FileWriter.write_file()` method takes a `path` string and writes directly to it without sanitization or validation. If `path` contains directory traversal sequences like `../`, it could write files outside the intended `base_path`. The `base_path` is stored but never used to validate the write location. Affected files: file_writer.py, ruleset.py Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
The `FileWriter.write_file()` method takes a `path` string and writes directly to it without sanitization or validation. If `path` contains directory traversal sequences like `../`, it could write files outside the intended `base_path`. The `base_path` is stored but never used to validate the write location. Affected files: file_writer.py, ruleset.py Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
Contributor
PR title does not follow the required formatYour title must follow this pattern: Example titles:
Allowed types: Just edit your PR title above to fix this. The check will re-run automatically. See the PR guidelines for full details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
FileWriter.write_file()method takes apathstring and writes directly to it without sanitization or validation. Ifpathcontains directory traversal sequences like../, it could write files outside the intendedbase_path. Thebase_pathis stored but never used to validate the write location.Severity:
highFile:
syft_client/sync/file_writer.pySolution
Validate that the resolved path is within
base_pathbefore writing. UsePath.resolve()and check that the resolved path starts withbase_path.resolve().Changes
syft_client/sync/file_writer.py(modified)packages/syft-permissions/src/syft_permissions/spec/ruleset.py(modified)Testing