Repository navigation
fix(client): land bundle entries beneath the output root and apply the region allowlist - #2538
Merged
Merged
Conversation
…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]>
There was a problem hiding this comment.
🔵 Needs a closer look
An unresolved source-identity mismatch and cross-platform filesystem race guarantees require final human security review.
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
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 6 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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, andwritable_destreserves the engine-owned paths since #2466. This PR covers the rest.Destination containment (item 1)
safe_joinis lexical, soout/link -> /elsewhereplus an entrylink/filewrote/elsewhere/file:create_dir_all, the temp file and the rename all followed the link.bundle::landing::Landing: the output directory held open as acap_std::fs::Dironce per pass.materialize,move_into_place,link_or_copy_atomicandfirst_writemove from the engine onto it, and every directory, temp file (acreate_newopen 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 (openat2RESOLVE_BENEATHon 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_slotsdecides 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.adr/appendix-bundles.md§ Output and the CHANGELOG. A symlink at the entry's own name is replaced, not followed..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.-ois still the current directory.Region allowlist (item 4)
entry_candidatessampled region-first and never readPullSite::region_allowlist.discover_candidatesnow returns aRegistry { nodes, outage_fallback }, and each entry's sample goes throughtargets::select_with_widening(nowpub(crate)): the allowlist narrows it, it widens back belowmin_fresh_candidates, and aBootstrap::Cachedoutage 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!inpull_manifestisuntil_interrupted, with a test that the first Ctrl-C drops the pending fetch (itsSettleOnDropis what queues the watermark writes) and ends the runInterrupted.Dependencies
cap-std 4indecdn-client(rustixwas already in the tree; no cap-tempfile, so the copy path needs no procfs).deny.tomlnow allowsApache-2.0 WITH LLVM-exception:winx, cap-std's Windows backend, carries only that form.Behaviour changes to know
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_apisnapshot test: passes with no diff.🤖 Generated with Claude Code