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

Open
IlyassRS3 wants to merge 1 commit from upstream-pr/486 into main
IlyassRS3 commented 2026-11-25 01:24:57 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by IlyassRS3 on 2026-11-25T01:24:57Z.


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).
<!-- greyfinch-sync:fxceless/victory-fork:issue:6594966885 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/486). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T01:24:57Z. --- ### 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`).
copilot-pull-request-reviewer[bot commented 2026-11-25 02:09:44 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T01:25:12Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:fxceless/victory-fork:review:6050133580 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/486#pullrequestreview-6050133580). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-25T01:25:12Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/486:upstream-pr/486'
git switch 'upstream-pr/486'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/486'
git switch 'upstream-pr/486'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/486'
git switch 'upstream-pr/486'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/486'
git switch 'main'
git merge --squash 'upstream-pr/486'
git switch 'main'
git merge --ff-only 'upstream-pr/486'
git switch 'main'
git merge 'upstream-pr/486'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!486
No description provided.