Skip to content

fix(security): verify temp workspace creation roots - #373

Merged
steipete merged 2 commits into
mainfrom
codex/temp-workspace-admission-20260914
Sep 16, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/temp-workspace-admission-20260914

Conversation

@steipete

@steipete steipete commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Temporary-workspace creation previously changed directory permissions by pathname before establishing trustworthy ownership. This change admits the root and its ancestry, preserves existing directory permissions, and binds child mode initialization and cleanup to retained identities and descriptors.

Admission stays current through creation and final adoption. Unsafe or ambiguous ownership states fail closed; bounded cleanup keeps its explicit capability requirement. Integration preserves Windows namespace handling, captured caller options, and the directory observation helpers introduced by the earlier security fixes.

The integrated package builds and its focused creation, permission, cleanup, namespace, and observation suites pass: 323 tests, with 81 platform/native skips. Fresh independent review through P2 found no actionable issue. Public workspace types were separated from lifecycle code to retain the existing file-size budget. Head 59e85b8656ca9deb5621c94086d8fb02a22d74b9 passed the complete CI matrix and was fast-forwarded onto main. An unrelated Windows ACL-command check passed unchanged on a targeted retry; its first execution took 30.3 seconds, matching the external-command timeout.

The first Windows Node 22 run exposed an unrelated retained-lock fixture timeout. Setup and drain now use the existing suite-fixture lifecycle and separate hook budgets; the wrapper assertion keeps its five-second budget. Both focused fixture suites pass (8 tests), and the CI fix received independent review through P2.

@steipete
steipete requested a review from a team as a code owner September 14, 2026 23:29
@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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 16, 2026, 5:05 AM ET / 09:05 UTC (Revision 23).

ClawSweeper review

What this changes

The PR verifies temporary-workspace roots and children before use, binds permission changes and cleanup to retained directory identities, and updates regression coverage, documentation, and a lock-test fixture.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep open: current main and v0.12.0 still contain the unsafe permission-change sequence this PR addresses. The stricter contract has explicit approval, and this review found no new actionable correctness defect.

Priority: P2
Reviewed head: 59e85b8656ca9deb5621c94086d8fb02a22d74b9

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation has substantial regression coverage and no new concrete finding, but required authority proof and performance recovery remain unestablished.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: Authority-chain proof required: both workspace factories and the retained-child owner need unprivileged built-public-API evidence covering fresh/existing roots, actual mode correction, unsafe-root/ancestor rejection without mutation, and replacement preservation before cleanup transfer. The captured tests and older benchmark run do not establish those after-fix final effects. 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: Authority-chain proof required: both workspace factories and the retained-child owner need unprivileged built-public-API evidence covering fresh/existing roots, actual mode correction, unsafe-root/ancestor rejection without mutation, and replacement preservation before cleanup transfer. The captured tests and older benchmark run do not establish those after-fix final effects. 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 11 items Repository policy: Read the full root AGENTS.md and contribution guide; no nested AGENTS.md or maintainer-notes directory was found. Applied the filesystem-boundary, compatibility, and changelog guidance while honoring the read-only review restriction.
Repair remains necessary on main: Main still calls ensurePrivateDirectory on the supplied root and applies child chmod by pathname before capturing the child's identity.
Latest release also retains the old sequence: The v0.12.0 source still changes supplied-root permissions and performs child pathname chmod before lstat. Release source was inspected through GitHub after the local historical blob lookup failed.
Findings None None.
Security Needs attention Establish preservation before authority transfer: The supplied tests simulate foreign ownership and substitutions, but do not provide the required unprivileged built-package evidence that forbidden objects remain unchanged before chmod and cleanup adoption; this is an evidence gap, not a demonstrated bypass.

How this fits together

fs-safe creates temporary directories for Node.js applications from caller-supplied roots and permission options. Its admission checks determine which directories may be used, have permissions initialized, and acquire cleanup authority.

flowchart TD
  A[Caller root and options] --> B[Verify root and ancestry]
  B --> C[Create unique child]
  C --> D[Retain and verify child identity]
  D --> E[Initialize permissions through descriptor]
  E --> F[Revalidate before adoption]
  F --> G[Workspace and guarded cleanup]
  B --> H[Reject unsafe state]
  D --> H
  F --> H
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: both workspace factories and the retained-child owner need unprivileged built-public-API evidence covering fresh/existing roots, actual mode correction, unsafe-root/ancestor rejection without mutation, and replacement preservation before cleanup transfer. The captured tests and older benchmark run do not establish those after-fix final effects. 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 security concern: Establish preservation before authority transfer - The supplied tests simulate foreign ownership and substitutions, but do not provide the required unprivileged built-package evidence that forbidden objects remain unchanged before chmod and cleanup adoption; this is an evidence gap, not a demonstrated bypass.
  • Resolve merge risk (P1) - Existing POSIX callers using foreign-owned roots, non-sticky writable ancestry, writable workspace modes, or restrictive bounded-cleanup modes will now fail; this is approved, but the required upgrade evidence remains outstanding.
  • Resolve merge risk (P1) - Unprivileged final-effect evidence has not established that foreign-owned or replaced objects remain untouched before permission correction and cleanup-authority transfer.
  • Resolve merge risk (P1) - Earlier candidates exceeded the declared latency gate; current-head performance recovery has not been demonstrated by the supplied measurements.
  • Complete next step (P2) - Add the required unprivileged authority transcript and current-head comparative performance results. Redact private paths, hosts, credentials, and other sensitive details; terminal output or diagnostic recordings are suitable. Update the PR body to trigger re-review, or ask a maintainer to comment @clawsweeper re-review if it does not run.

Findings

  • [medium] Establish preservation before authority transfer — src/private-temp-workspace.ts:214
Agent review details

Security

Needs attention: No concrete bypass or supply-chain regression was found, but the material permission and cleanup-authority handoff still requires final-effect proof.

Review metrics

Metric Value Why it matters
Production and test growth Production +1,664/-184, net +1,480; tests +3,453/-10, net +3,443 The production growth implements the stated admission and descriptor-lifecycle hardening, with substantial regression coverage.

Merge-risk options

Maintainer options:

  1. Hold for the approved evidence gates (recommended)
    Keep the security contract intact and defer landing until unprivileged final-effect proof and current base/candidate performance measurements satisfy the recorded conditions.

Technical review

Best possible solution:

Preserve the approved descriptor-bound admission design, with demonstrated fresh and existing-root safety, replacement preservation, and acceptable creation latency.

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

Yes, from source: both main factories change directory permissions by pathname before establishing child identity, and supplied-root modes are rewritten. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes in direction: retained descriptors and explicit admission address the unsafe sequence, and the compatibility change is approved. Final acceptance still depends on the recorded authority and performance evidence.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a concrete filesystem-safety repair without evidence of an active widespread emergency.
  • merge-risk: 🚨 security-boundary: Permission correction and retained cleanup authority materially change, while required forbidden-object final-effect proof remains outstanding.
  • merge-risk: 🚨 compatibility: Approved stricter POSIX admission intentionally rejects previously accepted roots and modes.
  • merge-risk: 🚨 other: Historical measurements exceeded the creation-latency gate, and current-head recovery remains unverified.
  • 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: Authority-chain proof required: both workspace factories and the retained-child owner need unprivileged built-public-API evidence covering fresh/existing roots, actual mode correction, unsafe-root/ancestor rejection without mutation, and replacement preservation before cleanup transfer. The captured tests and older benchmark run do not establish those after-fix final effects. 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] Establish preservation before authority transfer — src/private-temp-workspace.ts:214
    The supplied tests simulate foreign ownership and substitutions, but do not provide the required unprivileged built-package evidence that forbidden objects remain unchanged before chmod and cleanup adoption; this is an evidence gap, not a demonstrated bypass.
    Confidence: 0.97

What I checked:

  • Repository policy: Read the full root AGENTS.md and contribution guide; no nested AGENTS.md or maintainer-notes directory was found. Applied the filesystem-boundary, compatibility, and changelog guidance while honoring the read-only review restriction. (AGENTS.md:23, 59e85b8656ca)
  • Repair remains necessary on main: Main still calls ensurePrivateDirectory on the supplied root and applies child chmod by pathname before capturing the child's identity. (src/private-temp-workspace.ts:190, 5108b3bb6250)
  • Latest release also retains the old sequence: The v0.12.0 source still changes supplied-root permissions and performs child pathname chmod before lstat. Release source was inspected through GitHub after the local historical blob lookup failed. (src/private-temp-workspace.ts:141, 914cd7b41388)
  • Authority handoff inspected: Both factories admit ancestry before creation, retain the child, initialize its mode through a descriptor, and validate ancestry plus descriptor/name identity before transferring cleanup ownership. Failed admission closes descriptors without deleting unverified children. (src/private-temp-workspace.ts:188, 59e85b8656ca)
  • Approved compatibility direction: The September 15 decision explicitly approves stricter POSIX root, ancestry, and mode admission, conditional on unprivileged public-API authority proof and current-head comparative performance: fix(security): verify temp workspace creation roots #373 (comment).
  • Regression coverage and remaining proof gap: Creation tests cover preserved root modes, unsafe ancestry, descriptor chmod, and replacement preservation; foreign ownership is simulated through metadata spies. The complete captured body reports focused test results, not the required unprivileged built-package final-effect evidence. Its sourceRevision is ae155ee7b0e11fce73d4907f2bcb8a51f360ec8a798dc8d89370e02c3afb576a; the live body and head matched the snapshot. (test/temp-workspace-creation-admission.test.ts:130, 59e85b8656ca)

Likely related people:

  • Peter Steinberger: Raw commit f4c5b32 adds src/temp-workspace-owner.ts:245 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f4c5b321ea9f; files: src/temp-workspace-owner.ts)

Rank-up moves

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

  • Provide redacted unprivileged public-API output showing allowed creation and preservation of foreign-owned or replaced objects before final filesystem effects.
  • Provide current base/candidate comparative measurements satisfying the declared performance gate.

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 (22 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-15T10:04:41.591Z sha 77261cd :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T11:02:25.246Z sha 3399c47 :: needs real behavior proof before merge. :: [P2] [P2] Capture the child descriptor before injecting chmod faults | [P2] [P2] Restore restrictive fixture permissions before cleanup
  • reviewed 2026-09-15T11:18:55.046Z sha 4880e73 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T11:54:13.235Z sha 7d457a2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T17:54:22.347Z sha a5435b2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T20:55:25.012Z sha bcb4b93 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T22:35:32.251Z sha 6feef15 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T08:47:58.599Z sha e2261bc :: needs real behavior proof before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Performance gate update (exact head 4e998a03ef2b65dd9094a83d95c7e92fb1e7481a, base 1897be894d43a82c779e24bd7857fd2dbdd275ba, shared candidate harness, Node 24, 100 iterations × 10 samples):

  • Ubuntu native-off tempWorkspaceSync: 123.57 → 242.20 µs median (+96.0%); native-required: 153.57 → 278.51 µs (+81.4%).
  • macOS native-off: 338.84 → 468.77 µs (+38.3%); native-required: 236.13 → 505.84 µs (+114.2%, 2.14×).
  • Async creation also adds 90–258 µs depending on platform/profile.
  • resolveSecureTempRoot itself stayed within noise; the cost is in the new object/ancestry admission checkpoints.

The macOS native-required sync result trips this PR's declared ≥2× investigation threshold. I am holding the PR and consulting a fresh Astra performance-design challenger to reduce redundant metadata/realpath passes without weakening fail-closed admission. These remote results are not a merge approval. Windows was still running when captured.

@steipete
steipete force-pushed the codex/temp-workspace-admission-20260914 branch from 4e998a0 to fd2d2a1 Compare September 15, 2026 00:48
@steipete

Copy link
Copy Markdown
Contributor Author

Performance repair update:

  • Superseding head: fd2d2a1d9d6d921be9593d792b0a3104e78bbead; the regressing 4e998a0 measurements remain recorded above but no longer describe the candidate.
  • A GPT-6 Astra xhigh redesign consultation removed redundant existing-root and missing-component replays and added an exact-mode first-snapshot fast path.
  • A separate fresh GPT-6 Astra xhigh reviewer inspected the complete amended base-to-working diff and returned ACCEPT with no P0-P2 finding, judging this the best narrow repair.
  • Exact-0o700 child admission is source-accounted at 2 child lstats, 0 descriptor fstats, and 0 mode descriptor open/close/chmod calls.
  • Async observations fall from 4D+23 to 3D+8 for existing roots and from 4D+19M+23 to 4D+5M+8 with missing components. Sync falls from 4D+20 to 3D+8 and 4D+16M+20 to 4D+5M+8.

Exact base/head cross-platform measurement is now running at https://github.com/openclaw/fs-safe/actions/runs/34914744914 (50 iterations × 7 samples). The PR remains held until exact-head CI, real unprivileged behavior proof, and measured recovery clear.

@steipete

Copy link
Copy Markdown
Contributor Author

Exact optimized-head audit fd2d2a1 (20x7, run 34914744914) still fails the latency gate despite lower source-level observation counts. Ubuntu: async creation improved -17.84%/-24.29% (off/require), but sync regressed +45.46%/+36.30%; mode-correction regressed +76% to +111%. macOS: async +37.56%/+20.91%, sync +124.80%/+81.16%, mode-correction +101.94% to +202.57%. Windows native-off: async +134.42%, sync +203.17% (native-required sweep timed out). Ranges are generally non-overlapping. Merge remains blocked. Astra is re-evaluating the architecture from the exact samples; no performance claim will be made from call counts alone.

@steipete

Copy link
Copy Markdown
Contributor Author

Correction to the preceding evidence note: the method JSON records 50 iterations and 7 samples per row, not 20x7. The medians, ranges, and percentages quoted there are unchanged.

@clawsweeper clawsweeper Bot added 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. labels Sep 15, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer decision: approve the stricter POSIX temp-workspace admission contract, conditional on the current-head authority proof and performance gates. Rejection of foreign-owned roots, non-sticky writable ancestry, writable workspace modes, and restrictive modes that cannot support bounded owner cleanup is intentional. Permission correction must target the verified new child descriptor; ambiguous or replaced roots/children must remain untouched and must not acquire cleanup authority. Existing callers should supply an effectively owned root with safe ancestry and a mode that permits the documented bounded cleanup, or explicitly choose another compliant root; the implementation must not regain compatibility through an unsafe pathname chmod or cleanup fallback. Landing remains held until unprivileged built-public-API evidence covers both factories, fresh and existing roots, real mode correction, unsafe-root/ancestor rejection without mutation, and replacement preservation, and until exact-head comparative performance clears.

Admit temporary-workspace roots and children before use, preserve existing permissions, and bind mode initialization and cleanup to retained directory identities.
@steipete
steipete force-pushed the codex/temp-workspace-admission-20260914 branch from 6feef15 to e2261bc Compare September 16, 2026 08:38
Keep real sidecar acquisition and draining outside the wrapper-construction timeout. Track setup and test completion so fixture removal cannot race timed-out filesystem work.

This branch was previously deployed

1 inactive deployment
github-pages — 59e85b86 Deployed Sep 16, 2026 by steipete via Deploy docs #263
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. 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