Repository navigation
feat(transfer): thread DirSandbox through receiver --delete path (SEC-1.q2) - #4732
Merged
Merged
Conversation
…-1.q2) Replace the three unanchored syscalls in delete_extraneous_files with their sandbox-anchored siblings so a TOCTOU symlink swap on a top-level extraneous entry cannot redirect the listing or the unlink to an attacker-chosen inode outside the destination tree. Adds fast_io::read_dir_via_sandbox_or_fallback (mirrors the existing *_via_sandbox_or_fallback shape: openat(O_DIRECTORY | O_NOFOLLOW) + fdopendir for single-component scans, std::fs::read_dir fallback otherwise). Closes audit rows #5, #6, #7 from the SEC-1 path-syscall audit. Mirrors the SEC-1.r temp_guard/temp_cleanup carrier-threading pattern (PR #4723): the Option<Arc<DirSandbox>> is cloned once into the map_blocking worker closure and forwarded to every helper call. Sandbox-off and multi-component paths take the documented identical- behaviour fallback. No transfer-crate unsafe is introduced; all unsafe stays behind the existing fast_io safe wrappers. Windows continues through std::fs::remove_file / remove_dir_all / read_dir (NTFS handle semantics already close the symlink-swap window per the SEC-1.l audit).
SkipWhile<Components, _> has no as_path() method on stable Rust 1.88; the previous skip_while-then-as_path call introduced in SEC-1.q (#4728) slipped through that PR's CI but breaks fmt+clippy on every subsequent master CI run. Switch to a manual Components::next() walk that consumes the leading Prefix/RootDir/CurDir components, then calls as_path() on the unwrapped Components iterator.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…-1.q2) (#4732) * feat(transfer): thread DirSandbox through receiver --delete path (SEC-1.q2) Replace the three unanchored syscalls in delete_extraneous_files with their sandbox-anchored siblings so a TOCTOU symlink swap on a top-level extraneous entry cannot redirect the listing or the unlink to an attacker-chosen inode outside the destination tree. Adds fast_io::read_dir_via_sandbox_or_fallback (mirrors the existing *_via_sandbox_or_fallback shape: openat(O_DIRECTORY | O_NOFOLLOW) + fdopendir for single-component scans, std::fs::read_dir fallback otherwise). Closes audit rows #5, #6, #7 from the SEC-1 path-syscall audit. Mirrors the SEC-1.r temp_guard/temp_cleanup carrier-threading pattern (PR #4723): the Option<Arc<DirSandbox>> is cloned once into the map_blocking worker closure and forwarded to every helper call. Sandbox-off and multi-component paths take the documented identical- behaviour fallback. No transfer-crate unsafe is introduced; all unsafe stays behind the existing fast_io safe wrappers. Windows continues through std::fs::remove_file / remove_dir_all / read_dir (NTFS handle semantics already close the symlink-swap window per the SEC-1.l audit). * fix(engine): use Components::next() walk for plan_directory_to_relative SkipWhile<Components, _> has no as_path() method on stable Rust 1.88; the previous skip_while-then-as_path call introduced in SEC-1.q (#4728) slipped through that PR's CI but breaks fmt+clippy on every subsequent master CI run. Switch to a manual Components::next() walk that consumes the leading Prefix/RootDir/CurDir components, then calls as_path() on the unwrapped Components iterator. * fix(transfer): cfg-gate rel_for_unlink to unix to silence Windows unused-var
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.
Summary
Closes the SEC-1.q2 receiver-side wiring gap left by PR #4728. The
DeleteEmitter::with_sandboxcarrier slot landed but the productionreceiver-deletion loop in
crates/transfer/src/receiver/directory/deletion.rsstill called
std::fs::read_dir,std::fs::remove_dir_all, andstd::fs::remove_filedirectly under--delete, leaving audit rows#5, #6, #7 (from
docs/audits/sec-1-path-syscall-audit-2026-05-22.md)open. Implements Option B from the design doc shipped in PR #4729
(
docs/design/sec-1-q2-receiver-deletion-sandbox-2026-05-22.md).GAP sites closed by this PR:
deletion.rs:115(audit row Clamp peer protocol advertisements to supported range #5):fs::read_dir(&dest_path)swappedfor the new
fast_io::read_dir_via_sandbox_or_fallbackhelper.deletion.rs:157(audit row Handle too-old peer protocol advertisements gracefully #6):fs::remove_dir_all(&path)swapped for
fast_io::recursive_unlinkat_via_sandbox_or_fallback(added in SEC-1.s PR feat(fast_io): recursive_unlinkat sandbox helper for SEC-1.q (SEC-1.s) #4726).
deletion.rs:159(audit row Add byte-based legacy greeting parser #7):fs::remove_file(&path)swappedfor
fast_io::unlink_via_sandbox_or_fallback(existing SEC-1.ghelper).
New
fast_iohelper:read_dir_via_sandbox_or_fallbackmirrors the existing*_via_sandbox_or_fallbacksignature shape. When the sandbox ispresent and the listing target is the root or a single-component
subdir, the helper opens through
openat(O_DIRECTORY | O_NOFOLLOW)+fdopendir, materialises the entries into an ownedVec(matchingthe
recursive_unlinkatinvariant so per-entry*atcalls do notrace the live
DIR*cursor), and reports per-entry classify bitsvia
DirEntryView::file_type(backfillingDT_UNKNOWNviafstatat_nofollowagainst the same parent dirfd). Multi-componentand sandbox-absent paths fall back to
std::fs::read_dirso thepre-SEC-1.q2 behaviour is preserved byte-for-byte.
Mirrors the SEC-1.r
temp_guard/temp_cleanupprecedent (PR #4723):Option<&Arc<DirSandbox>>is plumbed through the existing call shapewithout restructuring the surrounding parallel-iteration. The carrier
is cloned once into the
map_blockingworker closure and forwardedinto every helper call. No transfer-crate
unsafeis introduced; allunsafestays behind the existingfast_iosafe wrappers.Cross-platform: all new code is
#[cfg(unix)]. Windows continuesthrough
std::fs::remove_file/remove_dir_all/read_dirper theSEC-1.l audit conclusion on NTFS handle semantics.
Test plan
crates/fast_io/src/dir_sandbox/at_syscalls.rs:sandbox lists the root when relative is empty, sandbox lists a
single-component subdir with correct file-type classification,
sandbox falls back for multi-component descents, sandbox-absent
fallback, symlink-at-leaf refused with
ELOOP/ENOTDIR, sandboxand std listings agree byte-for-byte.
crates/transfer/tests/delete_sandbox_swap.rs: symlink swap on afile deletion, symlink swap on a directory deletion (recursive),
symlink swap on the directory listing target, sandbox-on root
listing classifies entries correctly, sandbox-off fallback matches
std::fsbehaviour byte-for-byte.crates/transfer/src/receiver/tests/file_list/filter_chain.rscases updated to pass the new
sandbox: Noneargument and continueto pass.
fmt+clippy on the worktree-blocking platforms.