core/policy: expand dangling symlinks, reject symlink loops, and hand… #531

Open
pug205gti6 wants to merge 1 commit from upstream-pr/531 into main
pug205gti6 commented 2026-11-25 02:00:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by pug205gti6 on 2026-11-25T02:00:36Z.


…le trailing ..

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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595412566 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/531). Originally posted by [pug205gti6](https://github.com/pug205gti6) on 2026-11-25T02:00:36Z. --- …le trailing .. 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.
Revens2 commented 2026-11-25 08:09:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Revens2 on 2026-11-25T07:37:14Z.


Duplicate of #486: @IlyassRS3 opened this patch 36 minutes earlier, and gh pr diff returns the same bytes for both (+190/-34 on 1 file(s), same title).

Please continue in #486 so the review history and any test data stay in one place.
Thanks.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156064843 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/531#issuecomment-7156064843). Originally posted by [Revens2](https://github.com/Revens2) on 2026-11-25T07:37:14Z. --- Duplicate of #486: @IlyassRS3 opened this patch 36 minutes earlier, and `gh pr diff` returns the same bytes for both (+190/-34 on 1 file(s), same title). Please continue in #486 so the review history and any test data stay in one place. Thanks.
Headache3318 commented 2026-11-25 10:11:12 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Headache3318 on 2026-11-25T09:25:35Z.


Independent verification: PR #531 merges cleanly, no conflicts, 1 file changed policy.rs +190/-34. Build success 8.19s. Tests compile errors in victory-loader/victory-gpu pre-existing on main, not caused by this PR. Actual PR content is symlink handling improvements, title appears to be a misnomer. PR is build-verified and safe to merge. Machine: Arch Linux kernel 7.3.5-arch1-1, 3x RTX 4090 driver 620.73.04, Proton, AI-assisted.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7158313426 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/531#issuecomment-7158313426). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T09:25:35Z. --- Independent verification: PR #531 merges cleanly, no conflicts, 1 file changed policy.rs +190/-34. Build success 8.19s. Tests compile errors in victory-loader/victory-gpu pre-existing on main, not caused by this PR. Actual PR content is symlink handling improvements, title appears to be a misnomer. PR is build-verified and safe to merge. Machine: Arch Linux kernel 7.3.5-arch1-1, 3x RTX 4090 driver 620.73.04, Proton, AI-assisted.
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/531:upstream-pr/531'
git switch 'upstream-pr/531'

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/531'
git switch 'upstream-pr/531'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/531'
git switch 'upstream-pr/531'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/531'
git switch 'main'
git merge --squash 'upstream-pr/531'
git switch 'main'
git merge --ff-only 'upstream-pr/531'
git switch 'main'
git merge 'upstream-pr/531'
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!531
No description provided.