Skip to content

fix(move): bind staging modes to descriptors - #94

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

steipete merged 1 commit into
mainfrom
fix/staging-chmod

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • apply copied-file modes through the still-open staging descriptor
  • apply POSIX directory modes through a no-follow directory descriptor and avoid a pathname fallback on Windows
  • add deterministic real-filesystem regressions that swap each staging entry at the mode boundary under a restrictive umask

Proof

  • pnpm check
  • pnpm test:security
  • git diff --check
  • Codex autoreview: clean, no accepted/actionable findings

The regression demonstrates the old behavior redirecting the requested mode to an unrelated symlink target while leaving the published entry umask-clamped. With this patch, the same swap occurs once, the unrelated target remains unchanged, and the requested mode lands on the real published file or directory.

@steipete
steipete requested a review from a team as a code owner August 2, 2026 22:08
@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. 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. 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:27 PM ET / 22:27 UTC.

ClawSweeper review

What this changes

The branch applies copied-file modes through the open staging file descriptor and POSIX directory modes through a no-follow descriptor, adding deterministic staging-symlink-swap regressions for cross-device moves.

Merge readiness

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

Keep this PR open for merge review: the descriptor-bound permission changes are a focused security repair with no source-level correctness finding, but the updated body still lacks inspectable after-fix runtime evidence. Likely related person: steipete is the recent current-main owner of this move path and the analogous directory-mode hardening.

Priority: P2
Reviewed head: c7cd3cc8e0008e9d19a77d7807e2eafa3b3aa9f3

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation and focused regression design are strong, but merge readiness is capped until the contributor supplies inspectable real-behavior proof.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR describes a deterministic real-filesystem regression, but no inspectable after-fix terminal output, artifact, log, or recording is attached; add redacted output that shows the staging swap, unchanged victim mode, and corrected published mode. 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 stronger real behavior proof before merge: The PR describes a deterministic real-filesystem regression, but no inspectable after-fix terminal output, artifact, log, or recording is attached; add redacted output that shows the staging swap, unchanged victim mode, and corrected published mode. 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 Current vulnerable path: Current main restores copied directory modes with pathname-based fs.chmod(to, ...), leaving the staging pathname observable between creation and publication.
Proposed descriptor binding: The branch retains the staging file handle through copying and uses FileHandle.chmod; POSIX directories are opened with O_DIRECTORY | O_NOFOLLOW before their mode is applied, while Windows deliberately avoids a pathname fallback.
Focused regression coverage: The added test swaps each visible staging pathname for a symlink during descriptor chmod and asserts that the victim mode stays unchanged while the published file or directory receives its requested mode under a restrictive umask.
Findings None None.
Security None None.

How this fits together

movePathWithCopyFallback() creates a randomized temporary entry beside the destination, copies and verifies the source into it, applies source modes, then renames the staged entry into place. This protects callers whose cross-device moves encounter attacker-controlled destination directories.

flowchart LR
  Source[Source path] --> Stage[Temporary staging entry]
  Stage --> Copy[Copy and verify source identity]
  Copy --> Mode[Apply requested mode]
  Mode --> Publish[Guarded rename]
  Publish --> Destination[Published destination]
  Attacker[Staging pathname swap] -. blocked by .-> Mode
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR describes a deterministic real-filesystem regression, but no inspectable after-fix terminal output, artifact, log, or recording is attached; add redacted output that shows the staging swap, unchanged victim mode, and corrected published mode. 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) - On Windows, cross-device directory moves will intentionally retain the mode created by mkdir() rather than performing the current pathname chmod; this matches the current-main atomic-directory policy, but should be demonstrated or explicitly accepted as the bounded compatibility tradeoff.
  • Resolve merge risk (P1) - The patch is security-sensitive and the current PR body contains only test-command claims, not inspectable after-fix runtime output showing that a staging swap cannot change the unrelated target's mode.
  • Complete next step (P2) - No mechanical repair is identified; the contributor needs to provide real after-fix runtime proof and maintainers need the remaining Windows compatibility evidence before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch surface 3 files affected: 177 added, 12 removed The implementation is narrowly scoped to move-mode handling, an adversarial regression test, and the required unreleased security note.
Regression scenarios 2 real-filesystem staging-swap cases Both regular-file and directory staging modes are covered under a restrictive umask.

Merge-risk options

Maintainer options:

  1. Attach real swap-proof output (recommended)
    Add a redacted terminal transcript or linked artifact that performs the staging swap and prints the unchanged victim mode plus the final published mode before merge.
  2. Accept the Windows mode policy explicitly
    If maintainers accept that Windows directory modes remain mkdir()-only during copy fallback, record that this matches the existing atomic-directory policy and retain the no-pathname fallback.

Technical review

Best possible solution:

Land the descriptor-bound POSIX behavior and Windows no-pathname fallback only after a redacted real-filesystem proof visibly shows the swap, the unchanged victim mode, and the published entry's requested mode; preserve the established Windows policy rather than restoring an unsafe pathname chmod.

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

Yes, source-reproducible: current main applies modes to visible staging pathnames, and the branch's focused tests define a deterministic swap at that boundary. The submitted PR does not yet include inspectable output from that real filesystem run.

Is this the best way to solve the issue?

Yes, subject to proof: descriptor-bound chmod mirrors the current-main atomic-directory hardening and removes the unsafe pathname operation rather than adding a new API or fallback mode.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a focused security and correctness repair in a public cross-device move path, without evidence of a broad active outage.
  • merge-risk: 🚨 security-boundary: The patch changes how permission writes are bound to attacker-visible staging filesystem objects before publication.
  • merge-risk: 🚨 compatibility: Windows directory copy fallback intentionally no longer applies a post-creation pathname mode, so existing platform behavior requires explicit validation.
  • 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 stronger real behavior proof before merge: The PR describes a deterministic real-filesystem regression, but no inspectable after-fix terminal output, artifact, log, or recording is attached; add redacted output that shows the staging swap, unchanged victim mode, and corrected published mode. 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:

  • Current vulnerable path: Current main restores copied directory modes with pathname-based fs.chmod(to, ...), leaving the staging pathname observable between creation and publication. (src/move-path.ts:287, eda9a61fcf7f)
  • Proposed descriptor binding: The branch retains the staging file handle through copying and uses FileHandle.chmod; POSIX directories are opened with O_DIRECTORY | O_NOFOLLOW before their mode is applied, while Windows deliberately avoids a pathname fallback. (src/move-path.ts:172, c7cd3cc8e000)
  • Focused regression coverage: The added test swaps each visible staging pathname for a symlink during descriptor chmod and asserts that the victim mode stays unchanged while the published file or directory receives its requested mode under a restrictive umask. (test/move-path-fchmod-regression.test.ts:75, c7cd3cc8e000)
  • Feature-history precedent: Current main already adopted the same POSIX descriptor-bound directory-mode and Windows no-pathname-fallback policy for atomic replacement directories in commit 14448ba3. (src/move-path.ts:287, 14448ba3bb34)
  • Move-path provenance: Blame attributes the current move fallback and its pathname mode restoration to the v0.5.1 release commit, tying the affected behavior to the recent move implementation. (src/move-path.ts:287, 16e1bd489ae8)
  • Proof gate remains unmet: The PR body reports commands and describes the expected regression outcome, but it provides no redacted terminal transcript, live output, artifact, recording, or runtime log that independently shows the after-fix swap result. (c7cd3cc8e000)

Likely related people:

  • steipete: Peter Steinberger authored the current move fallback implementation in the v0.5.1 release and the immediately preceding descriptor-bound directory-mode hardening that establishes the same platform policy. (role: recent area contributor and analogous hardening author; confidence: high; commits: 16e1bd489ae8, 14448ba3bb34; files: src/move-path.ts)

Rank-up moves

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

  • Attach a redacted terminal transcript or artifact showing the after-fix filesystem swap result, with private paths and identifiers removed.
  • Update the PR body with that evidence; if an automatic fresh review does not occur, ask a maintainer to comment @clawsweeper re-review.

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-08-02T22:12:52.270Z sha 18b0836 :: needs real behavior proof before merge. :: none

movePathWithCopyFallback() closed the staging descriptor and then applied the
mode to the staging pathname, and applied staged directory modes by path. The
staging names are randomized but visible to anyone who can list the writable
target directory, so the entry could be replaced with a symlink before the
chmod and the mode change redirected before publication.

Regular files now keep the staging handle and use FileHandle.chmod(). POSIX
directories use an O_RDONLY|O_DIRECTORY|O_NOFOLLOW handle. Windows performs no
pathname fallback, since Node cannot portably open a directory descriptor there
and POSIX modes are not enforced.

No injectable filesystem member was added.
@steipete
steipete force-pushed the fix/staging-chmod branch from fae42b4 to c7cd3cc Compare August 2, 2026 22:24
@steipete
steipete merged commit 3c64caa into main Aug 2, 2026
22 checks passed
@steipete
steipete deleted the fix/staging-chmod branch August 2, 2026 22:28
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. 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