Skip to content

fix(windows): reject dangling writable leaves before creation - #823

Merged
steipete merged 2 commits into
mainfrom
fix/windows-dangling-writable-20261001
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/windows-dangling-writable-20261001

Conversation

@steipete

@steipete steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Windows Node opens can follow a dangling file symlink even with O_CREAT | O_EXCL. With native mode auto or off, openWritable() and Root.append() created the missing referent and then rejected the symlink during descriptor admission. An unchanged dangling link reproduces this; no race is needed.

Check the final leaf immediately before fallback creation when O_NOFOLLOW is unavailable. Preserve the missing referent and link, ordinary creation, and the existing contained-link behavior when mutation policy is omitted. Required native creation is unchanged; this preflight does not promise atomic confinement against concurrent replacement.

Validation: the real Windows AWS regression fails on main's production code in all eight negative cases (auto/off × replace/append/update/Root.append). With the fix, all ten regressions pass, plus eleven neighboring descriptor-identity tests; one POSIX-only case is skipped. TypeScript compilation passes. Codex autoreview is clean through P2. Includes an Unreleased Fixes entry and the creation-contract documentation. Exact-head all-OS CI and CodeQL are required before merge.

@steipete
steipete requested a review from a team as a code owner October 1, 2026 23:05
@clawsweeper

clawsweeper Bot commented Oct 1, 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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 7:38 PM ET / 23:38 UTC (Revision 2).

ClawSweeper review

What this changes

The PR rejects dangling final symlinks before Windows fallback writable-file creation and adds regression tests, creation-contract documentation, and an Unreleased changelog entry.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: neither current main nor v0.22.0 contains the pre-creation guard. No introduced correctness or security defect was found.

Priority: P2
Reviewed head: 601afcdeca7d59625002593651180af382c1986f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with direct regression coverage and explicit compatibility limits; no blocking patch defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies a MEMBER author, so the ordinary external-contributor proof gate does not apply. The captured body reports real Windows AWS runs through openWritable and Root.append, with eight main failures becoming ten passing regression cases; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies a MEMBER author, so the ordinary external-contributor proof gate does not apply. The captured body reports real Windows AWS runs through openWritable and Root.append, with eight main failures becoming ten passing regression cases; no stored-data contract changes.
Evidence reviewed 9 items Introduced production guard: The pinned introduced diff adds the existing final-symlink rejection helper immediately before fallback fs.open, only where O_NOFOLLOW is unavailable. Required-native creation and existing-file admission remain intact.
Main still needs the fix: Current main proceeds directly from mutation and path-selection checks to fallback creation. Its later descriptor admission can reject a symlink only after creation has occurred.
Latest release also lacks the guard: The v0.22.0 source has the same unguarded fallback creation. The release endpoint confirms v0.22.0 is the latest release, published October 1, 2026.
Findings None None.
Security None None.

How this fits together

fs-safe gives Node.js applications filesystem roots for handling untrusted paths. Its writable-file admission path resolves destinations, opens or creates files, and verifies their identities before returning a handle or appending data.

flowchart TD
  A[Untrusted destination path] --> B[Root and parent checks]
  B --> C[Open existing file]
  C --> D{File missing?}
  D -->|Yes| E[Reject observed final symlink]
  E --> F[Create file]
  D -->|No| G[Verify descriptor and path identity]
  F --> G
  G --> H[Return handle or append data]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and regression growth production +2, tests +41; 10 regression cases The production growth directly addresses premature creation and has negative and compatibility coverage.

Technical review

Best possible solution:

Keep the shared pre-creation rejection while preserving ordinary creation, existing contained-link behavior, and the documented best-effort fallback boundary.

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

Yes: an unchanged dangling file symlink reaches fallback creation in auto/off modes before descriptor rejection; the PR supplies a focused regression and reports real Windows before/after results. This read-only review did not execute that reproduction.

Is this the best way to solve the issue?

Yes: reusing the final-component rejection helper directly before creation is a narrow repair that preserves existing successful paths and avoids claiming atomic confinement.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a concrete Windows fallback creation defect through a narrow change without introducing a new API.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies a MEMBER author, so the ordinary external-contributor proof gate does not apply. The captured body reports real Windows AWS runs through openWritable and Root.append, with eight main failures becoming ten passing regression cases; no stored-data contract changes.

Evidence

What I checked:

  • Introduced production guard: The pinned introduced diff adds the existing final-symlink rejection helper immediately before fallback fs.open, only where O_NOFOLLOW is unavailable. Required-native creation and existing-file admission remain intact. (src/root-impl.ts:789, 601afcdeca7d)
  • Main still needs the fix: Current main proceeds directly from mutation and path-selection checks to fallback creation. Its later descriptor admission can reject a symlink only after creation has occurred. (src/root-impl.ts:788, e074abeeae2f)
  • Latest release also lacks the guard: The v0.22.0 source has the same unguarded fallback creation. The release endpoint confirms v0.22.0 is the latest release, published October 1, 2026. (src/root-impl.ts, ef7b5a909bff)
  • Shared rejection semantics: The reused helper lstat-checks the final component, rejects symlinks, tolerates genuinely missing paths, and propagates other inspection errors. It explicitly provides a preflight rather than an atomic concurrency boundary. (src/root-symlink-policy.ts:28, 601afcdeca7d)
  • Regression and compatibility coverage: Eight negative cases cover auto/off native modes across replace, append, update, and Root.append, checking that both the missing referent and original symlink are preserved. Two positive cases check regular creation and existing contained-link append behavior. The captured PR body reports these passing on real Windows AWS against production code after eight failures on main; this review did not execute them. (test/root-open-writable-dangling.test.ts:10, 601afcdeca7d)
  • Bounded fallback contract: The PR explicitly preserves required-native creation and omitted-policy contained-link behavior, and documents that the new inspection does not close the inspection/open race. This is the existing fallback limitation, not a new weakening. (docs/writing.md:685, 601afcdeca7d)

Likely related people:

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

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 (1 earlier review cycle)
  • reviewed 2026-10-01T23:08:17.504Z sha 738ae70 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit ea0fbcd into main Oct 1, 2026
47 checks passed
@steipete
steipete deleted the fix/windows-dangling-writable-20261001 branch October 1, 2026 23:52
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Verified on the exact head 601afcdeca7d59625002593651180af382c1986f.

Minimal Windows repro, using a fresh directory dir and omitted mutation policy:

configureFsSafeNative({ mode: "auto" });
await fs.symlink("missing", path.join(dir, "leaf"), "file");
await (await root(dir)).openWritable("leaf"); // rejects with "symlink"

Before the fix, dir/missing nevertheless existed as an empty file. After the fix it remains absent. Real AWS Windows tests reproduced the side effect in all eight auto/off × replace/append/update/Root.append cases; the fix passes all ten regressions and eleven adjacent identity tests (one POSIX-only case skipped). A compiled public-API replay confirms no created referent in all nine mode/writeMode combinations, including unchanged required-native behavior. Replaying the 16-seed differential corpus makes all eight dangling-leaf tree comparisons equal across Node/Bun and modes; only the backend-specific rejection codes differ.

Codex autoreview is clean through P2. An earlier head had an Intel macOS Bun child-process startup timeout; its one exact-job retry was superseded when main advanced and the branch was updated. Exact-head all-OS CI and CodeQL passed before the SHA-pinned squash merge. No release, tag, or publication.

steipete added a commit that referenced this pull request Oct 2, 2026
Add bounded transition checks for small pending-hint budgets, missing descendants, case and Unicode aliases, undecodable names, exclusions, directory lifecycle, scope replacement and subscription isolation. Verify invalidation-only cache convergence and calibrate failure cleanup and four-pass polling bounds.

Add seeded TypeScript reference properties, 65,536 Rust Pending operations, and sync/async atomic fault-injection coverage. Include the finite corpus in the nightly five-runner stress workflow. No new dependency or test-only restructuring.

Validated with 500 poll and 500 event seeds on Linux, APFS macOS and NTFS Windows, focused properties and Rust checks on each OS, plus exact-head all-OS CI and CodeQL. Parent-close precedence and Windows dangling-leaf creation were fixed separately in #820 and #823.
steipete added a commit that referenced this pull request Oct 2, 2026
Reject observed symlink leaves before portable Windows exclusive creation across standalone creators, Root create-only writes, lock records, exclusive copy publication, and internal stages. Preserve exclusive-create collisions, lock-denial provenance, and descriptor-bound cleanup.

Extend #823 with outside-target regressions: existing Root admission already rejected escaping absolute, relative, UNC, and device targets. Real Windows proof reproduces the remaining in-Root creation cases and standalone outside-target cases, including source-content writes after actual cross-volume EXDEV. Preserve the documented best-effort boundary against concurrent replacement.

Validation: real Windows AWS before/main/fixed matrices and focused suites; pnpm check; independent Codex review through P2; exact-head CI and CodeQL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant