Skip to content

Security: Path traversal in file_writer.py write_file method#9417

Open
tuanaiseo wants to merge 2 commits into
OpenMined:devfrom
tuanaiseo:contribai/fix/security/path-traversal-in-file-writer-py-write-f
Open

Security: Path traversal in file_writer.py write_file method#9417
tuanaiseo wants to merge 2 commits into
OpenMined:devfrom
tuanaiseo:contribai/fix/security/path-traversal-in-file-writer-py-write-f

Conversation

@tuanaiseo

Copy link
Copy Markdown

Problem

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.

Severity: high
File: syft_client/sync/file_writer.py

Solution

Validate that the resolved path is within base_path before writing. Use Path.resolve() and check that the resolved path starts with base_path.resolve().

Changes

  • syft_client/sync/file_writer.py (modified)
  • packages/syft-permissions/src/syft_permissions/spec/ruleset.py (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

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>
@github-actions

Copy link
Copy Markdown
Contributor

PR title does not follow the required format

Your title must follow this pattern:

type: short description

Example titles:

  • feat: add retry logic to job approval
  • fix: handle timeout in notification sender
  • docs: update syft-bg README
  • chore: bump dependencies
  • refactor: split init flow into helpers
  • test: add criteria validation tests
  • ci: add release train workflow

Allowed types: feat · fix · docs · chore · refactor · test · ci · perf · build

Just edit your PR title above to fix this. The check will re-run automatically.

See the PR guidelines for full details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant