Skip to content

fix(security): fence root file opens - #428

Merged
steipete merged 3 commits into
mainfrom
codex/root-file-final-boundary-20260916
Sep 16, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/root-file-final-boundary-20260916

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Low-level root-file opens could finish against a replaced root or file after traversal. This change captures the Root identity before traversal and verifies the Root, descriptor, and canonical pathname before returning an opened file.

The Windows correction binds native root spelling to the already-observed identity, including caller-supplied rootRealPath values, so short-name roots and long-name files agree without weakening identity checks. Integration preserves single-read pathname snapshots, metadata observations, namespace rejection, and namespaced-drive-root dispatch. POSIX and custom adapters retain their existing lookup ownership.

The integrated package builds and 102 focused open, JSON, path, and store tests pass (10 platform skips). Fresh independent review through P2 found no actionable issue. Head 1ae20ab44184fc5a11def0e0a70f03020e99c457 passed Windows and the complete CI matrix, including coverage, then was fast-forwarded onto main.

The first Windows run exposed a wide metadata fixture whose timed-out setup could keep writing and alter the following test’s native-loader state. File creation now uses tracked suite setup, failed batches settle completely, and cleanup owns the final mock/native reset. Focused fixture tests pass (20 tests, 1 platform skip); the change received independent review.

@steipete
steipete requested a review from a team as a code owner September 16, 2026 07:16
@clawsweeper

clawsweeper Bot commented Sep 16, 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 P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. 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. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 16, 2026, 6:09 AM ET / 10:09 UTC (Revision 3).

ClawSweeper review

What this changes

The branch adds final root and file identity checks before returning descriptors or reading contents, normalizes Windows root spellings, and updates documentation, regression tests, benchmarks, and fixture cleanup.

Merge readiness

⛔ Blocked before merge - 4 items remain

The low-level adapter hardening remains necessary. The merged Root-read work covers only part of this branch; no concrete patch defect was found, but real behavior proof and supplied-root compatibility acceptance remain unresolved.

Priority: P2
Reviewed head: 1ae20ab44184fc5a11def0e0a70f03020e99c457
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation and regression coverage are useful, but the required real behavior evidence remains test-only.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Needs real behavior proof before merge: the supplied body reports tests, while the unique openRootFile/openRootFileSync fence lacks an after-fix runtime transcript showing valid descriptor handoff and substitution rejection with closure before consumer reads. The inspected filesystem tests are supplemental. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Needs real behavior proof before merge: the supplied body reports tests, while the unique openRootFile/openRootFileSync fence lacks an after-fix runtime transcript showing valid descriptor handoff and substitution rejection with closure before consumer reads. The inspected filesystem tests are supplemental. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 9 items Applicable repository policy: Read the complete root AGENTS.md, CONTRIBUTING.md, and SECURITY.md. No nested AGENTS.md or maintainer-notes directory was present. Applied exact-identity, fail-closed, public-contract, and changelog guidance; did not run the prohibited autoreview helper or artifact-producing checks.
Distinct low-level final admission: The new admission callback verifies the captured root, resolves and confines the consumed pathname, compares the canonical leaf with the descriptor using bigint identity, and verifies the root again. openPinnedFileSync retains descriptor ownership until this callback succeeds and closes rejected descriptors.
Partial overlap is already merged: GitHub confirms #424 merged as 5434276. That implementation fences higher-level Root reads. Inspection of src/root-file.ts at fetched main still shows the low-level adapters without the new root observation or final-admission callback.
Findings None None.
Security None None.

How this fits together

fs-safe turns untrusted paths into filesystem access confined to a selected root. Its low-level file adapters supply admitted descriptors to callers, including structured-file readers and synchronous file stores.

flowchart TD
  A[Untrusted path and root] --> B[Capture root identity]
  B --> C[Traverse and validate path]
  C --> D[Open and verify descriptor]
  D --> E[Recheck root and canonical file]
  E -->|Accepted| F[Return descriptor to reader]
  E -->|Rejected| G[Close descriptor and report failure]
Loading

Decision needed

Question Recommendation
Should supplied-root opens unconditionally require the new root observations and final canonicalization, including their newly reachable adapter or native-helper failures? Accept the fence with upgrade evidence: Keep the mandatory checks after documenting the affected supplied-root cases and demonstrating supported runtime and adapter outcomes.

Why: The security fence is coherent, but acceptance of newly failing existing caller setups requires an explicit compatibility decision rather than an inferred approval from passing tests.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Needs real behavior proof before merge: the supplied body reports tests, while the unique openRootFile/openRootFileSync fence lacks an after-fix runtime transcript showing valid descriptor handoff and substitution rejection with closure before consumer reads. The inspected filesystem tests are supplemental. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - Existing supplied-root callers now require additional root metadata observations and final canonicalization. Custom adapters that cannot service these observations, or Bun POSIX require-mode setups without the canonicalizer, can begin rejecting previously successful opens; the supplied evidence does not demonstrate that upgrade boundary.
  • Complete next step (P2) - Provide the adapter runtime and compatibility evidence and obtain acceptance of the upgrade contract. Terminal screenshots or recordings are welcome; copied output and logs also count. Redact keys, private paths, IP addresses, and endpoints. Updating the PR body should trigger another review; otherwise ask a maintainer to comment @clawsweeper re-review.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth production +450 net lines; tests +1613 net lines The pinned introduced delta adds dedicated admission helpers and extensive race coverage, with the security boundary providing a stated justification for production growth.

Merge-risk options

Maintainer options:

  1. Establish the supplied-root upgrade contract (recommended)
    Demonstrate existing supplied-root callers with custom adapters and Bun native modes, and document any newly rejected configuration before accepting the change.
  2. Defer incompatible adapter changes
    Pause landing if supported callers need an adapter transition that this branch does not yet define.

Technical review

Best possible solution:

Retain the exact-identity fence with proven supplied-root compatibility and an explicit upgrade contract for custom adapters and Bun's existing native modes.

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

Yes, at source level: current-main low-level opens lack the captured-root and final-canonical admission sequence, and the new tests identify deterministic substitution points. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes, structurally: extending the existing pinned-open ownership boundary is a focused solution, and the docs accurately limit it to observational protection; runtime and upgrade evidence remain necessary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 54342760a4e9.

Labels

Label justifications:

  • P2: This is focused filesystem admission hardening with concrete tests and no demonstrated emergency affecting deployed users.
  • merge-risk: 🚨 compatibility: Supplied-root opens gain mandatory metadata and canonicalization calls that can expose new adapter or native-helper failures in existing setups.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Needs real behavior proof before merge: the supplied body reports tests, while the unique openRootFile/openRootFileSync fence lacks an after-fix runtime transcript showing valid descriptor handoff and substitution rejection with closure before consumer reads. The inspected filesystem tests are supplemental. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Applicable repository policy: Read the complete root AGENTS.md, CONTRIBUTING.md, and SECURITY.md. No nested AGENTS.md or maintainer-notes directory was present. Applied exact-identity, fail-closed, public-contract, and changelog guidance; did not run the prohibited autoreview helper or artifact-producing checks. (AGENTS.md:27, 1ae20ab44184)
  • Distinct low-level final admission: The new admission callback verifies the captured root, resolves and confines the consumed pathname, compares the canonical leaf with the descriptor using bigint identity, and verifies the root again. openPinnedFileSync retains descriptor ownership until this callback succeeds and closes rejected descriptors. (src/root-file-final-admission.ts:83, 1ae20ab44184)
  • Partial overlap is already merged: GitHub confirms fix(security): fence Root reads against root replacement #424 merged as 5434276. That implementation fences higher-level Root reads. Inspection of src/root-file.ts at fetched main still shows the low-level adapters without the new root observation or final-admission callback. (src/root-file.ts:139, 54342760a4e9)
  • Latest-release boundary: The root-file source at the supplied latest release v0.12.0 contains neither finalAdmission nor CanonicalRootObservation. The low-level change therefore remains absent from both inspected main and this release. (src/root-file.ts, 914cd7b41388)
  • Focused regression coverage: The adapter tests exercise async and sync opens against root, parent, and leaf substitutions at four final-admission phases, checking rejection, one descriptor close, and no adapter reads. Additional tests cover valid descriptors, contained aliases, missing paths, custom observation ownership, Windows root spellings, and unknown identities. These are supplemental test sources, not a supplied production-run transcript. (test/root-file-final-admission.test.ts:76, 1ae20ab44184)
  • Supplied-root compatibility boundary: Final canonicalization now runs even when rootRealPath was supplied. Custom adapters receive additional directory observations and a final realpath call. The built-in adapter uses src/realpath.ts, whose existing Bun POSIX require mode rejects unavailable canonicalization support; docs/install.md documents that runtime contract. This is a direct dependency on the target's runtime adapter, not a reason to inspect an unrelated repository. (src/root-file-final-admission.ts:71, 1ae20ab44184)

Likely related people:

  • Peter Steinberger: Raw commit 5434276 adds src/root-read-admission.ts:50 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 54342760a4e9; files: src/root-read-admission.ts)

Rank-up moves

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

  • Add redacted after-fix terminal output for async and sync root-file opens accepting valid files and rejecting root, parent, and final-file substitutions with descriptor closure before consumer reads.
  • Demonstrate supplied-root compatibility for custom adapters, Windows root spellings, and Bun native modes, including unavailable canonicalization support, and document the accepted upgrade behavior.

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 (2 earlier review cycles)
  • reviewed 2026-09-16T07:19:27.718Z sha 905d9a5 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T09:42:24.676Z sha 234d9c9 :: needs real behavior proof before merge. :: none

Fence Root reads against replacement of the captured root and final path, rejecting swapped trees before returning file contents or handles.
Fence low-level root-file opens with exact root and final-file identities, consistently admitting native Windows root spellings without weakening symlink or replacement rejection.
@steipete
steipete force-pushed the codex/root-file-final-boundary-20260916 branch from 905d9a5 to 234d9c9 Compare September 16, 2026 09:37
Keep file creation outside the observation assertion timeout, settle failed batches, and defer native-loader and mock reset until pending fixture work completes.
@steipete
steipete merged commit 1ae20ab into main Sep 16, 2026
31 checks passed
@vincentkoc
vincentkoc deleted the codex/root-file-final-boundary-20260916 branch September 25, 2026 11:15

This branch was previously deployed

1 inactive deployment
github-pages — 1ae20ab4 Deployed Sep 16, 2026 by steipete via Deploy docs #266
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. P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant