Skip to content

fix(client): land bundle entries beneath the output root and apply the region allowlist - #2538

Merged
thiras merged 3 commits into
mainfrom
fix/2439-bundle-containment
Oct 19, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/2439-bundle-containment

Conversation

@thiras

@thiras thiras commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2439.

Two of the four items in #2439 were already fixed on main: the Ctrl-C watch covers the paid manifest fetch since #2452, and writable_dest reserves the engine-owned paths since #2466. This PR covers the rest.

Destination containment (item 1)

safe_join is lexical, so out/link -> /elsewhere plus an entry link/file wrote /elsewhere/file: create_dir_all, the temp file and the rename all followed the link.

  • New bundle::landing::Landing: the output directory held open as a cap_std::fs::Dir once per pass. materialize, move_into_place, link_or_copy_atomic and first_write move from the engine onto it, and every directory, temp file (a create_new open plus a rename, both through the handle), hard link and rename resolves beneath the root. A symlink that leads out fails that entry; a directory swapped for a symlink mid-run cannot redirect the write either (openat2 RESOLVE_BENEATH on Linux, a component walk elsewhere, Windows included). A test swaps a directory for an escaping symlink after the pre-fetch check and asserts every writer still refuses.
  • plan_slots decides the skip first, then probes the parent chain of a path it will write (Landing::check), so an entry whose link already exists fails before its blob is paid for, and an entry already present behind such a link is still skipped. The check fails closed: a parent that is not a directory, or a chain that cannot be read, fails before the fetch too. The per-entry failure names the path: link/file resolves outside the output directory /out: a symlink in its path leads out of it.
  • A relative symlink inside the root is followed. A symlink with an absolute target is treated as an escape, even one that points back inside the root — inherent to beneath-root resolution, stated in adr/appendix-bundles.md § Output and the CHANGELOG. A symlink at the entry's own name is replaced, not followed.
  • The staging directory is read by its own path, so a symlinked .decdn-partial/ the handle refuses still lands entries (and donors) through the copy fallback. A refused move or link is logged at debug; the rename error stays in the copy's error context.
  • Engine-owned writes (skip cache, manifest cache, staging) and content-hashed reads stay on std paths; the manifest cannot name them. An empty -o is still the current directory.

Region allowlist (item 4)

entry_candidates sampled region-first and never read PullSite::region_allowlist. discover_candidates now returns a Registry { nodes, outage_fallback }, and each entry's sample goes through targets::select_with_widening (now pub(crate)): the allowlist narrows it, it widens back below min_fresh_candidates, and a Bootstrap::Cached outage list is not narrowed, as on the fetch path. NodeSelection's fields are private, so the public-API snapshot is unchanged.

Ctrl-C regression test (item 2)

The select! in pull_manifest is until_interrupted, with a test that the first Ctrl-C drops the pending fetch (its SettleOnDrop is what queues the watermark writes) and ends the run Interrupted.

Dependencies

cap-std 4 in decdn-client (rustix was already in the tree; no cap-tempfile, so the copy path needs no procfs). deny.toml now allows Apache-2.0 WITH LLVM-exception: winx, cap-std's Windows backend, carries only that form.

Behaviour changes to know

  • Absolute-target symlinks under the output directory are escapes for entries that are written (skipped entries are unaffected).
  • A copied entry lands with the usual file mode (0666 less umask) rather than tempfile's 0600; a moved or linked entry keeps the mode it had.

Verification

  • cargo fmt --check, cargo clippy --workspace --all-targets --all-features -D warnings, CARGO_BUILD_WARNINGS=deny cargo doc, cargo deny check, pre-commit run --all-files: clean.
  • cargo nextest run --workspace: 5243 passed.
  • public_api snapshot test: passes with no diff.
  • CI on the first push was green on every job, including both Windows cross-clippy targets and the anvil e2e suites.

🤖 Generated with Claude Code

…e region allowlist

A manifest path is checked for `..` and absolute components, but the
write followed a symlink in the entry's parent directories: with
`out/link -> /elsewhere` and an entry `link/file`, `create_dir_all`, the
temp file and the rename all landed `/elsewhere/file`.

The pull now holds the output directory open as a `cap_std::fs::Dir`
(`bundle::landing::Landing`) and lands every entry through it: the
directory, the temp file, the hard link and the rename all resolve
beneath the root, so a symlink that leads out fails the entry instead of
redirecting the write, and a directory swapped for a symlink mid-run
cannot redirect it either. `plan_slots` probes the parent chain before
the fetch, so an entry whose link already exists fails before its blob
is paid for. A relative symlink inside the root is followed; one with an
absolute target is an escape. The staging directory is read by its own
path, so a symlinked `.decdn-partial/` still lands entries by a copy.

Each entry's candidate sample now goes through
`targets::select_with_widening`, so `[client] region_allowlist` narrows
it with the same widening as a single fetch. `discover_candidates`
returns a `Registry` that records whether the list is a live read, and
a list the peer store supplied during a registry outage is not narrowed,
as on the fetch path.

`bundle pull`'s Ctrl-C watch already covers the paid manifest fetch; the
`select!` is now `until_interrupted`, with a test that the first Ctrl-C
drops the fetch and ends the run `Interrupted`.

`deny.toml` allows `Apache-2.0 WITH LLVM-exception` for `winx`, the
Windows backend of `cap-std`.

Closes #2439

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 10:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

An unresolved source-identity mismatch and cross-platform filesystem race guarantees require final human security review.

1 open issue
What changed in this PR

Hardens bundle output handling and aligns bundle discovery with single-fetch region filtering, addressing the remaining items in #2439.

Changes:

  • Routes entry writes through an open output-directory handle.
  • Applies region allowlists with widening and cached-outage fallback.
  • Adds containment, discovery, and manifest-fetch interruption tests.
File Description
deny.toml Allows the Windows backend license.
crates/​common/​src/​config/​types.rs Documents bundle region filtering.
crates/​client/​src/​targets.rs Shares the candidate-selection helper.
crates/​client/​src/​session.rs Updates allowlist documentation.
crates/​client/​src/​bundle/​landing/​tests.rs Tests landing and symlink handling.
crates/​client/​src/​bundle/​landing.rs Adds handle-relative entry writes.
crates/​client/​src/​bundle/​engine/​tests.rs Tests filtering and containment integration.
crates/​client/​src/​bundle/​engine.rs Integrates landing and filtered discovery.
crates/​client/​src/​bundle.rs Registers landing and registry state.
crates/​client/​Cargo.toml Adds capability filesystem dependencies.
crates/​cli/​src/​commands/​bundle_pull/​tests.rs Tests manifest-fetch cancellation.
crates/​cli/​src/​commands/​bundle_pull.rs Extracts interruption handling.
CHANGELOG.md Summarizes user-visible fixes.
Cargo.toml Declares shared filesystem dependencies.
Cargo.lock Locks new dependencies.
adr/​appendix-bundles.md Specifies containment and filtering behavior.
adr/​012-client.md Documents bundle allowlist application.

Review effort: Balanced

Comment thread crates/client/src/bundle/landing.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 4f6beff fix/2439-bundle-cont... d2265a5 +/-
76% 76% 0%
View coverage of the 6 most impacted files.
File main 4f6beff fix/2439-bundle-cont... d2265a5 +/-
crates/client/s...undle/engine.rs 65% 65% 0%
crates/cli/src/.../bundle_pull.rs 56% 56% 0%
crates/cache/src/engine.rs 91% 91% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/protocol/src/framing.rs 92% 93% +1%
crates/client/s...ndle/landing.rs 0% 91% +91%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 19, 2026 11:25 UTC

thiras and others added 2 commits October 19, 2026 14:09
…ail the check closed

Review follow-ups for #2439.

- `plan_slots` tested the parent chain before the skip set, so an entry
  already present behind a link the handle refuses was reported failed on
  every rerun although nothing would be written. The skip is decided
  first; the check applies to a path the pull writes.
- `Landing::check` passed every non-escape fault to the landing, after
  the fetch was paid for. It now fails on a parent that is not a
  directory and on any read fault other than a missing parent.
- The copy fallback stages its temp file through the handle with a
  `create_new` open and a rename, so it no longer needs procfs on Linux;
  `cap-tempfile` is dropped. A refused move or link is logged at debug
  and the rename error stays in the copy's error context; a staged name
  that cannot be removed after a failed landing is logged at warn.
- `Registry::live` is `outage_fallback`, which names what it decides.
- An empty output path is the current directory, as before.
- Tests: a directory swapped for an escaping symlink after the check is
  still refused by every writer; a donor under a symlinked staging
  directory lands through the copy fallback; a symlink at the entry's
  own name is replaced, not followed; a file parent and an unopenable
  output path fail; a timed-out registry read is the outage fallback.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`fresh_name` hands back the file it opened, so `copy_into` needs no
side slot and no unreachable "no temp file was opened" branch; its copy,
sync and rename are one chain with the staged-name cleanup as its error
inspection, as the link path already does. The `stat` of a staging blob
is one helper, and the escape probe after a failed `create_dir_all`
feeds `beneath` instead of returning early.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@thiras
thiras merged commit 0f7de48 into main Oct 19, 2026
33 checks passed
@thiras
thiras deleted the fix/2439-bundle-containment branch October 19, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bundle: harden the pull's destination paths, Ctrl-C window and region filter

2 participants