Repository navigation
fix(record): run a cached Swift helper only from ground this user controls - #4670
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on a062eb4. The verdict and the full list are in the summary comment.
|
I found one regression and one missing validation at a062eb4. CI is green (18 checks, none failing), and there are no conflicts. The cache walk now runs before the compile, so its refusal comes before xcrun's TOOL_MISSING (swift-cache.ts:203). On a Linux daemon host with no Swift, take a Every new test mocks Not blocking, take or leave: Two open inline threads do not apply, so you can resolve them. The walk already makes every level of the spelled path ground only this user or root can change, so publishing via the spelling gives no one a window: #4670 (comment). No user doc describes the Swift cache or Before merge, keep non-Apple hosts out of the cache walk, and attach the live macOS record run with a fresh cache. |
|
Host-only evidence at What this shows:
A Output |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 2ca6d59. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 9628850. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Thanks for the follow-up. At 3ea710b the code fixes from the earlier review are in, but a separate security cross-check found two blockers in how the compiler is launched, and one piece of evidence is still missing. CI is green on all 18 checks, but no CI job runs a real swiftc compile of these helpers, so green CI does not cover the changed compile and exec route. The real compile, publish and exec flow at this head has never run through the daemon (swift-cache.ts:375). The only live run is the host-only script at cefeebd. Five later commits changed swift-cache.ts: the sticky-ancestor refusal (7145837), judging children inside v3 (c6094bb), refuse instead of delete (8665c41) and the hint changes (9628850, 2c0e0d3). Every unit and provider test stubs xcrun. A wrong refusal on the real default root, or a broken HOME or module-cache env for the real swiftc, would break every MP4 record stop on macOS, and no test would catch it. Please run this on macOS at this head, or a later head where swift-cache.ts is unchanged. Leave AGENT_DEVICE_SWIFT_CACHE_DIR unset and move ~/Library/Caches/agent-device/swift-cache aside. On an iOS simulator, run record start, one tap and record stop (MP4); both must succeed. Then show ls -la of swift-cache, v3, bin, home and module-cache (all drwx------, your uid) and of bin/video-validator- and bin/recording-overlay- (-rwxr-xr-x, your uid). Run a second record stop on a new recording and show the same validator mtime (stat -f %m), which proves no recompile. Not blocking, take or leave: the docs row (configuration.md:165) and the record help (recording/index.ts:132) say chmod does not fix an exposed v3, bin, home or module-cache, but judgeOwnedDirectory judges only the current mode, so chmod 700 clears the refusal and reuses whatever was written while it was open, so both texts could say chmod clears the refusal but not that content, and to remove the directory or point AGENT_DEVICE_SWIFT_CACHE_DIR at a new one; untrustedAncestorOf restates the ancestor rule from swift-cache.ts:103-118, which makes three spellings of one rule; and test-kit exports mkdtempUnsharedForTestSync with no caller, because the capture-kit tests use their own copy. Could host-kit own one "no sticky pass-through" trust mode for private ancestry, for example a prepareScriptDestination option or an exported privateAncestryReason(path) that requires uid-or-root and no 0o022, sticky or not? swift-cache.ts could call it in place of the post-walk loop at :103-118, the test sweep could call it in place of untrustedAncestorOf, and the unused test-kit helper could go. The rest (v3 0700 judging, reuse predicate, O_NOFOLLOW fchmod, in-flight memo, darwin gate) looks like the minimal shape for the threat. The earlier question about moving the default to the per-user cache dir is answered. This would need an ADR 0016 amendment first, naming the mode for executable state, so host-kit owns both variants of the rule. None of the four open inline threads still applies at this head, so please resolve them: no chmod of a shared root remains, and a missing unshared dir now skips or fails on CI; both helpers now return realpath of the mkdtemp result; swiftCacheHint names the ancestor as text and builds no command, with a test for a path with a space and a quote; a skipped sweep records the unavailable marker and tests skip, or throw on CI. Security blockers from the cross-check (the cache tree itself holds up: a swapped binary is refused, and Linux Android stop keeps the MP4 container check):
Before the label: fix both blockers, then attach the live simulator record run described above, at a head where swift-cache.ts no longer changes. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Live simulator evidence at
Result: CommandsEvery Cache tree after the first stop (uid 501)The entries inside No recompile on later stopsThe tap in the second recording was refused because I reused a ref from a snapshot taken before the first tap navigated. That is the operator's mistake, not a product failure, and that CleanupThe state directory was removed and the original cache was put back. |
|
Thanks for the update. At 6a81c44 the new DEVELOPER_DIR judging and the stripped compiler env close most of the earlier findings, and the live simulator run you posted (#4670 (comment)) shows the real compile, publish and reuse working on a fresh default cache. Two environment bypasses remain. The compiler env is still built by removing names from the inherited environment. swiftCompilerEnv drops only the names in The cached helpers have the same problem at launch. The validator, overlay and frame decoder all run with Once the allowlist lands, please repeat the simulator run once at that head, since the compiler launch changes again. Include one pass with One item is a scope decision for the maintainer rather than a code fix. The system-selected Xcode, and an explicit one under Not blocking, take or leave: Could the allowlist and a single host-kit All 18 checks pass at this commit. None of them compile the helpers with a real swiftc. The bypass comes from dry runs on a macOS host: The four earlier inline threads on the unshared test directory helpers and Before merge, please build the compiler env from an allowlist so inherited |
|
Live simulator evidence at
Result: both passes passed. In each, Pass 1:
|
This comment has been minimized.
This comment has been minimized.
|
Live simulator evidence at
Result: passed. |
…trols The Swift helper cache defaults to a fixed name under the system temp directory and reused any executable file found at a predictable path. On a host where that directory is shared, another local user could plant the helper first and have it run as the current user. Each cache directory is now judged by host-kit's ancestry rule and missing levels are created owner-only. A cached executable is reused only when it is a regular file, not a link, owned by this user and not group- or other-writable; anything else is compiled over. Source text is written inside the compile's private temp directory. Untrusted ground is refused with reason swift_cache_untrusted and a hint naming AGENT_DEVICE_SWIFT_CACHE_DIR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All cache state now lives under <root>/v3: bin, home, module-cache, the compile lock and its temp directories. Each level is judged by host-kit's ancestry rule and created 0700, the version directory is the one trust boundary, and nothing an earlier layout compiled or cached is reused. - The default root moves to this user's cache directory (~/Library/Caches/agent-device/swift-cache on macOS, XDG cache elsewhere); AGENT_DEVICE_SWIFT_CACHE_DIR stays the override. Test lanes no longer pin the old temp location. - Work uses the judged physical bin, confirmed unchanged before the reuse check and before the rename. - The video validator memoizes only in-flight work, so every resolution runs the reuse check again, and it answers no-toolchain on non-macOS hosts before touching the cache. - swift_cache_untrusted survives the validator wrapper, permission errors in the walk are classified as it, and a group-writable directory keeps the chmod g-w remedy in the hint. - Configuration docs and record help name the variable, the default, the privacy rule and the operator's ACL responsibility. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ords on The video validator now compiles only on macOS hosts, so on a Linux runner the iOS recording case never reached its compile and waited for a call that cannot come. The file now runs on the darwin platform it describes, wherever the suite runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The version directory is the boundary. Every directory above it must be closed to the group and other users, sticky or not, so a cleanup cannot remove the cache and let another account claim its name before a helper runs. - A version directory this user owns is made 0700 through an O_DIRECTORY|O_NOFOLLOW descriptor, so a lock created under umask 002 in an older 0755 cache is unreachable. One owned by another uid is refused. - The compile output is made 0755 through an O_NOFOLLOW descriptor. - EACCES/EPERM from the lock, mkdtemp, chmod and rename are swift_cache_untrusted. Compiler failures keep the toolchain path. - The first bin confirmation is gone: the walk just answered it. The confirmation after the lock wait now has its own test. - Exports with no outside consumer are private. - Tests that reach the cache keep it in the checkout's ignored .tmp/, since /tmp is a sticky shared directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- bin, home and module-cache are judged directly. Each is created 0700 in the judged version directory, an existing one must be a real directory (lstat, no link) owned by this uid, and a wider one is closed to its owner through an O_DIRECTORY|O_NOFOLLOW descriptor. The link-following child walk is gone, so no link can send the compile, lock or helper outside v3. - Confirmation compares the directory's own lstat identity. - One wrapper maps EACCES/EPERM from every cache filesystem operation (lookup, lock, mkdtemp, source write, chmod, rename, cleanup) to swift_cache_untrusted. Typed errors, compiler failures included, keep their path. - Test caches live in a per-run directory under the checkout's .tmp/, which the Vitest global setup removes after the run and prunes for killed runs. The provider harness removes its cache in finally. - The configuration row states the ancestry rule precisely. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- If v3 or one of its cache directories is wider than 0700, the version directory is removed (rmSync does not follow links) and recreated private, so a link or lock entry planted while it was open never survives. This replaces the tighten-through-descriptor code. Links, non-directories and foreign owners are still refused. - A staging cleanup that fails no longer replaces the compiler failure: the failure stays primary with the cleanup error as secondary detail. - The checkout-local test sweep acts only on a real directory this uid owns (lstat) and skips with a warning otherwise. It keeps a run directory with no parseable pid. A test pins teardown's removal of the run directory. - The configuration row scopes the chmod remedy to mode bits writable by the group or other users. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing it The Swift cache no longer deletes cache state. If v3, bin, home or module-cache is wider than 0700, a link, not a directory, or owned by another uid, it is refused with swift_cache_untrusted and a hint that names it for rm -rf, or AGENT_DEVICE_SWIFT_CACHE_DIR. This code creates those directories at 0700, so an exposed one means someone changed it. With no deletion, a v3 link cannot redirect a recursive removal, and two processes cannot delete each other's cache. - The cache root is judged by the walk. v3 must then be a real directory directly beneath it, owned by this uid and created 0700 if missing, so a link-resolved v3 never reaches a mutation. - The checkout-local test sweep, and the helpers' fallback, require every level from the checkout root down to be a real directory this uid owns that the group and other users cannot write. The sweep no longer chmods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aths - The checkout-local root for test state is now unshared-test-dirs-<uid>, so in a shared checkout another user's runs never share it. The helper's fallback already verifies every level and runs no chmod. - mkdtempUnsharedForTestSync returns fs.realpathSync of the directory it created, so callers get the physical path the Swift cache compares. The per-test realpath workarounds are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lper fallback - sweepUnsharedRunDirectories is split at its seams: judging the chain from the checkout root, creating a missing level, the private-directory test, and choosing the prunable run directories. Behavior is unchanged. - mkdtempUnsharedForTestSync moves to its own module in test-kit and in capture-kit, and keeps only the run-directory path: every caller runs under the Vitest global setup, which names that directory once the chain is private. The fallback chain check was the clone and is gone. tmp-dir.ts and tmp-dir.fixtures.ts are back to their main versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The cache key for embedded sources and for inline source text now includes the fixed compiler arguments (--sdk macosx swiftc). A release that changes them without bumping the cache version gets new entries instead of reusing a binary built with other flags. A test plants executables at the old, argument-less entry names and shows they are not reused. - The overlay provenance test asserts that every Swift input handed to swiftc lies in the compile's private staging directory, as well as holding the embedded bytes. Bytes alone could not tell a staged file from the real checkout source. - The drift test asserts each helper's exact, ordered file list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The two findings from the earlier review (#4670 (comment)) are fixed at 9eb7311: the disk-path sources and the competing script above the package are gone, and the overlay and contact-sheet helpers now compile embedded sources from staging. One docs finding remains. The new configuration entry says recording refuses an unsafe The security cross-check of this head is clean. No conflicts are known. Only one check is still pending and has not failed, and the other 23 pass. Writing staged sources with an explicit 0o600 mode is optional, since the 0700 staging directory already confines them. |
This comment has been minimized.
This comment has been minimized.
…ualify the DEVELOPER_DIR docs - The configuration row and record help say DEVELOPER_DIR is checked when a Swift helper compiles, and that a cached helper is reused without checking it. - The stricter cache ancestry rule now runs on the nearest existing directory before host-kit's walk can create the cache root, so no level is made under ground the cache would then refuse. It runs again on the completed chain. The sticky-directory refusal test asserts nothing was created. - Staged sources are written with mode 0600 alongside wx. A test checks it under umask 022. - The source generator refuses an input that is not a regular file, such as a link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
At d3ba120 the docs finding from the 9eb7311 review (#4670 (comment)) is fixed. The configuration entry now says A cache root reached through a symlink is created before the refusal. Suppose Not blocking, and you can take or leave these:
23 of 24 checks pass; the remaining one is a review check. There are no conflicts. |
…reated A cache root that was a link to a missing directory made the preflight judge the link's own parent, because realpath fails on a dangling link. host-kit's walk then created the target, for example under /tmp, before the second check refused it. The preflight now resolves the cache root the way the kernel does, following each link on the way down, and judges the deepest existing directory it reaches with the strict ancestry rule before anything is created. A test points the cache root at a missing directory under a sticky shared directory and asserts nothing is created there. Tests now pick the compiler's Swift inputs by their .swift suffix rather than by argument position. The compiler-arguments cache-key test moved into swift-cache.test.ts to keep the trust test under the line limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
At 73b8445 the d3ba120 finding is fixed for stable link chains. The preflight follows links down to the deepest existing directory and judges that chain with the strict rule, and the new test asserts nothing is created in the shared directory. The code review found no problems, and all 24 checks pass. A separate security cross-check of this head found one remaining gap. It comes from the same cause the review flagged as optional: the preflight is a second link walk next to host-kit's. The strict preflight and the creation walk can resolve different paths. Suppose a cache-root link in a private directory points through a second link, owned by this user, that sits in a sticky shared directory such as Please use one walk. Apply the Swift cache ancestry rule to the physical parent and missing tail that host-kit's own walk computes when it authorizes creation, and refuse that plan before its first Not blocking: the test moves and the |
…'s one walk
The cache judged its ancestry in its own preflight walk, separate from
host-kit's creation walk. If a temp cleaner removed an intermediate link
between the two, host-kit could create directories under /tmp before the
final check refused them.
- prepareScriptDestination takes { privateAncestry: true }. With it, the
walk refuses any directory it traverses that is group- or world-writable,
sticky or not, or owned by anyone but root or this user. It applies this
to every level, including the existing ancestors of a link's resolved
target, before its first mkdir. The default for script destinations is
unchanged.
- The Swift cache passes the option. Its separate preflight, the post-walk
check, deepestExistingLevel and the copied MAX_LINK_HOPS are gone.
- New host-kit tests: sticky world- and group-writable ancestors, a
group-writable ancestor, a foreign owner, a link into a sticky shared
directory, and an intermediate link in a sticky directory that vanishes
mid-walk. Each is refused with nothing created. The default mode still
passes the sticky ancestor through.
- ADR 0016 notes that executable state asks the walk for private ancestry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
At 41f82c7 host-kit's creation walk applies the private Swift cache ancestry rule before its first
All 24 checks pass, and there are no conflicts. |
|
At b0f9412 the production Swift-cache regression is in: it fails on the old two-walk code at 73b8445 and passes at this head. The code is unchanged since 41f82c7, which a separate cross-check found clean. But the shipped recording route still needs live validation. Once the device tooling mismatch is resolved, could you run the real daemon and iOS simulator record start/stop route twice, first with a cold private directory and then with the existing helper, with touch overlay enabled? The previous live recording was at 1aa0069, and the mocked test cannot prove dispatch, capture, Swift compilation, or MP4 finalization at this head. Please provide both playable MP4s, verify overlay output and validator completion, and record the commands, device, SHA, directory and executable ownership and modes, plus executable mtime before and after reuse. Recording route All nine listed CI jobs are in progress; no failure output was supplied. No conflicts are known. Before merge, provide the live evidence above and wait for the required CI jobs to finish. |
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
|
The maintainer accepted host-only evidence for this head. The live recording route was exercised at 1aa0069. Since then the changes are confined to the private Swift cache and host-kit's creation walk, and real-filesystem tests cover them, including the production regression that fails on 73b8445. The security cross-check of the code at 41f82c7 is clean, and b0f9412 adds only that test. All checks pass, and there are no conflicts. This is ready for review. |
… compileSwiftSourceText The generator embeds the three recording helpers through the packager's comment stripper, which keeps every line in place, and the parity guard compares against the stripped files. The video validator compiles through compileSwiftSources under a fixed file name, so the second compile entry point and its duplicate cache-key construction are gone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Evidence for the two size cuts at Changes
Validation
Size (
Changed files: Gaps
|
Rebased onto main, `atomic-file.ts` stands at 1014 lines against the 1000-line lint limit (this branch 1000, #4670 +14). Trimmed this branch's own restated prose rather than splitting the module, which would move closure counts the eager-closure gate holds: the two staging guards are documented once, at the staging owner, and the `claimed` parameter every call site passed as `true` is gone with the claim step it described. The state chain now says beside `scriptTrust({})` why it asks the script rule's own trust: its extra strictness is the walk's policy, not #4670's private-ancestry option, because a state record is data rather than an executable another user could compile.
main's boundary line said the daemon trusts its state directory. This branch made that false: the state route and every state write, read and open are judged now (#4649), so the line says what the code does, and one line points at the ADR that names what the judgment leaves out. docs/agents sits 9 bytes under its 40000 budget after #4670, so the state pointer is that one line and the cleanup boundary lives in ADR 0016's "Where the guarantee does not reach".
Rebased onto main, `atomic-file.ts` stands at 1014 lines against the 1000-line lint limit (this branch 1000, #4670 +14). Trimmed this branch's own restated prose rather than splitting the module, which would move closure counts the eager-closure gate holds: the two staging guards are documented once, at the staging owner, and the `claimed` parameter every call site passed as `true` is gone with the claim step it described. The state chain now says beside `scriptTrust({})` why it asks the script rule's own trust: its extra strictness is the walk's policy, not #4670's private-ancestry option, because a state record is data rather than an executable another user could compile.
main's boundary line said the daemon trusts its state directory. This branch made that false: the state route and every state write, read and open are judged now (#4649), so the line says what the code does, and one line points at the ADR that names what the judgment leaves out. docs/agents sits 9 bytes under its 40000 budget after #4670, so the state pointer is that one line and the cleanup boundary lives in ADR 0016's "Where the guarantee does not reach".
Rebased onto main, `atomic-file.ts` stands at 1014 lines against the 1000-line lint limit (this branch 1000, #4670 +14). Trimmed this branch's own restated prose rather than splitting the module, which would move closure counts the eager-closure gate holds: the two staging guards are documented once, at the staging owner, and the `claimed` parameter every call site passed as `true` is gone with the claim step it described. The state chain now says beside `scriptTrust({})` why it asks the script rule's own trust: its extra strictness is the walk's policy, not #4670's private-ancestry option, because a state record is data rather than an executable another user could compile.
main's boundary line said the daemon trusts its state directory. This branch made that false: the state route and every state write, read and open are judged now (#4649), so the line says what the code does, and one line points at the ADR that names what the judgment leaves out. docs/agents sits 9 bytes under its 40000 budget after #4670, so the state pointer is that one line and the cleanup boundary lives in ADR 0016's "Where the guarantee does not reach".
Rebased onto main, `atomic-file.ts` stands at 1014 lines against the 1000-line lint limit (this branch 1000, #4670 +14). Trimmed this branch's own restated prose rather than splitting the module, which would move closure counts the eager-closure gate holds: the two staging guards are documented once, at the staging owner, and the `claimed` parameter every call site passed as `true` is gone with the claim step it described. The state chain now says beside `scriptTrust({})` why it asks the script rule's own trust: its extra strictness is the walk's policy, not #4670's private-ancestry option, because a state record is data rather than an executable another user could compile.
main's boundary line said the daemon trusts its state directory. This branch made that false: the state route and every state write, read and open are judged now (#4649), so the line says what the code does, and one line points at the ADR that names what the judgment leaves out. docs/agents sits 9 bytes under its 40000 budget after #4670, so the state pointer is that one line and the cleanup boundary lives in ADR 0016's "Where the guarantee does not reach".
Summary
Scope is 38 changed files across recording, host-kit, tests, and docs.
v3cache, withAGENT_DEVICE_SWIFT_CACHE_DIRas an override. Ignore the old cache.xcrun --sdk macosxand an allowlisted environment. Resolve and checkDEVELOPER_DIRwhen compiling. ACLs are outside this check.swift_cache_untrustedat record stop.93f6ac6: the embedded recording helpers are comment-stripped with the packager's stripper, lines kept in place. The video validator compiles throughcompileSwiftSources, socompileSwiftSourceTextis gone.Validation
73b8445, passes atb0f9412.pnpm check:affected --run --head 93f6ac6passed all runnable checks (exactCommit: true). Evidence is on the PR comment. CI owns native smoke and coverage.b0f9412to93f6ac6: unpacked −5,610 B, download −2,370 B.1aa0069, host-only MP4 validation at41f82c7, 24 passing checks atb0f9412.93f6ac6.swiftc -typecheckof the stripped helpers passed on macOS.🤖 Generated with Claude Code