Confine package filesystem operations - #630
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughChangesPackage filesystem security
Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens wflpkg package management filesystem operations to prevent path traversal and symlink-based escapes during remove/resolve/cache/install and archive extraction, aligning behavior with the manifest’s package-name validation rules.
Changes:
- Reuses the manifest package-name validator across resolver, cache, and remove flows.
- Adds symlink/non-directory/non-regular-file guards plus canonical containment checks before recursive mutation.
- Uses
tar::Entry::unpack_inand adds regression tests with outside-directory sentinels for key workflows.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/wflpkg/tests/workflow_integration.rs | Adds regression tests for remove_dependency invalid-name and symlink boundary rejection. |
| crates/wflpkg/tests/security_tests.rs | Expands security regression coverage for extraction, resolver boundaries, and cache hardening. |
| crates/wflpkg/src/resolver/package_path.rs | Confines package resolution to verified, non-symlinked directories and manifests. |
| crates/wflpkg/src/manifest/parser.rs | Exposes the existing package-name validator for reuse within the crate. |
| crates/wflpkg/src/commands/remove.rs | Validates names and refuses unsafe manifests/roots/targets before editing manifest or deleting. |
| crates/wflpkg/src/cache/mod.rs | Adds root/child verification helpers, strict name validation, and rejects unsafe filesystem objects during copy. |
| crates/wflpkg/src/archive.rs | Switches extraction to unpack_in with explicit “escaped destination” detection. |
| CHANGELOG.md | Documents the new package filesystem confinement behavior as a security change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if metadata.is_dir() { | ||
| copy_dir_recursive(&src_path, &dst_path)?; | ||
| } else { | ||
| } else if metadata.is_file() { | ||
| std::fs::copy(&src_path, &dst_path)?; |
| // Reject symlink and hard link entries to prevent symlink-based attacks | ||
| if entry.header().entry_type().is_symlink() || entry.header().entry_type().is_hard_link() { | ||
| return Err(PackageError::General(format!( | ||
| "Archive contains a symlink or hard link: {}", | ||
| entry_path.display() | ||
| ))); | ||
| } |
Summary
tar::Entry::unpack_inso extraction cannot traverse a pre-existing symlink ancestorSecurity impact
A repository-controlled
packagessymlink could makewfl removerecursively delete a directory outside the project. Related cache, resolver, manifest, and archive paths also trusted path joins without consistently validating each filesystem boundary. These operations now fail closed on symlinks, invalid names, non-directory targets, escaped canonical parents, and special files before mutating or executing anything outside the expected package roots.Validation
cargo test -p wflpkg --locked: all 216 tests passedcargo fmt --all -- --checkpassedgit diff --checkpassedPart of the Rust-source production-readiness work tracked in #610.
Summary by CodeRabbit