Core: resolve policy::resolve paths component by component to close symlink dotdot bypasses #2528

Closed
reeledMarek wants to merge 1 commit from upstream-pr/2530 into main
reeledMarek commented 2026-11-25 15:23:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:23:39Z.


Problem

victory_core::policy::resolve canonicalized the longest existing prefix, appended the non-existing tail, and ran lexical normalize(&out) without re-canonicalizing the result.

For a path such as <outside>/missing/../../<link>/out where <link> is a symlink into a subdirectory of a repository containing .victory-root, resolve stopped at <outside>, collapsed .. lexically to <parent>/<link>/out, and never resolved <link>. ensure_outside_repo then returned Ok(()), allowing downstream create_dir_all to write inside the repository.

Fix

  • Extract canonicalize_prefix returning (normalized_path, had_parent).
  • When .. components were collapsed in the non-existing tail, run one second canonicalize_prefix pass on the normalized path so any exposed symlinks are resolved.

Testing

  • Added synthetic test rejects_symlink_into_repo_exposed_after_dotdot_collapse in crates/victory-core/src/policy.rs.
  • Verified cargo test -p victory-core --locked, cargo clippy -p victory-core --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings, and cargo test -p xtask --locked.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6607868574 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2530). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:23:39Z. --- ### Problem `victory_core::policy::resolve` canonicalized the longest existing prefix, appended the non-existing tail, and ran lexical `normalize(&out)` without re-canonicalizing the result. For a path such as `<outside>/missing/../../<link>/out` where `<link>` is a symlink into a subdirectory of a repository containing `.victory-root`, `resolve` stopped at `<outside>`, collapsed `..` lexically to `<parent>/<link>/out`, and never resolved `<link>`. `ensure_outside_repo` then returned `Ok(())`, allowing downstream `create_dir_all` to write inside the repository. ### Fix - Extract `canonicalize_prefix` returning `(normalized_path, had_parent)`. - When `..` components were collapsed in the non-existing tail, run one second `canonicalize_prefix` pass on the normalized path so any exposed symlinks are resolved. ### Testing - Added synthetic test `rejects_symlink_into_repo_exposed_after_dotdot_collapse` in `crates/victory-core/src/policy.rs`. - Verified `cargo test -p victory-core --locked`, `cargo clippy -p victory-core --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings`, and `cargo test -p xtask --locked`.
Marvisak commented 2026-11-25 19:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:33:09Z.


Automated triage for the maintainers.

Needs work. The new head rewrites resolve in crates/victory-core/src/policy.rs to walk components and canonicalize each existing prefix before applying .., and drops normalize. On POSIX semantics this does close the <link>/../x case from the last review. On Windows, the only platform VIctory builds for and the only one CI runs, it still fixes nothing, and the new Case 2 assertion describes the wrong target:

  1. Win32 collapses .. as text before it resolves anything. So create_dir_all("<outside>\\missing\\..\\..\\link-sub\\..\\out") creates <tmp>\\out, not <repo>\\out. The test's comment ("steps out of <repo>/sub into <repo>/out") does not hold there. The new code now rejects a path that Windows would write outside the repository. That is stricter, so it is harmless, but the test asserts behaviour Windows does not have. Case 1 was already refused on main, because canonicalize succeeds on the whole prefix.
  2. The reply mentions a Windows \\?\\ verbatim-path test case, but the diff has none. It contains only rejects_symlink_into_repo_across_dotdot_components, which builds ordinary paths with join.

What would change the verdict: a test that fails on main in the Windows CI (for example the verbatim-path case you describe, if .. in such a path really reaches the filesystem), or a maintainer decision that POSIX semantics matter for this crate. In either case, Case 2's comment should say which platform it applies to.

Reply to the author: thanks for the rewrite. Point 2 is addressed for POSIX paths. Point 1, a failing case on Windows, is still open, because the verbatim-path test the reply mentions is not in the pushed commit (a10368d).

CI: check passed (Windows).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171063927 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2530#issuecomment-7171063927). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:33:09Z. --- <!-- victory-triage v1 head=a10368dc27ba18664a8f2653b7964e5593239186 verdict=needs-work at=2026-11-25T20:18:54Z --> Automated triage for the maintainers. **Needs work.** The new head rewrites `resolve` in `crates/victory-core/src/policy.rs` to walk components and canonicalize each existing prefix before applying `..`, and drops `normalize`. On POSIX semantics this does close the `<link>/../x` case from the last review. On Windows, the only platform VIctory builds for and the only one CI runs, it still fixes nothing, and the new Case 2 assertion describes the wrong target: 1. Win32 collapses `..` as text before it resolves anything. So `create_dir_all("<outside>\\missing\\..\\..\\link-sub\\..\\out")` creates `<tmp>\\out`, not `<repo>\\out`. The test's comment ("steps out of `<repo>/sub` into `<repo>/out`") does not hold there. The new code now rejects a path that Windows would write outside the repository. That is stricter, so it is harmless, but the test asserts behaviour Windows does not have. Case 1 was already refused on `main`, because `canonicalize` succeeds on the whole prefix. 2. The reply mentions a Windows `\\?\\` verbatim-path test case, but the diff has none. It contains only `rejects_symlink_into_repo_across_dotdot_components`, which builds ordinary paths with `join`. **What would change the verdict:** a test that fails on `main` in the Windows CI (for example the verbatim-path case you describe, if `..` in such a path really reaches the filesystem), or a maintainer decision that POSIX semantics matter for this crate. In either case, Case 2's comment should say which platform it applies to. **Reply to the author:** thanks for the rewrite. Point 2 is addressed for POSIX paths. Point 1, a failing case on Windows, is still open, because the verbatim-path test the reply mentions is not in the pushed commit (`a10368d`). CI: `check` passed (Windows). --- _Generated by [Claude Code](https://claude.ai/code)_
reeledMarek commented 2026-11-25 20:06:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:23Z.


Updated to address both triage points:

  • Rewrote policy::resolve to walk path components left-to-right, canonicalizing each existing prefix before applying ... This fixes <outside>/missing/../../<link>/../out (where <link> -> <repo>/sub) in addition to <outside>/missing/../../<link>/out.
  • Added regression tests covering both cases, plus a Windows \\?\ verbatim-path test case where Win32 does not collapse .. lexically before passing paths to the kernel (in addition to Linux/cross-platform CLI builds).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173175707 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2530#issuecomment-7173175707). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T20:05:23Z. --- Updated to address both triage points: - Rewrote `policy::resolve` to walk path components left-to-right, canonicalizing each existing prefix before applying `..`. This fixes `<outside>/missing/../../<link>/../out` (where `<link> -> <repo>/sub`) in addition to `<outside>/missing/../../<link>/out`. - Added regression tests covering both cases, plus a Windows `\\?\` verbatim-path test case where Win32 does not collapse `..` lexically before passing paths to the kernel (in addition to Linux/cross-platform CLI builds).
upstream-sync changed title from [PR #2530] Core: re-canonicalize policy::resolve paths after collapsing .. to close symlink bypass to [PR #2530] Core: resolve policy::resolve paths component by component to close symlink dotdot bypasses 2026-11-25 21:02:32 +00:00
upstream-sync closed this pull request 2026-11-26 06:02:29 +00:00
reeledMarek commented 2026-11-26 06:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:44:20Z.


Closing per triage: Win32 normalizes .. lexically before resolving symlinks (and \?\ verbatim paths do not interpret .. as parent traversal), while Case 1 is already rejected on main. Since VIctory targets x86-64 Windows only, this change only affects POSIX semantics and isn't worth the extra complexity. Thanks for the careful Windows analysis!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183760277 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2530#issuecomment-7183760277). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T05:44:20Z. --- Closing per triage: Win32 normalizes `..` lexically before resolving symlinks (and `\?\` verbatim paths do not interpret `..` as parent traversal), while Case 1 is already rejected on `main`. Since VIctory targets x86-64 Windows only, this change only affects POSIX semantics and isn't worth the extra complexity. Thanks for the careful Windows analysis!

Pull request closed

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
Marvisak/VIctory!2528
No description provided.