Skip to content

Confine package filesystem operations - #630

Merged
logbie merged 3 commits into
mainfrom
agent/harden-wflpkg-remove
Jul 17, 2026
Merged

Confine package filesystem operations#630
logbie merged 3 commits into
mainfrom
agent/harden-wflpkg-remove

Conversation

@logbie

@logbie logbie commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • reuse the manifest's exact package-name validator in cache, resolver, and remove paths
  • reject symlinked or non-directory cache/package roots and verify canonical parent containment before recursive mutations
  • reject symlinked/non-regular project and installed-package manifests
  • use tar::Entry::unpack_in so extraction cannot traverse a pre-existing symlink ancestor
  • reject special filesystem objects while copying packages
  • add regression coverage with outside-directory sentinels for removal, resolution, caching, installation, and extraction

Security impact

A repository-controlled packages symlink could make wfl remove recursively 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 passed
  • cargo fmt --all -- --check passed
  • git diff --check passed
  • all GitHub CI, config lint, and review checks passed on the final head

Part of the Rust-source production-readiness work tracked in #610.

Summary by CodeRabbit

  • Security
    • Hardened package and cache filesystem operations against symlink-based traversal and unsafe paths.
    • Validated package names and prevented operations outside expected project or cache directories.
    • Secured archive extraction from escaping its destination.
    • Added safeguards when resolving, installing, storing, or removing packages and manifests.
  • Tests
    • Added regression coverage for unsafe paths, symlinked directories and manifests, and archive extraction escapes.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d3b6e29c-0db3-41dd-bfe7-5f5fed9dcd55

📥 Commits

Reviewing files that changed from the base of the PR and between 090b7cf and 74af821.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • crates/wflpkg/src/archive.rs
  • crates/wflpkg/src/cache/mod.rs
  • crates/wflpkg/src/commands/remove.rs
  • crates/wflpkg/src/manifest/parser.rs
  • crates/wflpkg/src/resolver/package_path.rs
  • crates/wflpkg/tests/security_tests.rs
  • crates/wflpkg/tests/workflow_integration.rs

📝 Walkthrough

Walkthrough

Changes

Package filesystem security

Layer / File(s) Summary
Archive extraction and package validation
crates/wflpkg/src/archive.rs, crates/wflpkg/src/manifest/parser.rs, crates/wflpkg/src/resolver/package_path.rs, crates/wflpkg/tests/security_tests.rs, CHANGELOG.md
Shared package-name validation is reused across modules, archive extraction rejects destination escapes, and security tests cover invalid names, symlinked roots, and manifests.
Cache path verification and package transfer
crates/wflpkg/src/cache/mod.rs, crates/wflpkg/tests/security_tests.rs
Cache storage, lookup, installation, and recursive copying verify canonical directories and reject symlinked or unsupported filesystem entries.
Package resolution and dependency removal
crates/wflpkg/src/resolver/package_path.rs, crates/wflpkg/src/commands/remove.rs, crates/wflpkg/tests/workflow_integration.rs
Resolution and dependency removal validate manifests and package directories before returning paths or deleting local packages. Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/harden-wflpkg-remove

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@logbie
logbie marked this pull request as ready for review July 16, 2026 18:13
Copilot AI review requested due to automatic review settings July 16, 2026 18:13

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_in and 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.

Comment on lines 311 to 314
if metadata.is_dir() {
copy_dir_recursive(&src_path, &dst_path)?;
} else {
} else if metadata.is_file() {
std::fs::copy(&src_path, &dst_path)?;
Copilot AI review requested due to automatic review settings July 16, 2026 18:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment on lines 296 to 302
// 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()
)));
}
Copilot AI review requested due to automatic review settings July 17, 2026 05:00
@logbie
logbie merged commit a10cf06 into main Jul 17, 2026
7 of 8 checks passed
@logbie
logbie deleted the agent/harden-wflpkg-remove branch July 17, 2026 05:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants