Skip to content

fix(atomic): bind directory modes to descriptors - #95

Merged
steipete merged 1 commit into
mainfrom
fix/dirmode-chmod
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/dirmode-chmod

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • apply dirMode through verified, no-follow directory descriptors on POSIX
  • remove the remaining pathname chmod / chmodSync calls from atomic replacement
  • preserve plain node:fs injection and reuse the existing optional fchmodSync sync capability
  • document the fail-closed POSIX open behavior and bounded Windows mkdir(mode) behavior

Security impact

The previous pathname chmod could be redirected through a symlink when an attacker could rename entries in the destination directory's parent. That prerequisite is stronger than write access inside the destination directory and, on sticky directories, also depends on ownership or equivalent privilege. The caller must additionally have chmod authority over the unrelated symlink target.

The regression swaps the directory entry at the mode-application boundary with real syscalls under umask 0077. On origin/main, both async and sync paths leave the requested directory at 0755 and change the unrelated directory to 0751. This branch leaves the unrelated directory at 0755 and applies 0751 to the opened real target.

Windows does not enforce POSIX directory modes and Node cannot consistently open directory descriptors there. The implementation therefore keeps mode passing on mkdir but does not make a vulnerable pathname fallback.

Verification

  • pnpm check (679 passed, 32 skipped)
  • pnpm test:security (64 passed)
  • focused descriptor-mode regressions (10 passed)
  • git diff --check
  • Codex autoreview: clean, no accepted/actionable findings

@steipete
steipete requested a review from a team as a code owner August 2, 2026 22:10
@clawsweeper clawsweeper Bot added 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. P1 Urgent regression or broken agent/channel workflow affecting real users now. 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. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 6:14 PM ET / 22:14 UTC.

ClawSweeper review

What this changes

The PR replaces pathname-based parent-directory mode changes during atomic file replacement with verified, no-follow directory descriptor operations on POSIX, while retaining bounded Windows behavior.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 6 items remain

This PR pursues a valid security hardening, but its new synchronous injected-filesystem guard permits an adapter without fchmodSync to skip the established default parent-directory mode when dirMode is omitted. That compatibility and permission-boundary regression needs a focused repair before merge.

Priority: P1
Reviewed head: cfaa746703369c697c0fce7f102762f17e5a1d2a

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has a valuable security objective and focused tests, but a blocking compatibility defect and missing inspectable real-behavior proof keep it below merge-ready quality.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR body describes real syscall race results but does not include inspectable terminal output, logs, recording, or linked artifact showing the after-fix run; add redacted runtime evidence before merge. 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 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body describes real syscall race results but does not include inspectable terminal output, logs, recording, or linked artifact showing the after-fix run; add redacted runtime evidence before merge. 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 6 items Descriptor-bound hardening: The branch opens a POSIX parent directory with no-follow and directory-only flags, verifies the opened descriptor against the pre-open identity, then applies the mode through that descriptor.
Default-mode compatibility regression: Current main unconditionally applies the effective default parent mode after mkdir. The branch only rejects a missing injected fchmodSync when dirMode was explicitly supplied, while its new helper returns without applying the effective default mode.
Current-main behavior: The base implementation calls chmodSync on the parent after mkdir regardless of whether dirMode was explicitly supplied, so custom synchronous adapters previously received the default 0o700 behavior.
Findings 1 actionable finding [P1] Require descriptor chmod for the effective default directory mode
Security Needs attention Sync adapter can skip default parent permissions: A POSIX custom adapter without fchmodSync can proceed when dirMode is omitted, causing the new directory-mode helper to return without enforcing the effective default 0o700 directory mode.

How this fits together

The atomic write subsystem creates a sibling temporary file, applies security-relevant modes, and renames it into place. Its injectable filesystem adapters support tests and alternate implementations, so descriptor-mode handling must retain both filesystem safety guarantees and the public adapter contract.

flowchart LR
  A[Caller options] --> B[Atomic replacement]
  B --> C[Create parent directory]
  C --> D[Open verified parent descriptor]
  D --> E[Apply directory mode]
  E --> F[Write pinned temp file]
  F --> G[Rename into destination]
  G --> H[Published file]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body describes real syscall race results but does not include inspectable terminal output, logs, recording, or linked artifact showing the after-fix run; add redacted runtime evidence before merge. 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.
  • Require descriptor chmod for the effective default directory mode (P1) - When a custom POSIX sync adapter omits fchmodSync and the caller omits dirMode, this guard permits execution but applyDirectoryModeSync returns without applying the effective default 0o700 mode. Current main applies that default through chmodSync, so this silently weakens existing adapter behavior. Treat the default as mode-requiring too, or fail before mkdirSync, and add a regression for this adapter shape.
  • Resolve security concern: Sync adapter can skip default parent permissions - A POSIX custom adapter without fchmodSync can proceed when dirMode is omitted, causing the new directory-mode helper to return without enforcing the effective default 0o700 directory mode.
  • Resolve merge risk (P1) - On POSIX, a custom synchronous filesystem adapter without fchmodSync and without an explicit dirMode can now create or retain the parent directory without the established default 0o700 mode.
  • Resolve merge risk (P1) - The supplied status shows the Windows Node 22 check failing and Windows package smoke still in progress, so the claimed platform behavior is not fully validated.
  • Complete next step (P2) - The branch has a narrow repair, but the contributor must also provide real after-fix proof and the pending Windows validation needs review before merge.

Findings

  • [P1] Require descriptor chmod for the effective default directory mode — src/replace-file.ts:395-401
  • [medium] Sync adapter can skip default parent permissions — src/replace-file.ts:395
Agent review details

Security

Needs attention: The descriptor hardening is security-positive, but the synchronous injected-adapter guard introduces a concrete permission-boundary regression.

Review metrics

Metric Value Why it matters
Patch surface 6 files affected; 303 added, 19 removed The change spans public docs, compatibility types, descriptor operations, and swap-race regression coverage.
Platform checks 1 failed, 2 in progress Windows validation remains incomplete for a patch that explicitly changes Windows behavior.

Merge-risk options

Maintainer options:

  1. Preserve the default mode contract (recommended)
    Require fchmodSync for the effective default parent mode on POSIX, or otherwise retain that behavior through an equally safe adapter contract with focused regression coverage.
  2. Pause for adapter-contract redesign
    Pause this PR if custom sync adapters without fchmodSync should intentionally have a no-mode behavior, because that would change the established public injection contract.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Update the POSIX sync injected-filesystem guard so missing fchmodSync cannot silently skip the effective default dirMode; add a regression for omitted dirMode and retain descriptor-only mode changes.

Technical review

Best possible solution:

Preserve the effective default parent-directory mode for synchronous injected adapters by failing before mutation when descriptor chmod is unavailable, or explicitly redesign and approve that adapter contract; add a regression that covers omitted dirMode.

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

Yes. On POSIX, inject a synchronous filesystem without fchmodSync and omit dirMode; the guard permits the call and the new helper returns without applying the effective default 0o700 parent mode.

Is this the best way to solve the issue?

No. Descriptor-bound directory chmod is the right safety mechanism, but the synchronous capability guard must account for the effective default dirMode, not only an explicitly supplied option.

Full review comments:

  • [P1] Require descriptor chmod for the effective default directory mode — src/replace-file.ts:395-401
    When a custom POSIX sync adapter omits fchmodSync and the caller omits dirMode, this guard permits execution but applyDirectoryModeSync returns without applying the effective default 0o700 mode. Current main applies that default through chmodSync, so this silently weakens existing adapter behavior. Treat the default as mode-requiring too, or fail before mkdirSync, and add a regression for this adapter shape.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The changed synchronous adapter path can weaken default parent-directory permissions for existing POSIX consumers.
  • add merge-risk: 🚨 compatibility: The PR changes behavior for documented injectable synchronous filesystem adapters when dirMode is omitted.
  • add merge-risk: 🚨 security-boundary: Skipping the effective default directory mode can leave an atomic-write parent directory less private than the established contract.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body describes real syscall race results but does not include inspectable terminal output, logs, recording, or linked artifact showing the after-fix run; add redacted runtime evidence before merge. 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.

Label justifications:

  • P1: The changed synchronous adapter path can weaken default parent-directory permissions for existing POSIX consumers.
  • merge-risk: 🚨 compatibility: The PR changes behavior for documented injectable synchronous filesystem adapters when dirMode is omitted.
  • merge-risk: 🚨 security-boundary: Skipping the effective default directory mode can leave an atomic-write parent directory less private than the established contract.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body describes real syscall race results but does not include inspectable terminal output, logs, recording, or linked artifact showing the after-fix run; add redacted runtime evidence before merge. 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

Security concerns:

  • [medium] Sync adapter can skip default parent permissions — src/replace-file.ts:395
    A POSIX custom adapter without fchmodSync can proceed when dirMode is omitted, causing the new directory-mode helper to return without enforcing the effective default 0o700 directory mode.
    Confidence: 0.98

What I checked:

  • Descriptor-bound hardening: The branch opens a POSIX parent directory with no-follow and directory-only flags, verifies the opened descriptor against the pre-open identity, then applies the mode through that descriptor. (src/replace-file-descriptor.ts:36, cfaa74670336)
  • Default-mode compatibility regression: Current main unconditionally applies the effective default parent mode after mkdir. The branch only rejects a missing injected fchmodSync when dirMode was explicitly supplied, while its new helper returns without applying the effective default mode. (src/replace-file.ts:395, cfaa74670336)
  • Current-main behavior: The base implementation calls chmodSync on the parent after mkdir regardless of whether dirMode was explicitly supplied, so custom synchronous adapters previously received the default 0o700 behavior. (src/replace-file.ts:402, 8926c3303c5b)
  • Feature provenance: The adjacent replacement-mode descriptor behavior appears to date to the earlier atomic hardening commit; this PR is not an ancestor of current main and no containing release tag was found. (src/replace-file.ts:404, da387a72a840)
  • Focused coverage gap: The branch adds real pathname-swap regressions and a plain node:fs injection case, but it does not cover a custom synchronous adapter without fchmodSync when the caller omits dirMode. (test/atomic-dirmode-regression.test.ts:193, cfaa74670336)
  • Repository safety policy: Repository policy requires fail-closed filesystem identity handling and focused regression coverage for swap races, permissions, and platform fallbacks. (AGENTS.md:21, 8926c3303c5b)

Likely related people:

  • steipete: The recent atomic replacement descriptor-mode commit is attributed to Peter Steinberger, and the PR author steipete continues the same code path. (role: introduced adjacent descriptor-mode behavior; confidence: high; commits: da387a72a840, cfaa74670336; files: src/replace-file.ts, src/replace-file-descriptor.ts, test/atomic-fchmod-regression.test.ts)

Rank-up moves

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

  • Fix the effective-default dirMode guard and add the missing injected-adapter regression.
  • Add a redacted terminal transcript, log, or recording showing the POSIX swap-race result after the fix.
  • Resolve the failing Windows Node 22 check and refresh platform validation.

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.

@steipete
steipete merged commit 14448ba into main Aug 2, 2026
43 of 44 checks passed
@steipete
steipete deleted the fix/dirmode-chmod branch August 2, 2026 22:18
steipete added a commit that referenced this pull request Aug 2, 2026
The 10-second bound added in #89 was too tight for the command fallback and
fired on contended Windows runners, producing an intermittent
permission-unverified failure on unrelated pull requests. That code means "we
could not verify", which a consumer may reasonably treat as a security signal,
so emitting it because a runner was busy is a false alarm with real
consequences.

Successful runs of the affected secure-read test measure 1.930s to 5.400s, and
one Node 24 leg passed at 9.349s with roughly 651ms of margin. The contended
failures on #94 and #95 landed at 10.130s and 10.173s, which is the old bound
firing rather than a hang.

Thirty seconds is over five times the slowest observed success and about three
times the overloaded cutoff, while still terminating a genuinely wedged command
rather than letting it hang indefinitely. The deadline stays per process, since
each child is the independently wedgable unit and an overall budget would let
several slow-but-successful commands compete for one allowance and reproduce
the same false result.

Fail-closed behavior is unchanged: a real failure or timeout still yields
source "unknown", and secure reads still reject it as permission-unverified.
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. P1 Urgent regression or broken agent/channel workflow affecting real users now. 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