Skip to content

feat(transfer): thread DirSandbox through receiver --delete path (SEC-1.q2) - #4732

Merged
oferchen merged 3 commits into
masterfrom
feat/sec-1-q2-receiver-deletion-sandbox
May 22, 2026
Merged

oferchen merged 3 commits into
masterfrom
feat/sec-1-q2-receiver-deletion-sandbox

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Closes the SEC-1.q2 receiver-side wiring gap left by PR #4728. The
DeleteEmitter::with_sandbox carrier slot landed but the production
receiver-deletion loop in crates/transfer/src/receiver/directory/deletion.rs
still called std::fs::read_dir, std::fs::remove_dir_all, and
std::fs::remove_file directly 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:

New fast_io helper:

  • read_dir_via_sandbox_or_fallback mirrors the existing
    *_via_sandbox_or_fallback signature shape. When the sandbox is
    present 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 owned Vec (matching
    the recursive_unlinkat invariant so per-entry *at calls do not
    race the live DIR* cursor), and reports per-entry classify bits
    via DirEntryView::file_type (backfilling DT_UNKNOWN via
    fstatat_nofollow against the same parent dirfd). Multi-component
    and sandbox-absent paths fall back to std::fs::read_dir so the
    pre-SEC-1.q2 behaviour is preserved byte-for-byte.

Mirrors the SEC-1.r temp_guard / temp_cleanup precedent (PR #4723):
Option<&Arc<DirSandbox>> is plumbed through the existing call shape
without restructuring the surrounding parallel-iteration. The carrier
is cloned once into the map_blocking worker closure and forwarded
into every helper call. No transfer-crate unsafe is introduced; all
unsafe stays behind the existing fast_io safe wrappers.

Cross-platform: all new code is #[cfg(unix)]. Windows continues
through std::fs::remove_file / remove_dir_all / read_dir per the
SEC-1.l audit conclusion on NTFS handle semantics.

Test plan

  • Unit tests in 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, sandbox
    and std listings agree byte-for-byte.
  • New integration regressions in
    crates/transfer/tests/delete_sandbox_swap.rs: symlink swap on a
    file 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::fs behaviour byte-for-byte.
  • Existing crates/transfer/src/receiver/tests/file_list/filter_chain.rs
    cases updated to pass the new sandbox: None argument and continue
    to pass.
  • CI: full nextest matrix (Linux musl, macOS, Windows) plus
    fmt+clippy on the worktree-blocking platforms.

…-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).
@github-actions github-actions Bot added the enhancement New feature or request label May 22, 2026
oferchen added 2 commits May 22, 2026 16:32
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
oferchen merged commit b9ae886 into master May 22, 2026
56 checks passed
@oferchen
oferchen deleted the feat/sec-1-q2-receiver-deletion-sandbox branch May 22, 2026 14:20
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant