Skip to content

fix(root): confine mkdir and writable-open creation in require mode - #751

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

steipete merged 5 commits into
mainfrom
codex/require-harden-create-20260927

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Required-mode Root mkdir and writable-open creation previously retained pathname mutations. Creation now admits and retains native parent directories, creates missing children relative to them, and opens missing files exclusively without following the final component. FileHandle handoff must match the originally created inode, and append retains creation-parent ownership through settlement so a rejected handoff cannot authorize cleanup of a replacement.

The native creation syscall receives the requested mode, preserving umask and inherited ACL restrictions without a widening post-create chmod. Unsupported handoffs fail closed. Windows uses handle-relative creation and cleanup; private Windows mkdir retains its existing protected native creator. Adjacent POSIX mkdir/open steps are fused into one native call while policy and identity fences remain.

The hardened path applies only to require. Default auto retains its previous best-effort creation paths even when the addon is loaded. Mode selection is captured before asynchronous admission and uses a cheap probe with unchanged configuration precedence. Missing-addon consumer probes explicitly verify helper-unavailable rather than restoring a JavaScript fallback. Compatibility and platform details are in #752. 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: required mkdir 236.40 -> 1,015.35 us/call; append creation with a missing parent 616.55 -> 1,860.02 us/call. Auto mkdir 232.98 -> 233.39 us/call (+0.2%); auto append creation 550.42 -> 556.41 us/call (+1.1%), within the controls. A focused warmed auto openWritable A/A/B control measured 210.03 -> 209.30 us/call with no demonstrated slowdown.

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, 10:13 AM ET / 14:13 UTC (Revision 7).

ClawSweeper review

What this changes

The branch routes required-mode Root directory and missing-file creation through retained native parent directories and identity-checked file handles, while keeping automatic mode on its existing creation path.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 10 items remain

Current main still uses pathname-based creation, so this security fix remains useful. The latest head retains two require-mode compatibility breaks, lacks an Unreleased entry, and needs its security guidance coordinated with the open documentation PR.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Real production-path proof is strong, but compatibility findings and an unresolved security contract keep the patch below merge-ready quality.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The changed Root creation owner is exercised through the built public package by the exact-head Linux, macOS, and Windows mutation-proof run, which reports successful allowed mkdir, writable-open and append cases and rejected parent or authority substitutions. Earlier linked combined-branch campaigns add longer race coverage; 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): The changed Root creation owner is exercised through the built public package by the exact-head Linux, macOS, and Windows mutation-proof run, which reports successful allowed mkdir, writable-open and append cases and rejected parent or authority substitutions. Earlier linked combined-branch campaigns add longer race coverage; no stored-data contract changes are present.
Evidence reviewed 10 items Repository policy: The full root policy treats filesystem confinement and public compatibility as security-sensitive and calls for user-visible security and compatibility changes under Unreleased.
Current-main behavior: Current main opens existing writable files and creates missing ones with Node pathname opens; the native creation file added by this PR is absent from main. The requested hardening remains necessary.
Existing-file compatibility: With default mkdir behavior, required mode invokes native parent creation before trying the existing-file open. An unavailable or older creation helper can therefore reject an operation that needs no creation.
Findings 3 actionable findings [P1] Open existing files before requiring creation support
[P1] Resolve the restrictive-mode creation break
[P2] Record the public security change under Unreleased
Security Needs attention Coordinate the public confinement guarantee: Current writing guidance recommends require mode for hostile mutation while the companion operation matrix and limitations remain unmerged. Publishing this change with an overbroad guarantee could lead callers to rely on protection that other operations do not yet provide.

How this fits together

Root accepts caller-supplied paths and mutation options, checks them against a filesystem root and policy, then creates directories or opens files. Native require mode is intended to constrain the filesystem effects of those operations.

flowchart LR
A[Caller path and options] --> B[Root mutation]
B --> C{Native mode}
C --> D[Retained parent directory]
C --> E[Guarded pathname path]
D --> F[Directory or file creation]
E --> F
F --> G[Verified result or error]
Loading

Decision needed

Question Recommendation
Should require-mode creation deliberately fail closed for restrictive permissions that prevent a safe FileHandle handoff, despite the existing creation-mode contract and measured latency? Approve bounded fail-closed behavior: Accept the restrictive-mode limitation and measured cost after the existing-file defect is fixed and the upgrade and security guidance is published.

Why: Preserving those creation cases may require a different descriptor handoff, while a fail-closed change intentionally stops some existing require-mode workflows.

Before merge

  • Open existing files before requiring creation support (P1) - With default mkdir behavior, this calls the native creation helper before the existing-file fs.open. An unavailable or older helper now rejects openWritable or append on a file that already exists. Move helper admission to the missing-file branch and cover that case.
  • Resolve the restrictive-mode creation break (P1) - The handoff check rejects modes such as 0o400 and restrictive umasks or ACLs before creation, while the existing Root creation contract allows those permissions. Preserve a safe handoff if feasible, or obtain approval for the fail-closed upgrade behavior and test and document it explicitly.
  • Record the public security change under Unreleased (P2) - This new required-mode creation path changes both confinement and compatibility, but Unreleased has no user-facing entry. Add a concise security and upgrade note as required by the repository policy.
  • Resolve security concern: Coordinate the public confinement guarantee - Current writing guidance recommends require mode for hostile mutation while the companion operation matrix and limitations remain unmerged. Publishing this change with an overbroad guarantee could lead callers to rely on protection that other operations do not yet provide.
  • Resolve merge risk (P1) - Require-mode opens of existing files can fail when an older or unavailable creation helper is encountered, even though no file needs creating.
  • Resolve merge risk (P1) - Require-mode creation with restrictive modes, umasks, or inherited ACLs can now fail closed where an existing setup previously worked; the upgrade contract needs explicit approval and guidance.
  • Resolve merge risk (P1) - The operation-specific security and compatibility guidance in fix(root): confine documented guarantees in require mode #752 remains unmerged, so this change should not land with a broader confinement claim than the combined implementation supports.
  • Resolve merge risk (P1) - The PR reports roughly fourfold required-mode mkdir latency and threefold append creation latency with a missing parent; that operator cost has not received an explicit acceptance decision.
  • Complete next step (P2) - Fix existing-file admission, decide and document the restrictive-mode upgrade contract, add the Unreleased entry, and coordinate the security guidance before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Open existing files before requiring creation support — src/root-impl.ts:701-705
  • [P1] Resolve the restrictive-mode creation break — src/root-create-native.ts:209-215
  • [P2] Record the public security change under Unreleased — src/root-impl.ts:1026-1031
  • [medium] Coordinate the public confinement guarantee — src/root-impl.ts:1026
Agent review details

Security

Needs attention: The native path adds confinement, but its require-mode guarantee needs the operation-specific security guidance in the open companion PR.

Review metrics

Metric Value Why it matters
Code growth production +433 net lines, tests +314 net lines, probes +2 net lines The substantial production growth serves the stated retained-parent confinement goal and merits focused review of the new custody paths.

Merge-risk options

Maintainer options:

  1. Repair admission and publish the contract (recommended)
    Open existing files before requiring creation support, resolve the restrictive-mode decision, add the Unreleased entry, and coordinate the companion documentation.
  2. Accept the remaining operating cost
    After the compatibility defects are addressed, explicitly accept the measured require-mode latency and describe it for affected callers.

Technical review

Best possible solution:

Keep creation confined to retained native parents in require mode, preserve existing-file opens, and publish an approved restrictive-permission upgrade contract with the companion security guidance.

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

Yes. The current-head source shows helper admission before an existing-file open, and the added restrictive-mode test explicitly expects require-mode rejection; this read-only review did not execute either case locally.

Is this the best way to solve the issue?

No, not yet. Retained native creation addresses the confinement gap, but existing-file opens should remain independent of creation support and the restrictive-mode change needs an approved upgrade path.

Full review comments:

  • [P1] Open existing files before requiring creation support — src/root-impl.ts:701-705
    With default mkdir behavior, this calls the native creation helper before the existing-file fs.open. An unavailable or older helper now rejects openWritable or append on a file that already exists. Move helper admission to the missing-file branch and cover that case.
    Confidence: 0.96
  • [P1] Resolve the restrictive-mode creation break — src/root-create-native.ts:209-215
    The handoff check rejects modes such as 0o400 and restrictive umasks or ACLs before creation, while the existing Root creation contract allows those permissions. Preserve a safe handoff if feasible, or obtain approval for the fail-closed upgrade behavior and test and document it explicitly.
    Confidence: 0.95
  • [P2] Record the public security change under Unreleased — src/root-impl.ts:1026-1031
    This new required-mode creation path changes both confinement and compatibility, but Unreleased has no user-facing entry. Add a concise security and upgrade note as required by the repository policy.
    Confidence: 0.98

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 682fe7589aa3.

Labels

Label changes:

No label changes.

Label justifications:

  • P0: The PR addresses a security-sensitive filesystem confinement gap for untrusted paths.
  • merge-risk: 🚨 compatibility: Require-mode existing-file opens and restrictive new-file modes can stop working after merge.
  • merge-risk: 🚨 security-boundary: The changed confinement boundary needs operation-specific guidance coordinated with the still-open documentation PR.
  • merge-risk: 🚨 other: The measured required-mode creation latency is a material operator cost outside the more specific risk categories.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit 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): The changed Root creation owner is exercised through the built public package by the exact-head Linux, macOS, and Windows mutation-proof run, which reports successful allowed mkdir, writable-open and append cases and rejected parent or authority substitutions. Earlier linked combined-branch campaigns add longer race coverage; no stored-data contract changes are present.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed Root creation owner is exercised through the built public package by the exact-head Linux, macOS, and Windows mutation-proof run, which reports successful allowed mkdir, writable-open and append cases and rejected parent or authority substitutions. Earlier linked combined-branch campaigns add longer race coverage; no stored-data contract changes are present.

Evidence

Security concerns:

  • [medium] Coordinate the public confinement guarantee — src/root-impl.ts:1026
    Current writing guidance recommends require mode for hostile mutation while the companion operation matrix and limitations remain unmerged. Publishing this change with an overbroad guarantee could lead callers to rely on protection that other operations do not yet provide.
    Confidence: 0.86

What I checked:

  • Repository policy: The full root policy treats filesystem confinement and public compatibility as security-sensitive and calls for user-visible security and compatibility changes under Unreleased. (AGENTS.md, a33a6b7a77cf)
  • Current-main behavior: Current main opens existing writable files and creates missing ones with Node pathname opens; the native creation file added by this PR is absent from main. The requested hardening remains necessary. (src/root-impl.ts:715, 682fe7589aa3)
  • Existing-file compatibility: With default mkdir behavior, required mode invokes native parent creation before trying the existing-file open. An unavailable or older creation helper can therefore reject an operation that needs no creation. (src/root-impl.ts:701, a33a6b7a77cf)
  • Restrictive-mode compatibility: The new handoff rejects creation when mode, umask, or inherited permissions prevent reopening the file. The added integration test explicitly expects require mode to reject mode 0o400 while auto mode succeeds. (src/root-create-native.ts:209, a33a6b7a77cf)
  • Public creation contract: The writing guide says mode selects new-file permissions for append and openWritable; it does not yet describe the new require-mode rejection for restrictive creation. (docs/writing.md:342, a33a6b7a77cf)
  • Release-note gap: Unreleased has no entry for this user-visible confinement and compatibility change. (CHANGELOG.md:3, a33a6b7a77cf)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: 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.

  • Move creation-helper admission after the existing-file attempt and cover the default mkdir case.
  • Settle the restrictive-mode upgrade decision and add its regression and Unreleased guidance.
  • Coordinate the operation-specific security caveat with fix(root): confine documented guarantees in require mode #752.

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 (6 earlier review cycles)
  • reviewed 2026-09-28T08:01:08.662Z sha a003280 :: blocked before merge. :: [P1] Resolve the restrictive-mode upgrade break
  • reviewed 2026-09-28T08:09:11.668Z sha a003280 :: blocked before merge. :: [P1] Resolve the restrictive-mode upgrade break | [P1] Leave existing-file opens independent of creation support
  • reviewed 2026-09-28T08:29:18.401Z sha 480068b :: needs real behavior proof before merge. :: [P1] Preserve restrictive-mode writable creation | [P1] Open existing files before requiring a creation helper | [P2] Update the packaged consumer scenario contract
  • reviewed 2026-09-28T08:44:32.214Z sha 5cb53aa :: needs real behavior proof before merge. :: [P1] Open existing files before requiring creation support | [P1] Resolve the restrictive-mode creation break | [P2] Record the user-visible security change under Unreleased
  • reviewed 2026-09-28T11:08:21.952Z sha 554460a :: needs real behavior proof before merge. :: [P1] Open existing files before requiring creation support | [P1] Resolve the restrictive-mode creation break | [P2] Record the public security change under Unreleased
  • reviewed 2026-09-28T13:22:08.365Z sha 554460a :: blocked before merge. :: [P1] Open existing files before requiring creation support | [P1] Resolve the restrictive-mode creation break | [P2] Record the public security change under Unreleased

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. and removed 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. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. labels 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. 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. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 28, 2026
@steipete
steipete force-pushed the codex/require-harden-create-20260927 branch from 554460a to dc878d0 Compare September 28, 2026 14:05
@steipete
steipete merged commit c4912a5 into main Sep 28, 2026
47 checks passed
@steipete
steipete deleted the codex/require-harden-create-20260927 branch September 28, 2026 14:26
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: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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