Repository navigation
fix(sandbox): refuse an aliased masked leaf at one pass, not only two of them - #12579
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Description claims an import-time partition assert ("RED at import"); HEAD pins the partition with a test instead — correct the stale mechanism claim before merge. [DESIGN-REVIEWED] 8e63b9e |
GPT 5.6 Review — ✅ human override acceptedHuman judgment by @chenmingwei23 overrides the GPT 5.6 finding for This comment is updated in place on each push. The model was not re-run because an authorized human decision supersedes it. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify on a real host that no supported layout symlinks a newly-refused leaf (e.g. What this change shipsInventory (10 items) — 10 justifiedIntent: FIX — make a symlinked masked crew-home leaf refuse the spawn instead of silently binding the mask over the link's target (linked issue; enforces the HIDDEN disposition
Duplication checked: [FIRST-PRINCIPLES-REVIEWED] 8e63b9e |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsNo findings. The sole candidate — a degrade-leaf spawn refusal when an md-notebook intermediate component is unreadable — does not clear the falsification bar. Its trigger is "if the agent strips search permission from an owned directory," an adversarial if-a-caller-were-to input the candidate itself admits has no non-adversarial construction. The outcome ( [OPUS-REVIEWED] 8e63b9e Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
… of them A masked crew-home leaf that nothing materialises reached no alias check at all. The sealing loop only warns, and the maskable-dir refusal covers the nine leaves it precreates, so `ledger`, `routing`, `webhooks`, `ledgers` and every other unmaterialised masked leaf could be a symlink: `isdir` follows it, the bind-mask attaches to the target, and the leaf's own name stays writable in the data home for a sandboxed process to unlink and replace. `_refuse_aliased_masked_leaves` closes that at one pass over every masked leaf. It creates nothing, so an absent store is skipped rather than materialised -- which is what the retired `ledgers` root requires, its own entry saying that precreating it would re-materialise a retired name on every machine. The set is derived from `_CREW_HIDDEN_LEAVES`, so a leaf added later inherits the refusal instead of needing a reviewer to notice it was left out. Two exceptions are deliberate and each has a test asserting it is NOT refused: `.env`, the operator's hand-authored channel-credential file and the clearest dotfile-manager case in the list; and the extra-hardlink shape for every leaf, because a hardlink does not make the masked name replaceable while hardlinking snapshot tools leave one on hosts whose backups work. `scratch` and `backup` read like relocation candidates and refuse: each resolves to one managed path with no override, so a second name is not a layout the product offers. The pass runs last on the spawn path so a leaf carrying its own tailored refusal answers first and keeps its own sentence -- `live_target.json` shares its wording with `kirocrew doctor`, and the md-notebook leaves name their own documents. Prose that claimed the refusal covered only two leaves is corrected in `docs/system-specs/modules/security.md`, `agent_panel.py` and the test docstring. Refs #12171
7db97f3 to
23502dc
Compare
|
Dispositions for the verdicts on First Principles BLOCK: the
|
GPT 5.6 Review — 🔴 changes requested (blocking)GPT 5.6 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/sandbox.py:1727 -- Permitted aliases and non-atomic preflight leave masked paths exposed BLOCKING -- src/kiro_crew/sandbox.py:2457 -- Filesystem errors are treated as absence [BLOCK-MERGE] 23502dc Adjudication (Opus 4.8) — is blocking on each finding proportionate?Both fenced findings concern unbounded-harm (credential/protected-state) exposure via the alias/preflight checks in F1 (sandbox.py:1727) — Harm: UNBOUNDED (credential substitution/exposure). Conditions confirmed: F2 (sandbox.py:2457) — Harm: UNBOUNDED (access to masked protected app data). Conditions confirmed: False positive or not applicable? A repository writer can comment: |
23502dc to
ea47f7a
Compare
|
Dispositions for the two blocking findings on F2 (
|
ea47f7a to
9d71128
Compare
9d71128 to
8e63b9e
Compare
Disposition at head
|
Head
|
Field verification for First Principles' watch item, measured rather than arguedRaised at the first head and again at Method: import Population: 46 masked leaves, 1 tolerated ( Result across 9 data homes, 405 leaf-by-home pairs, 127 leaves actually present:
So on this host the pass refuses nothing that exists today. The premise holds here, and the What this does NOT establish, stated plainlyThis is one host, not a survey, and it is not a dotfile-managed host: It also cannot speak for a host that keeps Pattern harvestRule candidate: when a reviewer asks for field verification, do not answer it with a source grep. |
The GPT lane re-sampled itself at this same sha and disagreed with itselfNo code changed between the two samples. The head is
The two adjudications reverse on the same premise, using the same source comment. Sample 1 read the I am recording this rather than pushing against it, because it decides the strategy. Findings that One of the two findings is already satisfied for the case it namesF2 asks to "Refuse symlinks and extra hardlinks for credential-bearing masked files", and names
So on this branch a symlinked What genuinely remains from F2 is the hard link shape, which this pass warns about rather than Both residuals now have their own issues, because neither is this PR's scope
Both are pre-existing. Before this PR these leaves had no alias check at all, so neither shape Where this leaves the PRDesign Review PASS, First Principles PASS, Opus 4.8 no findings, every CI lane green or skipped, The remaining blocker is two fenced security-class findings that were withheld from adjudication, so Pattern harvestRule candidate: before treating a fenced finding as a converging signal, sample it twice at the same |
|
/ai-review override gpt 8e63b9e: Circular re-sampling: this same SHA gave 1 then 2 findings, FLAG then UPHOLD-FENCED, the adjudicator reversing on its own premise at sandbox.py:1712-1716. Test applied: the actor must already hold the stronger capability, since planting the hardlink needs read access to the secret, and the mount race needs a concurrent writer to win a narrow window. AGENTS.md:146 forbids the demanded widening. Both residuals are pre-existing and fully tracked in #12641 and #12642. |
Human judgment recorded@chenmingwei23 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed the full diff and independently checked the /ai-review override gpt on this head by reading both GPT samples out of the workflow run logs rather than the summary. The override is legitimate: neither residual is a regression from this diff. On main .env sits in _CREW_HIDDEN_LEAVES but in no precreate/sealable list, so it reached no alias check at all; this PR moves it to visited-and-warned. The hardlink read path and the lstat-then-mount window are the same warn-and-continue shape _materialize_sealable_ceilings already carries on main, and both are tracked in #12641 and #12642. AGENTS.md:146-152 forbids the widening the lane demanded. Design, First Principles and Opus all PASS; tests call _refuse_aliased_masked_leaves directly against real symlinks and go red on revert.
… of them (kirodotdev#12579) * fix(sandbox): refuse an aliased masked leaf at one pass, not only two of them A masked crew-home leaf that nothing materialises reached no alias check at all. The sealing loop only warns, and the maskable-dir refusal covers the nine leaves it precreates, so `ledger`, `routing`, `webhooks`, `ledgers` and every other unmaterialised masked leaf could be a symlink: `isdir` follows it, the bind-mask attaches to the target, and the leaf's own name stays writable in the data home for a sandboxed process to unlink and replace. `_refuse_aliased_masked_leaves` closes that at one pass over every masked leaf. It creates nothing, so an absent store is skipped rather than materialised -- which is what the retired `ledgers` root requires, its own entry saying that precreating it would re-materialise a retired name on every machine. The set is derived from `_CREW_HIDDEN_LEAVES`, so a leaf added later inherits the refusal instead of needing a reviewer to notice it was left out. Two exceptions are deliberate and each has a test asserting it is NOT refused: `.env`, the operator's hand-authored channel-credential file and the clearest dotfile-manager case in the list; and the extra-hardlink shape for every leaf, because a hardlink does not make the masked name replaceable while hardlinking snapshot tools leave one on hosts whose backups work. `scratch` and `backup` read like relocation candidates and refuse: each resolves to one managed path with no override, so a second name is not a layout the product offers. The pass runs last on the spawn path so a leaf carrying its own tailored refusal answers first and keeps its own sentence -- `live_target.json` shares its wording with `kirocrew doctor`, and the md-notebook leaves name their own documents. Prose that claimed the refusal covered only two leaves is corrected in `docs/system-specs/modules/security.md`, `agent_panel.py` and the test docstring. Refs kirodotdev#12171 * fix(sandbox): check the leaf's components, fail closed on an unreadable path `os.lstat` un-follows only the FINAL component, so the alias pass still resolved through a link planted at an intermediate component. Multi-component masked leaves genuinely exist -- `apps/aws-control/data`, `apps/meetings/data/edits`, the md-notebook state leaves -- and those intermediates sit inside the agent-writable data home, so a link at one lands the mask on an attacker-chosen tree while the lexical name stays replaceable. The same hole the pass exists to close, one level up. `_first_linked_component_below` walks the components under the data home root-first and stops at the first hit, so each test runs only after every component above it is known not to be a link. The data home itself and its parents are NOT walked: `config_dir()` documents that a symlinked data HOME is a supported layout, and refusing it would break every spawn on such a host. Both stat sites now FAIL CLOSED on an errno other than ENOENT, which is the split the sibling `_refuse_if_symlink_leaf` already makes. A blanket `except OSError` treated "could not judge" as "safe", and the data home is agent-writable: an agent that strips search permission from a directory it owns turns EACCES into a silent skip, and the launcher's own `isdir` guard skips the mask for the same reason, so the child can restore the permission and reach the state unmasked. The ancestor walk had the identical fail-open one level up, because `os.path.islink` answers False when the stat fails, so both are fixed together rather than one per round. ENOENT stays benign, since nearly every leaf is absent on an ordinary host and refusing there would make the pass a blanket outage. A planted link at an intermediate of an md-notebook state leaf DEGRADES rather than refusing, matching `carveout_chain_has_planted_link` instead of overriding it. While that predicate holds the carve-out is withheld and the owning backend cannot write the state, so an unmasked leaf has nothing to expose. The exempt set derives from `_MD_NOTEBOOK_PRECREATE_CONTENT` so the two cannot drift. Tolerated leaves are VISITED and WARNED rather than excluded from the walk. Excluding them implemented the exception as "never looked at", which reproduced on the credential leaf the exact silence this pass exists to end. The extra-hardlink shape is warned here too, since `_warn_if_alias_backed` never runs over these leaves. All warnings fire per spawn, matching that function's own stated reason. `security.md` states the platform scope rather than leaving the refusal unqualified: the pass is called from `namespace_argv`, so it governs the Linux bind-mask path. Thirteen mutations, all killed, including both directions of each stat site: the blanket fail-open restored, and a widened refusal that would have made an absent leaf refuse. Refs kirodotdev#12171
… of them (kirodotdev#12579) * fix(sandbox): refuse an aliased masked leaf at one pass, not only two of them A masked crew-home leaf that nothing materialises reached no alias check at all. The sealing loop only warns, and the maskable-dir refusal covers the nine leaves it precreates, so `ledger`, `routing`, `webhooks`, `ledgers` and every other unmaterialised masked leaf could be a symlink: `isdir` follows it, the bind-mask attaches to the target, and the leaf's own name stays writable in the data home for a sandboxed process to unlink and replace. `_refuse_aliased_masked_leaves` closes that at one pass over every masked leaf. It creates nothing, so an absent store is skipped rather than materialised -- which is what the retired `ledgers` root requires, its own entry saying that precreating it would re-materialise a retired name on every machine. The set is derived from `_CREW_HIDDEN_LEAVES`, so a leaf added later inherits the refusal instead of needing a reviewer to notice it was left out. Two exceptions are deliberate and each has a test asserting it is NOT refused: `.env`, the operator's hand-authored channel-credential file and the clearest dotfile-manager case in the list; and the extra-hardlink shape for every leaf, because a hardlink does not make the masked name replaceable while hardlinking snapshot tools leave one on hosts whose backups work. `scratch` and `backup` read like relocation candidates and refuse: each resolves to one managed path with no override, so a second name is not a layout the product offers. The pass runs last on the spawn path so a leaf carrying its own tailored refusal answers first and keeps its own sentence -- `live_target.json` shares its wording with `kirocrew doctor`, and the md-notebook leaves name their own documents. Prose that claimed the refusal covered only two leaves is corrected in `docs/system-specs/modules/security.md`, `agent_panel.py` and the test docstring. Refs kirodotdev#12171 * fix(sandbox): check the leaf's components, fail closed on an unreadable path `os.lstat` un-follows only the FINAL component, so the alias pass still resolved through a link planted at an intermediate component. Multi-component masked leaves genuinely exist -- `apps/aws-control/data`, `apps/meetings/data/edits`, the md-notebook state leaves -- and those intermediates sit inside the agent-writable data home, so a link at one lands the mask on an attacker-chosen tree while the lexical name stays replaceable. The same hole the pass exists to close, one level up. `_first_linked_component_below` walks the components under the data home root-first and stops at the first hit, so each test runs only after every component above it is known not to be a link. The data home itself and its parents are NOT walked: `config_dir()` documents that a symlinked data HOME is a supported layout, and refusing it would break every spawn on such a host. Both stat sites now FAIL CLOSED on an errno other than ENOENT, which is the split the sibling `_refuse_if_symlink_leaf` already makes. A blanket `except OSError` treated "could not judge" as "safe", and the data home is agent-writable: an agent that strips search permission from a directory it owns turns EACCES into a silent skip, and the launcher's own `isdir` guard skips the mask for the same reason, so the child can restore the permission and reach the state unmasked. The ancestor walk had the identical fail-open one level up, because `os.path.islink` answers False when the stat fails, so both are fixed together rather than one per round. ENOENT stays benign, since nearly every leaf is absent on an ordinary host and refusing there would make the pass a blanket outage. A planted link at an intermediate of an md-notebook state leaf DEGRADES rather than refusing, matching `carveout_chain_has_planted_link` instead of overriding it. While that predicate holds the carve-out is withheld and the owning backend cannot write the state, so an unmasked leaf has nothing to expose. The exempt set derives from `_MD_NOTEBOOK_PRECREATE_CONTENT` so the two cannot drift. Tolerated leaves are VISITED and WARNED rather than excluded from the walk. Excluding them implemented the exception as "never looked at", which reproduced on the credential leaf the exact silence this pass exists to end. The extra-hardlink shape is warned here too, since `_warn_if_alias_backed` never runs over these leaves. All warnings fire per spawn, matching that function's own stated reason. `security.md` states the platform scope rather than leaving the refusal unqualified: the pass is called from `namespace_argv`, so it governs the Linux bind-mask path. Thirteen mutations, all killed, including both directions of each stat site: the blanket fail-open restored, and a widened refusal that would have made an absent leaf refuse. Refs kirodotdev#12171
What is the problem?
A masked crew-home leaf that nothing materialises reached no alias check at all.
sandbox.pyhas two pre-spawn passes over crew-home leaves, and both run on every Linuxspawn from
namespace_argv:_materialize_sealable_ceilings_CREW_NO_ALIAS_LEAVES_materialize_maskable_dirs_CREW_PRECREATE_HIDDEN_DIR_LEAVES_refuse_if_symlink_leaf_CREW_HIDDEN_LEAVESholds 46 entries. Nine of them are precreated, so the second passalready refuses an aliased name for those. The remaining 37 are reached by neither pass:
ledger,ledgers,routing,webhooks,work-ledger,scratch,backup,inbound-spool,tasks,kas,cron-history,cron-running,mcp-apps,workflow_library, the auth store and its sidecars, and the rest.For those, a symlinked leaf is silently accepted.
os.path.isdirfollows the link, so theisdir-guarded mask loop binds over the link's target while the leaf's own name staysin the writable data home. A sandboxed process unlinks that name, drops its own directory
or file there, and everything the gateway later reads through the masked path is bytes the
sandbox controls.
This corrects the mechanism recorded in the issue on two points, both measured:
crew-logas an unprotected sibling.crew-logis precreated, so_materialize_maskable_dirsalready refuses a link at that name. The sealing loop'swarning fires first, but the spawn is refused three lines later, so there was no hole
there.
_warn_if_alias_backedinstead". For the four itnames, they get neither the refusal nor the warning, because neither pass reaches a leaf
nothing materialises.
Why this issue matters to the user
The masked leaves hold the records a reader trusts instead of re-deriving, and the
credentials the gateway holds on the operator's behalf: conductor work-ledger items, the
cross-session
ledger, channel routing, webhook registrations, the refused-inbound spoolwhose entries are re-posted verbatim as gateway-authored messages, the identity store whose
bytes are a live bearer token. The mask is the only fence that answers a spawned
subprocess calling
open(); the library write rules bind only callers who go through thelibrary, and the file-tool gate answers only the agent's own tools.
An operator reading the module reasonably concludes the crew home refuses an aliased
protected leaf, because that is what the existing helper is named for. For most of the
masked list that was not true, and the failure was silent by construction: nothing logged,
nothing refused, and the mask reporting itself established while attached to somewhere
else.
How our fix solves it
_refuse_aliased_masked_leavesadds one pass, at one call site, over every masked leaf.Chaining from the symptom to the root cause: the symptom is a mask attached to a path the
leaf name does not denote. The mechanism is that
mount(2)binds what a path resolves to,so any disposition expressed as a path is voided by a link at that path. The root cause is
that the alias decision was attached to the materialisation lists rather than to the
masked population itself, so a leaf became covered only as a side effect of needing a mount
target. Moving the decision onto the masked population is what makes coverage follow from
being masked.
It checks the leaf and every component below the data home.
lstatun-follows only thefinal component, so a leaf-only check still resolves through a link planted at an
intermediate component, and multi-component masked leaves genuinely exist
(
apps/aws-control/data,apps/meetings/data/edits, the md-notebook state leaves). Thoseintermediates sit inside the agent-writable data home, so a link at one of them lands the
mask on an attacker-chosen tree while the lexical name stays replaceable. Components are
walked root-first and the walk stops at the first hit, so each test runs only after every
component above it is known not to be a link. The data home itself and its parents are
deliberately not walked, because
config_dir()documents that a symlinked data HOME isa supported layout.
Three properties make one pass correct where the issue's proposed approach needed a
precreate step per leaf:
is what the retired
ledgersroot requires, and its own entry in_CREW_HIDDEN_LEAVESsays so: "Precreating it would re-materialise the retired name on every machine." A
refusal only needs to fire on a path that exists, so precreate was never a prerequisite.
_CREW_HIDDEN_LEAVESminus an exception set, so a leaf addedlater inherits the refusal instead of needing a reviewer to notice it was left out. A
test pins that the two buckets partition the masked list.
tailored refusal answers first and keeps its own sentence.
live_target.jsonshares itswording with
kirocrew doctorand is pinned by a test that compares the two verbatim;the md-notebook state leaves name their own documents.
Three cases are deliberately not refused, and each has a test asserting so:
.envstays tolerated. It is the operator's own hand-authored channel-credentialfile, documented as such, and it is the clearest member of the class the warn path exists
for: a dotfile manager symlinks exactly this file, so refusing it would fail every agent
spawn on an ordinary host.
name replaceable, and hardlinking snapshot tools leave one behind on hosts whose backups
are working correctly. The warning is emitted by this pass rather than left to
_warn_if_alias_backed, which never runs over these leaves: without it the alias wouldsit outside the mask with nothing said about it, which is the silent-by-construction
property the pass exists to end.
refusing, matching
carveout_chain_has_planted_linkrather than overriding it. While thatpredicate holds, the carve-out is withheld and the owning backend cannot write that state,
so an unmasked leaf has nothing to expose; refusing would let one optional app's on-disk
layout stop every sandboxed spawn on the host. The exempt set is derived from
_MD_NOTEBOOK_PRECREATE_CONTENTso the two cannot drift.scratchandbackupread like relocation candidates and were checked against thatstandard rather than assumed. Neither is a supported second name:
agent_scratch.scratch_root()isconfig_dir() / "scratch", no resolver in the tree readsan override for either, and no document tells an operator to relocate one. Both refuse, and
the reasoning is recorded beside the exception set.
Scope. The pass is called from
namespace_argv, so it governs the Linux bind-mask path.macOS fences the same leaves through Seatbelt subpath denies, which are path rules rather
than mounts and hold for a name that does not exist yet, so whether a symlinked leaf there
resolves outside the denied subpath is a separate question this change does not answer. The
security.mdparagraph states that scope rather than leaving the refusalplatform-unqualified.
Prose that claimed the refusal covered only the two panel leaves is corrected in
docs/system-specs/modules/security.md, inagent_panel.py, and in the test docstringthat said "unlike every other ceiling".
What tests we did
test/test_sandbox_absent_ceiling_seal.py, run with-n0: 180 passed.Twelve affected files, chosen by what the change reaches rather than by what it edits
(anything driving
namespace_argv, reading a set this change touches, or symlinking amasked leaf), all green: 1662 tests, zero failures. Files covered include
test_sandbox_argv.py(218),test_sandbox_governance_mask.py(618),test_sandbox_md_notebook_carveout.py(47),test_sandbox_dev_fleet_live_target.py(41),test_agent_panel_store.py(90),test_crew_log_core.py(204),test_inbound_spool.py(72) and
test_appearance_library.py(130).New coverage:
per leaf asserting nothing was written through the link;
be a blanket outage;
_CREW_HIDDEN_LEAVES,must not overlap, and a leaf in neither is a failure;
reported;
Every new test was mutation-verified. Twelve mutations, all killed:
.envloses its exceptionOne is listed with a caveat. The reason mutation passed on its first form because the test
searched the whole module and matched a doc line belonging to an earlier set, so it now reads
only the doc block directly above the exception set and reds when a leaf is tolerated without a
stated reason.
The partition invariant was an import-time
assertin an earlier revision. First Principlesobserved that the derived tuple had no runtime consumer, so both module asserts were removed and
the partition is now
test_the_tolerated_set_names_only_masked_leaves. That is stricter, notlooser:
python -Ostrips anassert, so the invariant previously held only in unoptimisedbuilds. Mutation-verified in its test form, baseline exit 0 and a tolerated entry naming a
non-masked leaf exit 1.
Gates:
black --check,isort --check-only,flake8,mypyon the changed files, and therepo's own
check_black_formatting.py,docs_lint.py,check_sync_io_in_async.py,check_loop_bound_locks.py,check_subprocess_encoding.py,check_brand_name.py,check_comment_history.py,check_feature_map.py,check_testpaths_coverage.py-- allexit 0. The diff-scoped gates were re-run after committing, because before that they
reported "0 changed file(s)" and were non-discriminating.
Three CI shard reds on the first head are not from this diff, and neither file is in it:
test_apps_doc_catalogue.py::test_the_agents_bullet_names_every_app_and_its_count(3.12shard 8 and Windows shard 8) and
test_runtime_cleanup_windows.py::test_windows_failed_tree_kill_keeps_live_pid_records(Windows shard 7). The Coverage Gate red is its own cascade: its first step is "Require
upstream coverage jobs to have succeeded" and every later step is skipped, so it is
unmeasured rather than failing on content.
Pattern harvest
Rule candidate: agents-md
Pattern: a disposition expressed as a PATH (a mask, a seal, a precreate) is voided by a
link anywhere in that path, so the check must cover the leaf AND every component below the
owned root --
lstatun-follows only the final component. The generalizable half is theplacement rule rather than the syntax: when a decision is attached to a
materialisation list, coverage becomes a side effect of needing a mount target, and every
member that does not need one is silently exempt. Attach it to the population the
disposition is about, derive the member list from that population, and pin the partition so
a member added later inherits a decision instead of inheriting silence. This PR is the
second instance of the same shape in this module:
_CREW_NO_ALIAS_LEAVESwas itself thefirst, scoped to two leaves because those were the two being precreated at the time.
Any other suggestions on the work
The issue's closing suggestion, that
_warn_if_alias_backedmay deserve a level thatsurfaces independently of which leaves refuse, is untouched here. It is a change to what
the warning does for the sealed ceilings, which is a different population from the one this
PR moves, and worth deciding on its own.
One stale name spotted and deliberately left: the existing
test_an_absent_ledgers_root_is_materialized_before_the_mask_bindsassertscrew-log, notledgers-- a leftover from the rename. Renaming a test is not this PR's business.Closes #12171