Skip to content

fix(root): confine removal in require mode - #744

Merged
steipete merged 7 commits into
mainfrom
codex/require-harden-remove-20260927
Sep 28, 2026
Merged

steipete merged 7 commits into
mainfrom
codex/require-harden-remove-20260927

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Required-mode Root removal previously checked parent names and then dispatched pathname unlink/rmdir, allowing a concurrent parent swap to redirect deletion before the post-check rejected it. Removal now retains the admitted parent, matches its identity to the original admission, and uses identity-checked unlinkat on POSIX or exact-handle FileDispositionInfoEx on Windows. Recursive POSIX removal enumerates through retained directory descriptors and preserves ordering, budgets, cancellation, authority checks, force semantics, and error context.

These hardened paths apply only to require. Default auto keeps its previous best-effort implementation and does not confine removal under hostile concurrency. Required recursive directories fail closed with helper-unavailable on Windows and Linux without openat2/RESOLVE_NO_XDEV; auto keeps its existing behavior. POSIX checks are not an expected-inode conditional unlink, and guarded platform admission retains its best-effort label. The operation/platform matrix and compatibility notes are in #752.

The final post-authority leaf observation remains intact, including explicit symlink-policy rejection. The routing probe preserves mode precedence and live environment changes without scanning irrelevant legacy interpreter-path diagnostics on the auto path. No CHANGELOG changes are included.

Validation: current-head CI is green (38 passing checks, seven skips), including full checks and native lanes; focused tests, git diff --check, and independent Codex TOCTOU review through P2 passed. The combined final runtime completed 60 x 20-second strict campaigns per platform/configuration with zero outside/denied effects and complete supported-operation coverage: Linux openat2 1,012,000 calls; forced fallback 966,990; macOS 711,310; Windows 133,858. Recursive directories were explicitly tested fail-closed where unsupported. Append creation uses a unique basename per attempt. The final timing sweep uses recorded 0-8 ms hostile/restored intervals; earlier faster incomplete campaigns are retained and are not called passing.

Proof: Linux, macOS/Windows. Platform best-effort labels and namespace limitations remain as documented.

Paired Linux method benchmark, same native binary with A/A controls and interleaved runs: required remove 169.90 -> 290.24 us/call; recursive filesystem-order removal 18,856.70 -> 8,013.04 us/call. Auto remove 168.43 -> 169.56 us/call (+0.7%, within observed variation).

Performance evidence: paired method run, warmed auto control. The proof-only follow-ups change the harness/workflow; production src/native bytes match the measured runtime.

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 28, 2026, 9:52 AM ET / 13:52 UTC (Revision 9).

ClawSweeper review

What this changes

Root removal in required-native mode now deletes through retained parent handles, adds descriptor-based POSIX recursive traversal, and tests the new removal path.

Merge readiness

⛔ Blocked before merge - 8 items remain

Current main and v0.21.1 still use pathname removal, so this security repair remains necessary. The branch has credible cross-platform runtime proof, but its required-mode upgrade contract needs maintainer approval and two prior review findings remain unresolved.

Priority: P0
Reviewed head: e99e98cec1b6926e8047be891473042019945359
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong cross-platform runtime evidence supports a focused security repair, while upgrade approval and two concrete corrections still block merge.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): Linked Linux, macOS, and Windows jobs built the public package and native binding and exercised required-mode Root mutations under adversarial parent swaps, reporting zero outside or denied effects and fail-closed unsupported recursion. The combined proof branch uses the same TypeScript removal owner and POSIX native removal blobs as this PR head; no stored-data contract changes are present.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): Linked Linux, macOS, and Windows jobs built the public package and native binding and exercised required-mode Root mutations under adversarial parent swaps, reporting zero outside or denied effects and fail-closed unsupported recursion. The combined proof branch uses the same TypeScript removal owner and POSIX native removal blobs as this PR head; no stored-data contract changes are present.
Evidence reviewed 11 items Current main still needs the fix: The main-branch Root implementation calls the guarded pathname removal path; that path ultimately calls pathname unlink or rmdir.
Latest release also uses pathname removal: The v0.21.1 Root implementation has the same fallback dispatch and no native removal route.
Introduced required-mode route: The PR selects native removal only in require mode; the default auto mode retains the existing removal path.
Findings 3 actionable findings [P1] Resolve the recursive removal upgrade contract
[P2] Attach context to initial native inspection errors
[P3] Record the removal contract under Unreleased
Security Needs attention Final POSIX leaf replacement remains possible: The final statat and unlinkat are separate operations. A replacement within the retained parent can be removed after the identity check, so maintainers should explicitly accept and document this bounded guarantee.

How this fits together

Root accepts paths and mutation options from an application, checks them against its filesystem root, then removes files or directory trees. The selected native mode determines whether removal uses retained filesystem handles or guarded pathname operations.

flowchart LR
A[Remove request] --> B[Native mode]
B --> C{Require mode?}
C -->|No| D[Guarded pathname removal]
C -->|Yes| E[Admitted root and parent]
E --> F[Policy and identity checks]
F --> G[Native deletion]
D --> H[Result or typed error]
G --> H
Loading

Decision needed

Question Recommendation
Should required-mode Root removal adopt fail-closed recursive platform limits and the bounded POSIX leaf guarantee as its public contract? Approve the bounded contract: Accept the platform failures and POSIX leaf limit, then publish the companion documentation and upgrade guidance before merge.

Why: These limits change existing required-mode behavior and define what security boundary consumers may rely on; code and finite race campaigns cannot approve that contract.

Before merge

  • Resolve the recursive removal upgrade contract (P1) - Required-mode recursive removal previously used guarded traversal, but this route returns helper-unavailable for Windows directories and unsupported Linux traversal. Existing callers can stop working after upgrade; obtain explicit contract approval and publish the migration behavior before merge.
  • Attach context to initial native inspection errors (P2) - If the first native stat fails during recursive removal, this catch rethrows it without the operation, phase, and relativePath details supplied by later failures. Normalize it as an inspect failure for the requested target.
  • Record the removal contract under Unreleased (P3) - This new required-mode dispatch changes a public security and compatibility contract, but Unreleased is empty. Add a concise user-facing note covering the stronger boundary and platform failure modes.
  • Resolve security concern: Final POSIX leaf replacement remains possible - The final statat and unlinkat are separate operations. A replacement within the retained parent can be removed after the identity check, so maintainers should explicitly accept and document this bounded guarantee.
  • Resolve merge risk (P1) - Existing require-mode callers can newly receive helper-unavailable for recursive directories on Windows and Linux without the required native traversal support; the upgrade contract needs explicit approval and release guidance.
  • Resolve merge risk (P1) - POSIX retains the parent but cannot make its final leaf identity check and unlink atomic, so a last-moment replacement within that parent may be deleted; the public security guarantee needs explicit acceptance.
  • Complete next step (P2) - Resolve the required-mode contract and POSIX leaf guarantee with the owner, restore initial-inspection error details, and add the Unreleased entry before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Resolve the recursive removal upgrade contract — src/root-remove-native.ts:79-87
  • [P2] Attach context to initial native inspection errors — src/root-remove-native.ts:75-77
  • [P3] Record the removal contract under Unreleased — src/root-impl.ts:997
  • [medium] Final POSIX leaf replacement remains possible — native/src/root_remove.rs:33
Agent review details

Security

Needs attention: Retained parents prevent the reported redirect, but the POSIX leaf-check/unlink window still needs an approved, precise public guarantee.

Review metrics

Metric Value Why it matters
Code growth production +521 net lines, tests +391 net lines, benchmarks +11 lines The substantial native removal implementation has focused regression coverage and a stated security justification.

Merge-risk options

Maintainer options:

  1. Approve and publish strict semantics (recommended)
    Approve the bounded security and platform contract, land the coordinated documentation, and state the upgrade impact under Unreleased.
  2. Keep the existing required-mode behavior
    Introduce a separate explicit strict removal choice with tests for both the existing and stricter paths.

Technical review

Best possible solution:

Land the retained-parent deletion with an approved platform contract, precise POSIX leaf-limit documentation, and an Unreleased note for required-mode users.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main admits the parent and later dispatches pathname unlink or rmdir, exposing the reported swap interval. I did not execute a local current-main reproduction.

Is this the best way to solve the issue?

No, not yet merge-ready. Retained-parent native deletion addresses the reported redirect, but required-mode compatibility, initial-inspection diagnostics, and the release note still need resolution.

Full review comments:

  • [P1] Resolve the recursive removal upgrade contract — src/root-remove-native.ts:79-87
    Required-mode recursive removal previously used guarded traversal, but this route returns helper-unavailable for Windows directories and unsupported Linux traversal. Existing callers can stop working after upgrade; obtain explicit contract approval and publish the migration behavior before merge.
    Confidence: 0.96
  • [P2] Attach context to initial native inspection errors — src/root-remove-native.ts:75-77
    If the first native stat fails during recursive removal, this catch rethrows it without the operation, phase, and relativePath details supplied by later failures. Normalize it as an inspect failure for the requested target.
    Confidence: 0.97
  • [P3] Record the removal contract under Unreleased — src/root-impl.ts:997
    This new required-mode dispatch changes a public security and compatibility contract, but Unreleased is empty. Add a concise user-facing note covering the stronger boundary and platform failure modes.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cf71fe80db39.

Labels

Label changes:

No label changes.

Label justifications:

  • P0: The PR addresses a current filesystem-boundary escape where a parent swap can redirect deletion before a post-check rejects it.
  • merge-risk: 🚨 compatibility: Required-mode recursive deletion can newly fail on Windows and unsupported Linux traversal, interrupting existing callers.
  • merge-risk: 🚨 security-boundary: The new native deletion boundary is stronger, but its remaining POSIX leaf-swap window must be stated and accepted precisely.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (linked_artifact): Linked Linux, macOS, and Windows jobs built the public package and native binding and exercised required-mode Root mutations under adversarial parent swaps, reporting zero outside or denied effects and fail-closed unsupported recursion. The combined proof branch uses the same TypeScript removal owner and POSIX native removal blobs as this PR head; no stored-data contract changes are present.
  • proof: sufficient: Contributor real behavior proof is sufficient. Linked Linux, macOS, and Windows jobs built the public package and native binding and exercised required-mode Root mutations under adversarial parent swaps, reporting zero outside or denied effects and fail-closed unsupported recursion. The combined proof branch uses the same TypeScript removal owner and POSIX native removal blobs as this PR head; no stored-data contract changes are present.

Evidence

Security concerns:

  • [medium] Final POSIX leaf replacement remains possible — native/src/root_remove.rs:33
    The final statat and unlinkat are separate operations. A replacement within the retained parent can be removed after the identity check, so maintainers should explicitly accept and document this bounded guarantee.
    Confidence: 0.95

What I checked:

  • Current main still needs the fix: The main-branch Root implementation calls the guarded pathname removal path; that path ultimately calls pathname unlink or rmdir. (src/root-impl.ts:993, cf71fe80db39)
  • Latest release also uses pathname removal: The v0.21.1 Root implementation has the same fallback dispatch and no native removal route. (src/root-impl.ts:993, 305ff575ce13)
  • Introduced required-mode route: The PR selects native removal only in require mode; the default auto mode retains the existing removal path. (src/root-impl.ts:997, e99e98cec1b6)
  • Required-mode compatibility change: Recursive directory removal returns helper-unavailable when native directory traversal is unavailable; the new integration test explicitly expects this on Windows. (src/root-remove-native.ts:80, e99e98cec1b6)
  • Initial inspection lacks error context: The first recursive native stat error is rethrown without operation, phase, and relative-path details, unlike later inspection failures. (src/root-remove-native.ts:75, e99e98cec1b6)
  • POSIX leaf limitation: The implementation explicitly acknowledges that statat and unlinkat are separate operations, leaving a final leaf-replacement window within the retained parent. (native/src/root_remove.rs:33, e99e98cec1b6)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the required-mode upgrade and bounded POSIX guarantee with the Root contract owner.
  • Restore initial-inspection failure details.
  • Add the concise Unreleased security and compatibility entry.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-28T03:36:09.500Z sha 51dfbb6 :: blocked before merge. :: [P2] Honor force when a directory vanishes before native descent | [P2] Preserve recursive removal failure details in the native path
  • reviewed 2026-09-28T08:01:25.803Z sha 32a4830 :: needs real behavior proof before merge. :: [P2] Preserve details for the initial native inspection failure
  • reviewed 2026-09-28T08:09:05.323Z sha 32a4830 :: needs real behavior proof before merge. :: [P2] Preserve details for the initial native inspection failure | [P3] Add an Unreleased entry for the removal contract
  • reviewed 2026-09-28T08:28:51.661Z sha ffc657e :: needs real behavior proof before merge. :: [P1] Preserve the recursive removal upgrade contract | [P2] Attach removal details to initial native inspection errors | [P3] Add the user-facing Unreleased entry
  • reviewed 2026-09-28T08:48:45.164Z sha c0fee44 :: needs real behavior proof before merge. :: [P1] Preserve the recursive removal upgrade contract | [P2] Attach details to initial native inspection errors | [P3] Record the user-visible removal change under Unreleased
  • reviewed 2026-09-28T09:30:58.155Z sha 5304a9b :: needs real behavior proof before merge. :: [P1] Preserve the recursive removal upgrade contract | [P2] Attach details to initial native inspection errors | [P3] Record the user-visible removal change under Unreleased
  • reviewed 2026-09-28T11:08:38.897Z sha 59bb904 :: needs real behavior proof before merge. :: [P1] Preserve the recursive removal upgrade contract | [P2] Attach context to initial native inspection errors | [P3] Record the removal change under Unreleased
  • reviewed 2026-09-28T13:15:27.401Z sha 59bb904 :: blocked before merge. :: [P1] Resolve the recursive removal upgrade contract | [P2] Attach context to initial native inspection errors | [P3] Record the removal contract under Unreleased

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 28, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Sep 28, 2026
@steipete
steipete marked this pull request as ready for review September 28, 2026 13:10
@steipete
steipete requested a review from a team as a code owner September 28, 2026 13:10
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Sep 28, 2026
@steipete
steipete force-pushed the codex/require-harden-remove-20260927 branch from 59bb904 to a4e2746 Compare September 28, 2026 13:44
@steipete
steipete merged commit 682fe75 into main Sep 28, 2026
47 checks passed
@steipete
steipete deleted the codex/require-harden-remove-20260927 branch September 28, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant