Repository navigation
fix: make the remaining is_symlink() guards see Windows junctions - #11136
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Confirm the Windows CI shard runs the new real-shape tests green — the mutation check quoted was POSIX-only, so Windows behavior rests on that shard. [DESIGN-REVIEWED] b04b770 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Confirm the real-shape tests actually go red-on-base on a Windows shard — the author's mutation check ran only on a POSIX host. What this change shipsInventory (9 items) — 9 justifiedIntent: FIX — close #10737, the deferred audit making the remaining
Evidence checked: [FIRST-PRINCIPLES-REVIEWED] b04b770 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsThe PR uniformly widens No findings. [OPUS-REVIEWED] b04b770 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
463b66b to
b56a010
Compare
Audit of the is_symlink()-based link guards that PR #9062's First Principles Review lane deferred (issue #10737). A directory junction -- the shape platform_compat.symlink_or_junction and any unelevated Windows writer produce -- answers False to is_symlink(), and when dangling also to exists()/is_file()/is_dir(), so each of these guards was blind to exactly the link that can occur on Windows. Converted (junction-aware oracle, one pinning test per site built with the product's own link helper plus a simulated-junction test so POSIX shards pin it too): - seed.py dangling-$KIROCREW_HOME guard: now pinned_fs.is_reparse_point, the oracle the sibling guardrails in the same function already use. A dangling junction fell through every exists()-gated guard into the raw copytree FileExistsError the guard exists to prevent. - deploy/__init__.py link migration: is_link_or_junction / unlink_link_or_junction. <home>/skills/<name> is also published by apps/bridges.py through symlink_or_junction, so a live junction reached the exists() branch where rmtree_force refused it and gateway startup aborted; a dangling one crashed copytree. - pod/runtime.py orphan_homes, cleanup_home (pre- and post-check), _rmtree_bounded, write_pod_config: is_link_or_junction. On unelevated Windows a junction is the only link a same-user writer can plant under pod_root, so the planted alias was listed as an orphan, resolved to its live sibling, passed containment, and its refusal was reported as "something is still writing there" after the full retry window. Annotated, not converted: stop_pod's systemd drop-in check is Linux-only. Semgrep rule proposed in #9062 (symlink_or_junction writer + is_symlink reader in one module): evaluated and declined -- the writer and reader live in different modules at every site in this audit (bridges.py vs deploy, frontend.py vs pod/provision.py, or no product writer at all), so the rule would have matched none of them, while a module-agnostic is_symlink() rule would need a 166-site allowlist. Closes #10737
b56a010 to
b04b770
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
Approved after a full read of the diff on the current head: the change matches the linked issue and body, every load-bearing claim was spot-checked against main, tests pin the behaviour, all review lanes are clean and nothing is left undisposed on this head.
…rodotdev#11136) Audit of the is_symlink()-based link guards that PR kirodotdev#9062's First Principles Review lane deferred (issue kirodotdev#10737). A directory junction -- the shape platform_compat.symlink_or_junction and any unelevated Windows writer produce -- answers False to is_symlink(), and when dangling also to exists()/is_file()/is_dir(), so each of these guards was blind to exactly the link that can occur on Windows. Converted (junction-aware oracle, one pinning test per site built with the product's own link helper plus a simulated-junction test so POSIX shards pin it too): - seed.py dangling-$KIROCREW_HOME guard: now pinned_fs.is_reparse_point, the oracle the sibling guardrails in the same function already use. A dangling junction fell through every exists()-gated guard into the raw copytree FileExistsError the guard exists to prevent. - deploy/__init__.py link migration: is_link_or_junction / unlink_link_or_junction. <home>/skills/<name> is also published by apps/bridges.py through symlink_or_junction, so a live junction reached the exists() branch where rmtree_force refused it and gateway startup aborted; a dangling one crashed copytree. - pod/runtime.py orphan_homes, cleanup_home (pre- and post-check), _rmtree_bounded, write_pod_config: is_link_or_junction. On unelevated Windows a junction is the only link a same-user writer can plant under pod_root, so the planted alias was listed as an orphan, resolved to its live sibling, passed containment, and its refusal was reported as "something is still writing there" after the full retry window. Annotated, not converted: stop_pod's systemd drop-in check is Linux-only. Semgrep rule proposed in kirodotdev#9062 (symlink_or_junction writer + is_symlink reader in one module): evaluated and declined -- the writer and reader live in different modules at every site in this audit (bridges.py vs deploy, frontend.py vs pod/provision.py, or no product writer at all), so the rule would have matched none of them, while a module-agnostic is_symlink() rule would need a 166-site allowlist. Closes kirodotdev#10737
) (#15310) A Windows directory JUNCTION is a reparse point that Path.is_symlink() and os.path.islink() both answer False for while is_dir() answers True, and it is the only directory link an unprivileged Windows writer can plant. Four link guards still tested is_symlink() (or a bare is_dir()), so each failed OPEN for a junction while reading green on POSIX, where the same plant is a symlink the old predicate catches. All four move to platform_compat.is_link_or_junction, the repository's mandated predicate. - portability.apply_import_zip: the replace-mode skills/auto strip guarded shutil.rmtree with a bare is_dir(), so a junction planted at skills/auto in the extraction tree aimed the delete OUTSIDE the archive. The LINK is now unlinked with unlink_link_or_junction (never its target); only a real directory reaches rmtree. - connections.mint._is_reapable_spec: a junction at a mint-spec name was read as our own spec and unlinked, removing a directory link into a target this module does not own. - connections.warm._warm_spec_is_foreign: a junction at a warm-spec name read as a free path (is_symlink() and, when dangling, exists() both False), so the writer replaced it and the sweep unlinked it. - mcp_gateway.spill cleanup_old_spill_files / maybe_spill_response: a junction at the spill dir was followed, so the sweep deleted 24h-old files under its target (confused-deputy delete outside the data home). Tests stage a real junction through conftest.make_dir_link (a junction on Windows, a directory symlink on POSIX) and assert the guard refuses it without touching the link's target, matching #11136 / #14327. The four now match test_link_screen_hold_pin's discovery condition (is_link_or_junction screen + a by-name resolve), so link_screen_sites.py is regenerated. All four are the NO-HOLD kind: each refuses every link and never traverses one. The issue's fourth named site -- the deploy staging walk -- already carries the fix on main (#14327, _stage_tree_safe), so it is not re-touched here. Fixes #12379 Fixes #10492 Co-authored-by: kirocrew-agent <agent@kirocrew.local>
What
Audit of the
is_symlink()-based link guards that PR #9062's First Principles Review lane deferred to #10737:seed.py,deploy/__init__.py, andpod/runtime.py. Every guard that can meet a Windows directory junction now uses a junction-aware oracle; the one site that cannot is annotated so the next audit does not re-count it.Why
A directory junction is what
platform_compat.symlink_or_junction(and any unelevated Windows writer) produces, because a directory symlink there needsSeCreateSymbolicLinkPrivilege. A junction answers False tois_symlink(), and when dangling also toexists()/is_file()/is_dir(). So each guard below was blind to exactly the link shape that can occur on Windows:seed.pydangling-$KIROCREW_HOMEguardsymlink_or_junction/ any Windows writer publishing the homeexists()-gated guard into the rawcopytreeFileExistsErrorthe guard exists to preventdeploy/__init__.pylink migrationapps/bridges.pypublishes<home>/skills/<name>viasymlink_or_junction; a deploy skill shares that namespaceexists()branch,rmtree_forcerefused it (stdlib rmtree does not descend a junction root), gateway startup aborted with "could not remove"; dangling one crashedcopytreepod/runtime.pyorphan_homespod_root(the guard's own threat model; on unelevated Windows a junction is the only link a same-user writer can plant)pod/runtime.pycleanup_homepre-check,_rmtree_bounded, post-checkpod/runtime.pywrite_pod_configcreate-only guardconfig.jsonAnnotated, not converted:
stop_pod's systemd drop-inis_symlink()is Linux-only; junctions do not exist there.How
seed.py:pinned_fs.is_reparse_point(dst) and not dst.exists()-- the same oracle the sibling populated/empty-link guardrails in that function already use, so one function keeps one oracle. Message now says "dangling symlink or junction"; the guardrail constant is unchanged.deploy/__init__.py:is_link_or_junction(link)->unlink_link_or_junction(link)(removes the link, never its target). Link-first so a dangling entry is still handled.pod/runtime.py: the fiveis_symlink()reads in the orphan / reclaim / config-seed path route throughplatform_compat.is_link_or_junction. Messages say "symlink or junction" / "symbolic link or junction"; existingmatch="symbolic link"/"symlink" in outassertions still hold.Pattern harvest
Not generalizable: as a lint rule -- see the semgrep evaluation below. The reusable pattern is the test recipe (real shape via
symlink_or_junction+ simulated junction via the OS oracle), which this PR applies at every site.Semgrep rule (proposed in #9062's Pattern harvest): evaluated, declined
The proposal was a same-module rule:
symlink_or_junctionwriter +is_symlinkreader in one file. Measured against this audit, the writer and the reader are in different modules at every site:apps/bridges.pywrites,deploy/__init__.pyreads;frontend.pywrites,pod/provision.pyread (#9062);seed.pyandpod/runtime.pyhave no product writer at all (the link is user- or attacker-planted). The rule would have matched 0 of 3 sites here and 1 of 3 in #9062. A module-agnostic "anyis_symlink()/os.path.islink" rule has the recall but not the precision: 166 such calls across 78 modules insrc/kiro_crewtoday (vs 142is_link_or_junctioncalls), most of them legitimate on POSIX-only paths, so it would ship with a 166-entry allowlist that every new POSIX-only guard has to grow. Neither is worth adding; this PR's pinning tests are the guard.Tests
Per converted site, two tests, following the pattern #9062 established:
platform_compat.symlink_or_junction, so each platform exercises what it actually produces: a symlink on POSIX (already handled, passes on base), a junction on an unelevated Windows shard (red on base).platform_compat._ISJUNCTION, orpinned_fs.is_reparse_pointforseed.py) is taught to recognise one real directory / one absent path, while everypathlibpredicate keeps its true answer (is_symlink()False,is_dir()/exists()as a live or dangling junction would answer).is_link_or_junction/unlink_link_or_junctionrun their real logic over it. These tests are red on base on every platform.Mutation check (source reverted, tests kept): 10 failed, 6 passed -- the 10 are the simulated-shape tests plus the message assertions; the 6 are the real-shape tests that on this POSIX host produce a symlink the old guards already handled (they go red only on the Windows shards). Source re-applied: all green.
Ran by path with
-n0on Python 3.12:test/test_seed.py,test/test_readonly_source_skill_install.py,test/test_deploy_round15_fixes.py: 84 passedtest/test_pod.py: 461 passed, 1 skippedtest_deploy_round15_fixes.py::test_symlink_migration_replaces_with_copywas a source-text pin onlink.is_symlink()/link.unlink(); it now pins the junction-aware pair and asserts the old spelling is gone.isort / flake8 / black / mypy clean on the seven changed files.
Other
push_guard.py --require-single-on-baseexit 0..github/black-baseline.txtdropstest/test_deploy_round15_fixes.py: rewriting its pin left the file black-clean, and the baseline is shrink-only (the lint gate requires the graduated entry to be pruned). The quote-style hunks in that file are black's output for that graduation.is_link_or_junctionandis_reparse_pointboth start withos.path.islink, and the junction arms are False off Windows.Closes #10737