Skip to content

fix(Untar): ensure files are extracted inside the destination directory - #785

Merged
michaeljguarino merged 2 commits into
mainfrom
fix/code-scanning-alert
Jul 21, 2026
Merged

fix(Untar): ensure files are extracted inside the destination directory#785
michaeljguarino merged 2 commits into
mainfrom
fix/code-scanning-alert

Conversation

@floreks

@floreks floreks commented Jul 21, 2026

Copy link
Copy Markdown
Member
  • Verify target paths to prevent extraction outside the destination
  • Add unit tests for validation of target path and content extraction within destination directory

Summary

Labels

Test Plan

Checklist

  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • I have added relevant labels to this PR to help with categorization for release notes.

- Verify target paths to prevent extraction outside the destination
- Add unit tests for validation of target path and content extraction within destination directory
@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR keeps tar extraction inside the destination directory. The main changes are:

  • Validates archive entry paths before extraction.
  • Uses root-scoped file and directory operations.
  • Adds tests for traversal, symlink escape, and normal extraction.

Confidence Score: 5/5

This looks safe to merge.

  • The updated extraction path addresses the reported symlink escape.
  • Extracting to the filesystem root no longer depends on a broken string-prefix check.
  • No blocking issues were found in the changed code.

Important Files Changed

Filename Overview
pkg/utils/tar.go Adds path validation and root-scoped extraction to keep files within the destination.
pkg/utils/tar_test.go Adds coverage for valid extraction, parent traversal, and pre-existing symlink escapes.

Reviews (2): Last reviewed commit: "fix(Untar): enhance path security and va..." | Re-trigger Greptile

Comment thread pkg/utils/tar.go Outdated
Comment thread pkg/utils/tar.go Outdated
@floreks floreks added the bug-fix This pull request fixes a bug label Jul 21, 2026
- Use `os.OpenRoot` and consolidate directory creation
- Check local path using `filepath.IsLocal`
- Refactor `makeDir` to use `root.MkdirAll`
- Improve error messaging for file extraction
- Add test to reject symlinks resolving outside the destination
@floreks

floreks commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

@greptileai

@michaeljguarino
michaeljguarino merged commit b542720 into main Jul 21, 2026
15 checks passed
@michaeljguarino
michaeljguarino deleted the fix/code-scanning-alert branch July 21, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix This pull request fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants