GHSA-PMM9-4H7Q-24C8
gix_worktree_state::checkout() follows an existing terminal symlink on Windows during non-exclusive (incremental) materialization
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche 0.33.0 | gix-worktree-state · -10 d desde divulgación | |
| Remediación | Parche 0.55.0 | gix-worktree · -10 d desde divulgación | |
| Remediación | Parche 0.86.0 | gix · -10 d desde divulgación | |
| Divulgación | Publicada | GHSA-PMM9-4H7Q-24C8 divulgada · CVSS 5.3 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
`gix-worktree-state::checkout()` follows an existing terminal symlink on Windows during non-exclusive (incremental) materialization
Type: Security — path traversal / arbitrary file write outside the worktree (CWE-59: Improper
Link Resolution Before File Access, "Link Following")
Component: `gix_worktree_state::checkout()` — the real, public, unmodified low-level checkout
entry point (crate-root re-export in `gix-worktree-state`), reachable via the `gix` umbrella crate's
own documented `Repository::checkout_options()` builder. Contributing gaps live in
`gix-worktree-state`, `gix-worktree`, and `gix-features`.
Affects: any consumer of `gix_worktree_state::checkout()` that calls it with
`destination_is_initially_empty: false` (the default value returned by
`Repository::checkout_options()` itself — see Reachability below) on Windows, wherever
`core.symlinks` resolves to `true` (the default read by `fs_capabilities()` when unset, and what
`gix::init()`'s own filesystem probe records whenever the OS/user can create symlinks — Developer
Mode, admin, `SeCreateSymbolicLinkPrivilege`).
Confirmed present at: git `main` commit `5e75997fd429365518b42f4aef9c75f50e348593`
(2026-07-22T13:23:12Z), effectively current HEAD (`2315ede7`, ~1h later — no relevant file changed
in between; verified via commit history on the three affected files). Also present in the current
crates.io releases: `gix-worktree-state` 0.32.0, `gix-worktree` 0.54.0, `gix-features` 0.48.1,
`gix-fs` 0.21.2, `gix` 0.85.0 (no relevant change to the affected functions since well before any of
these releases).
Credit: Sergey Gordeychik ([scadastrangelove@gmail.com](mailto:scadastrangelove@gmail.com)),
found using the rust-in-peace https://github.com/scadastrangelove/rust-in-peace pipeline
(AI-assisted Rust vulnerability research).
Summary
`gix_worktree_state::checkout()` — the real, public function any `gix`-based tool would call to
materialize a tree into a worktree — follows an existing symlink on Windows when a later checkout
call replaces the same path with a regular file, writing the new content through the link and
outside the worktree.
Concretely: an index/tree contains a symlink entry (mode `120000`) at some path `P`, pointing
anywhere outside the worktree the checking-out user has write access to. Checking it out with
`destination_is_initially_empty: true` (a fresh/empty destination) creates a real filesystem reparse
point at `<worktree>\P`. A second checkout call, with `destination_is_initially_empty: false` (an
existing/non-empty destination — "incremental" checkout) against an index/tree that instead has a
regular-file entry (mode `100644`) at the same path `P`, **follows the existing reparse point on
Windows** and writes the new blob's content to whatever `P` points at.
Reachability
`gix_worktree_state::checkout()` is `gix-worktree-state`'s crate-root re-export
(`pub use checkout::function::checkout;`) — the same public function `gix`'s own
`clone::checkout.rs` calls to materialize a fresh clone. `Repository::checkout_options()`
(`gix/src/repository/checkout.rs`) is a public method, documented as returning "options that can
be used to drive a low-level checkout operation" — i.e. `gix` itself directs a downstream consumer
here to build a checkout beyond clone. Reading its implementation
(`gix/src/config/cache/access.rs::checkout_options()`) shows `destination_is_initially_empty: false`
is the literal default value it returns — a caller gets the incremental/non-exclusive setting
unless they explicitly override it to `true` (which is exactly what `clone::checkout.rs` does, for
its specific fresh-checkout case). The `fs.symlink` field of the same `Options` comes from
`fs_capabilities()`, which reads `core.symlinks` from config, **defaulting to `true` if the key is
absent** — and `gix::init()`'s own filesystem probe stores exactly that value at real repo-creation
time, matching git-for-windows' own `core.symlinks` autodetection.
Every production call site of `gix_worktree_state::checkout()` in the gitoxide workspace was
enumerated (GitHub code search):
- `gix/src/clone/checkout.rs:122` — the only call site inside the `gix` crate itself — explicitly
sets `opts.destination_is_initially_empty = true;` (fresh clone only).
- `gitoxide-core/src/index/checkout.rs` (`checkout_exclusive`, backing the `gix`/`ein` CLI's own
checkout plumbing command) — also hardcodes `true`, and explicitly `bail!`s ("Refusing to checkout
index into existing directory") if the destination already exists.
No caller currently in the gitoxide workspace passes `destination_is_initially_empty: false` — there
is not yet a shipped `git pull` or incremental/onto-existing-worktree checkout feature built on this
function. The vulnerable configuration is not an obscure combination a downstream developer would
need to construct deliberately, though: it is the value `checkout_options()` returns by default.
A downstream application implementing pull/incremental-checkout on the sanctioned builder would need
to actively override the flag to be safe for a fresh-checkout case (as `clone::checkout.rs` does),
not to hit this.
Impact statement (the claim this report supports): *A downstream application that invokes
`gix_worktree_state::checkout()` with `destination_is_initially_empty: false` on an index whose
regular-file entry collides with a path that already holds a symlink can overwrite the symlink's
target — outside the checkout destination — on Windows, in a release build, using the library's own
default option value.* This is confirmed as a library-API primitive via the real public API and the
real config-driven option builder; it is not demonstrated as reachable through any currently shipped
`git pull`/`git checkout`/CLI feature (see "What this report does not claim").
Root cause — three components, all required
1. The terminal path component is never collision-checked for non-directory entries.
`gix-worktree/src/stack/delegate.rs`, `create_leading_directory()`:
fn create_leading_directory(
is_last_component: bool,
stack: &gix_fs::Stack,
mode: Option<gix_index::entry::Mode>,
mkdir_calls: &mut usize,
unlink_on_collision: bool,
) -> std::io::Result<()> {
if is_last_component && !crate::stack::mode_is_dir(mode).unwrap_or(false) {
return Ok(()); // <-- no symlink/collision check at all for the LAST component
}
...Every existing-path/symlink-collision check in this function only runs for intermediate
directory components of the path. For the terminal component of a file or symlink entry — exactly
the case here — the function returns immediately, deferring entirely to whatever happens when the
file is later opened.
**2. The only remaining safety net is a debug-only assertion, and it cannot fire for this scenario
even when compiled in.** `gix-worktree-state/src/checkout/entry.rs`:
#[cfg(not(debug_assertions))]
fn debug_assert_dest_is_no_symlink(_path: &Path) {}
/// This is a debug assertion as we expect the machinery calling this to prevent this possibility in the first place
#[cfg(debug_assertions)]
fn debug_assert_dest_is_no_symlink(path: &Path) {
if let Ok(meta) = path.metadata() {
debug_assert!(
!meta.file_type().is_symlink(),
"BUG: should not ever allow to overwrite/write-into the target of a symbolic link: {}",
path.display()
);
}
}
fn open_options(path: &Path, destination_is_initially_empty: bool, overwrite_existing: bool) -> std::fs::OpenOptions {
if overwrite_existing || !destination_is_initially_empty {
debug_assert_dest_is_no_symlink(path); // <-- no-op in release builds
}
...The condition that triggers the check — `overwrite_existing || !destination_is_initially_empty` —
is exactly the incremental-checkout case. The comment documents the intent ("we expect the
machinery calling this to prevent this possibility in the first place") — but (1) shows that
machinery does not prevent it, and this function's own enforcement is a `debug_assert!`, a no-op in
any release build.
Even in a debug build, this check cannot fire for the scenario in this report: it calls
`path.metadata()`, which follows symlinks (unlike `path.symlink_metadata()`, which does not).
For a symlink pointing at an *existing* target — exactly this attack — `metadata()` resolves through
the link and returns the target's (non-symlink) file type, so `meta.file_type().is_symlink()` is
`false` and the assertion is vacuously satisfied. Verified empirically, not just from source: the
`e2e2` PoC (below) independently re-runs the identical `path.metadata().is_symlink()` check on both
a release and a debug-profile build on Windows and prints the result — `false` on both.
3. The remaining OS-level protection is Unix-only. `gix-features/src/fs.rs`:
/// Prepare open options which won't follow symlinks when the file is opened.
///
/// Note: only effective on unix currently.
pub fn open_options_no_follow() -> std::fs::OpenOptions {
#[cfg_attr(not(unix), allow(unused_mut))]
let mut options = std::fs::OpenOptions::new();
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt;
options.custom_flags(libc::O_NOFOLLOW);
}
options
}On Unix, `O_NOFOLLOW` is the layer that actually holds — and it does hold, empirically (see
Reproduction below): even though (1) and (2) are equally absent/ineffective on Linux, the `open()`
syscall itself refuses to follow the symlink. On Windows there is no equivalent flag applied at
all. All three gaps have to line up for the escape to occur, and on Windows, they do.
Reproduction
Two PoCs, run on GitHub Actions `windows-latest` (free tier) with a Linux control for isolation.
Attached in `poc/`:
`poc/poc/` (mechanism) — creates a real symlink on disk directly, then opens it with the exact
`gix_features::fs::open_options_no_follow()` call plus the flags a checkout write uses, and checks
whether the write followed the link.
`poc/e2e2/` (end-to-end) —
- A real repository via `gix::init()` (which itself probes filesystem symlink support and records
the result as `core.symlinks` in config).
- Two real commit objects (commit A: tree with the symlink entry, no parent; commit B: tree with the
colliding regular-file entry, parent = commit A), with the default branch ref updated between them
via `Repository::reference()` — gitoxide's own public ref-edit API.
- `checkout::Options` built via `Repository::checkout_options()` — the real, public, config-driven
builder — with only the one caller-intent flag (`destination_is_initially_empty`) explicitly set
per call; everything else, including `fs.symlink`, comes untouched from the real builder.
- The index is persisted to disk after commit A's checkout (`gix::index::File::write()`), exactly as
`gix::clone::PrepareCheckout::main_worktree()` does, before commit B's incremental checkout runs.
- Independently re-checks the `path.metadata().is_symlink()` call the debug-only safety net uses, on
both release and debug profiles, and prints the result.
Observed (CI run `29936610607` https://github.com/scadastrangelove/gitoxide-win-symlink-poc/actions/runs/29936610607 — see `CI-RESULTS.md` for full logs):
| PoC | environment | after commit A | after commit B | result |
|---|---|---|---|---|
| `e2e2` | Windows, release | `evil.is_symlink = true` | canary outside worktree overwritten | `* END-TO-END ESCAPE CONFIRMED *`; `debug_assert`'s own check printed `false` |
| `e2e2` | Windows, debug | `evil.is_symlink = true` | canary outside worktree overwritten | escape reproduced in a debug build too; `debug_assert`'s own check printed `false` |
| `e2e2` | Linux control | `evil.is_symlink = true` | canary untouched | contained — `O_NOFOLLOW` holds |
| `poc` (mechanism) | Windows | — | `canary(outside)="PWNED" evil.is_symlink=true` | `* ESCAPE *` |
| `poc` (mechanism) | Windows, `create_new` control | — | — | contained (`create_new` never opens an existing path) |
| `poc` (mechanism) | Linux | — | — | contained |
The Linux/Windows pairing on identical code isolates the escape to the Windows platform
specifically — the symlink is created identically on both; only the write that follows it differs.
Every crate ships a committed `Cargo.lock`, and the CI workflow builds with `cargo run --locked`, so
the exact dependency graph analyzed is reproducible.
Impact
*A downstream application that invokes `gix_worktree_state::checkout()` with
`destination_is_initially_empty: false` on an index whose regular-file entry collides with an
existing symlink can overwrite the symlink's target outside the destination, within the rights of
the process running it.* No privilege escalation, no sandbox escape — the write happens as the
user/process already running the checkout. Confirmed only for the incremental-checkout case
(`destination_is_initially_empty: false` against a pre-existing symlink); `overwrite_existing: true`
and NTFS short-name-collision variants are plausible but not evaluated (see below).
Same class of bug as CVE-2021-21300 / CVE-2024-32002 (real Git's own case-collision /
symlink-redirected-checkout-write CVEs) and RUSTSEC-2024-0348 / GHSA-f89h-2fjh-2r9q (gitoxide's own
prior, now-fixed, symlink cache-revalidation CVE) — same general shape (checkout write redirected
through an attacker-placed symlink), different specific gap, still open on Windows in the code path
analyzed here.
Suggested fix directions (not prescriptive)
- Extend `create_leading_directory`'s collision check to cover the terminal component for
- Fix `debug_assert_dest_is_no_symlink` to use `symlink_metadata()` instead of `metadata()` (closes
- Implement a Windows equivalent of `O_NOFOLLOW` in `open_options_no_follow()` (closes gap 3) — e.g.
- Any one of these closes the reproduced escape; which layer should own this invariant is for the
What this report does not claim
- Not reachable through any shipped `git pull`/`git checkout`/CLI feature today — verified by
- Not evaluated: `overwrite_existing: true` checkouts, NTFS short-name collisions (`git~1`), or
- Not evaluated on macOS (case-insensitive by default, same `#[cfg(unix)]` `O_NOFOLLOW` path as
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
crates.iogix-worktree-state |
Corregida | 0.33.0 | -10 d | 0.37.0 no afectada |
crates.iogix-worktree |
Corregida | 0.55.0 | -10 d | 0.59.0 no afectada |
crates.iogix |
Corregida | 0.86.0 | -10 d | 0.90.0 no afectada |
0.33.00.55.00.86.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/GitoxideLabs/gitoxide/security/advisories/GHSA-pmm9-4h7q-24c8Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
