core/policy: expand dangling symlinks, reject symlink loops, and handle .. after missing paths #486

Open
github-bot wants to merge 1 commit from github-bot/gh-486 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 01:24 UTC · original
IlyassRS3:fix/policy-dangling-symlink-and-dotdot → main · +190 −34 · 1 files · 1 commits · open

Summary

Hardens victory_core::policy::resolve (crates/victory-core/src/policy.rs), which enforces Rule #1 (ensure_outside_repo), to walk components left-to-right and explicitly expand symbolic links (including dangling ones) up to a bounded hop limit (MAX_SYMLINK_HOPS = 40).

Bugs fixed

Previously, resolve() called std::fs::canonicalize in a loop and peeled the tail via Path::file_name() on any error:

  1. Rule #1 bypass via dangling symlinks: If <outside>/link is a symlink pointing to <repo>/not-yet-created, canonicalize() fails with NotFound, resolve() peels link and returns <outside>/link, and ensure_outside_repo returns Ok(()) — allowing caches/outputs to be created inside the repository once the target directory is created.
  2. Symlink loops silently accepted: canonicalize() fails with ELOOP, which was treated identically to NotFound, peeling the loop component and returning Ok(()) instead of failing closed.
  3. Failure on .. after a non-existent component: Path::file_name() returns None for .., causing valid paths outside the repository like <outside>/missing/.. to fail with PolicyError::Io.

Implementation notes

  • Preserves Windows extended-length/canonical prefix handling by canonicalizing RootDir and every existing non-symlink component via std::fs::canonicalize, and also falls back to read_link when canonicalize fails on a reparse point (such as a dangling NTFS junction) where file_type().is_symlink() may be false.
  • Keeps Unix symlink creation tests under #[cfg(unix)] so Windows runners without SeCreateSymbolicLinkPrivilege stay green, while running the .. regression tests on all platforms.

Verification

  • AI-assisted: Yes (written and verified with AI assistance).
  • Environment: macOS arm64 (Apple M5), CPU-only, Rust 1.98.1, no Windows GPU / no game files.
  • cargo test --locked -p victory-core -p xtask: 14 passed, 0 failed (victory-core, including 3 new tests: handles_dotdot_after_nonexistent_component, rejects_dangling_symlinks_into_repo, rejects_symlink_loops) + 4 passed, 0 failed (xtask, including repository_passes_policy).
  • cargo clippy --locked -p victory-core --all-targets -- -D warnings: 0 warnings.
  • cargo clippy --locked -p victory-core --all-targets --target x86_64-pc-windows-msvc -- -D warnings and --all-features: 0 warnings.
  • Mutation check on unpatched upstream/main (a803c87): all 3 new tests fail on unpatched upstream/main (4 passed; 3 failed).
**@⁠IlyassRS3** on GitHub · 2026-11-25 01:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/486) `IlyassRS3:fix/policy-dangling-symlink-and-dotdot` → `main` · +190 −34 · 1 files · 1 commits · open ### Summary Hardens `victory_core::policy::resolve` (`crates/victory-core/src/policy.rs`), which enforces Rule #1 (`ensure_outside_repo`), to walk components left-to-right and explicitly expand symbolic links (including dangling ones) up to a bounded hop limit (`MAX_SYMLINK_HOPS = 40`). ### Bugs fixed Previously, `resolve()` called `std::fs::canonicalize` in a loop and peeled the tail via `Path::file_name()` on *any* error: 1. **Rule #1 bypass via dangling symlinks**: If `<outside>/link` is a symlink pointing to `<repo>/not-yet-created`, `canonicalize()` fails with `NotFound`, `resolve()` peels `link` and returns `<outside>/link`, and `ensure_outside_repo` returns `Ok(())` — allowing caches/outputs to be created inside the repository once the target directory is created. 2. **Symlink loops silently accepted**: `canonicalize()` fails with `ELOOP`, which was treated identically to `NotFound`, peeling the loop component and returning `Ok(())` instead of failing closed. 3. **Failure on `..` after a non-existent component**: `Path::file_name()` returns `None` for `..`, causing valid paths outside the repository like `<outside>/missing/..` to fail with `PolicyError::Io`. ### Implementation notes - Preserves Windows extended-length/canonical prefix handling by canonicalizing `RootDir` and every existing non-symlink component via `std::fs::canonicalize`, and also falls back to `read_link` when `canonicalize` fails on a reparse point (such as a dangling NTFS junction) where `file_type().is_symlink()` may be false. - Keeps Unix symlink creation tests under `#[cfg(unix)]` so Windows runners without `SeCreateSymbolicLinkPrivilege` stay green, while running the `..` regression tests on all platforms. ### Verification - **AI-assisted**: Yes (written and verified with AI assistance). - **Environment**: macOS arm64 (Apple M5), CPU-only, Rust `1.98.1`, no Windows GPU / no game files. - `cargo test --locked -p victory-core -p xtask`: **14 passed, 0 failed** (`victory-core`, including 3 new tests: `handles_dotdot_after_nonexistent_component`, `rejects_dangling_symlinks_into_repo`, `rejects_symlink_loops`) + **4 passed, 0 failed** (`xtask`, including `repository_passes_policy`). - `cargo clippy --locked -p victory-core --all-targets -- -D warnings`: **0 warnings**. - `cargo clippy --locked -p victory-core --all-targets --target x86_64-pc-windows-msvc -- -D warnings` and `--all-features`: **0 warnings**. - **Mutation check on unpatched `upstream/main` (`a803c87`)**: all 3 new tests fail on unpatched `upstream/main` (`4 passed; 3 failed`).
Previously, policy::resolve peeled path components with Path::file_name()
on any std::fs::canonicalize error. That caused three bugs in
ensure_outside_repo:

1. Policy bypass via dangling symlinks: a symlink outside the repo whose
   target inside the repo does not exist yet caused canonicalize() to
   return NotFound; resolve() peeled the link name and returned the
   outside path, letting ensure_outside_repo return Ok(()).
2. Symlink loops silently accepted: canonicalize() returned ELOOP, which
   resolve() treated like NotFound, peeled the link name, and returned Ok(()).
3. Trailing `..` after a missing component errored: Path::file_name()
   returns None on `..`, so paths like `<outside>/missing/..` returned
   PolicyError::Io.

Walk components left-to-right, canonicalizing existing prefixes while
explicitly expanding symbolic links (and dangling reparse points) via
read_link up to MAX_SYMLINK_HOPS (40), returning PolicyError::Io on
loops or non-NotFound errors.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:44:28 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/486/head:github-bot/gh-486'
git switch 'github-bot/gh-486'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-486'
git switch 'github-bot/gh-486'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-486'
git switch 'github-bot/gh-486'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-486'
git switch 'main'
git merge --squash 'github-bot/gh-486'
git switch 'main'
git merge --ff-only 'github-bot/gh-486'
git switch 'main'
git merge 'github-bot/gh-486'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.