Repository navigation
fix(dashboard): make the skill-bundle link defence see a Windows junction - #9059
bolichen97 merged 1 commit into
Conversation
…tion `_write_bundle`'s leaf-link defence removes a pre-planted link at the skill dir so the containment checks below cannot be resolved against its target. It tests `skill_dir.is_symlink()`, which is False for a Windows junction — and a junction is the shape that matters there, because a *directory* symlink on Windows needs `SeCreateSymbolicLinkPrivilege` while a junction needs none. With the defence inert, the very next line is `shutil.rmtree(skill_dir)`, and `rmtree` refuses a junction exactly as it refuses a symlink. `_write_bundle` runs under `await asyncio.to_thread(...)` with no `except` in scope, so the `OSError` leaves the handler uncaught. Measured: the install request answers **500 Internal Server Error** with `OSError: Cannot call rmtree on a symbolic link`. Routed through `platform_compat.is_link_or_junction` / `unlink_link_or_junction`, the repo's canonical pair for this. The unlink half matters as much as the predicate: a junction is a directory reparse point detached with `rmdir`, so the target's contents survive exactly as a symlink's do under `unlink` — a plain `rmtree` here would delete through it. Containment itself was never breached: `skill_dir.resolve()` follows a junction and the `relative_to(skills_root)` check below refuses. This restores the defence-in-depth layer above it, and stops the refusal surfacing as a 500. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Root-cause fix routed through the repo's canonical [DESIGN-REVIEWED] 59ca6c7 |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed Review detailsThe diff is a narrow, correct widening of an existing leaf-link defense from symlink-only to symlink-or-junction. Let me confirm the helpers behave correctly on POSIX and that the caller can't hit the unsafe else branch. The verification confirms:
The candidate list found nothing, and my own falsification pass re-derived no grounded defect: the change strictly widens containment, the removal path preserves link targets, and the containment/traversal guards downstream are unchanged. Nothing meets (a)+(b)+(c) at 80+. No findings. [OPUS-REVIEWED] 59ca6c7 |
First Principles Review (Fable 5, fork) — 🟡 CONCERNSPremise-level review of All claims verified against the base tree. The First-Principles-Verdict: CONCERNS The fix is cause-level and reuses the canonical pair, but it is a point patch: 5 counted siblings of the same guard-above-rmtree pattern stay broken. What this change shipsIntent: make a dashboard skill-bundle install recoverable when the skill dir is a pre-planted Windows junction (today: 409 → retry with overwrite → unhandled 500, no way forward). This is a FIX.
No new config key, flag, export, or schema property; the change consumes the existing Watch
[FIRST-PRINCIPLES-REVIEWED] 59ca6c7 |
bolichen97
left a comment
There was a problem hiding this comment.
Tech Lead review — approved.
Correct helper. AGENTS.md's cross-platform table names is_link_or_junction / unlink_link_or_junction as the canonical pair and lists path.is_symlink() as the wrong spelling ("misses a Windows junction"). This routes the guard through exactly that pair. The unlink half is the part that matters: unlink_link_or_junction detaches a junction with rmdir, so the target's contents survive — verified in platform_compat.py, and asserted by test_the_junctions_target_survives_being_replaced. Reaching for rmtree after detection would have deleted through the link; the PR explicitly avoids that.
Scope is the whole of this link-defence path. The only other is_symlink in _write_bundle is the per-file file_path.parent.is_symlink() guard, and leaving it is right: the file_path.resolve().relative_to(resolved_root) check immediately above already resolves the full parent chain (junctions included), and the guard's failure action is continue, not rmtree — so a junction there cannot produce the uncaught OSError this PR fixes. Swapping it would be a no-behaviour churn. Within this defence path, this was the last site with a real behavioural gap.
Consistent with #8873 (same author, same defect class, merged): same remedy shape — route the predicate through platform_compat, add an endpoint-level test using a real junction via conftest.make_dir_link.
Severity graded honestly in the description — a dead defence-in-depth layer plus an unrecoverable 409→overwrite→500 loop, not a containment escape, since resolve() + relative_to(skills_root) still holds. I confirmed that reading.
Signals. 66 check-runs, 61 success / 5 skipped, 0 failures; Windows backend shards ran, so the junction tests execute on the platform the blind spot lives on. GPT 5.6 and Opus 4.8: no blocking findings. Design Review: PASS. First Principles: CONCERNS (advisory) for 5 counted siblings of the guard-above-rmtree pattern in other modules — correctly out of scope here and declared in the Pattern harvest section; pod/provision.py:229 is the one with the identical uncaught-OSError shape and is worth a follow-up. readiness: passed applied 17:02Z, after the single commit (16:19Z) and all review lanes. The one Focus Cue Gate annotation is a pre-existing notice, not from this diff.
…tion (kirodotdev#9059) `_write_bundle`'s leaf-link defence removes a pre-planted link at the skill dir so the containment checks below cannot be resolved against its target. It tests `skill_dir.is_symlink()`, which is False for a Windows junction — and a junction is the shape that matters there, because a *directory* symlink on Windows needs `SeCreateSymbolicLinkPrivilege` while a junction needs none. With the defence inert, the very next line is `shutil.rmtree(skill_dir)`, and `rmtree` refuses a junction exactly as it refuses a symlink. `_write_bundle` runs under `await asyncio.to_thread(...)` with no `except` in scope, so the `OSError` leaves the handler uncaught. Measured: the install request answers **500 Internal Server Error** with `OSError: Cannot call rmtree on a symbolic link`. Routed through `platform_compat.is_link_or_junction` / `unlink_link_or_junction`, the repo's canonical pair for this. The unlink half matters as much as the predicate: a junction is a directory reparse point detached with `rmdir`, so the target's contents survive exactly as a symlink's do under `unlink` — a plain `rmtree` here would delete through it. Containment itself was never breached: `skill_dir.resolve()` follows a junction and the `relative_to(skills_root)` check below refuses. This restores the defence-in-depth layer above it, and stops the refusal surfacing as a 500. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Problem / Motivation
_write_bundleindashboard/handlers/discover.py(the skill-bundle install path)opens with a deliberate leaf-link defence, and its comment states the reason:
is_symlink()is False for a Windows junction — and the junction is preciselythe shape that matters here, because a directory symlink on Windows needs
SeCreateSymbolicLinkPrivilegewhile a junction needs none. So the shape anunprivileged process can actually plant is the one the defence does not see.
With the defence inert, the very next line runs:
shutil.rmtreetreats a junction as a link exactly as it treats a symlink(
_rmtree_islinkmatchesIO_REPARSE_TAG_MOUNT_POINTon Windows) and raises._write_bundleruns underawait asyncio.to_thread(_write_bundle)with noexceptin scope, so theOSErrorleaves the handler uncaught.Measured against unpatched
origin/main, driving the realPOST /api/skills/-/discover/installendpoint with a real_winapi.CreateJunctionjunction:Why it matters
Graded honestly: this is a dead defence-in-depth layer plus a 500, NOT a
containment escape. The layer below still holds —
skill_dir.resolve()followsthe junction and the
relative_to(skills_root)check refuses — so nothing iswritten outside the skills root either way. That is stated up front so the
severity is not read as higher than it is.
What is actually broken is that the install becomes unrecoverable through the
UI. Without
overwritethe request answers409 exists(the junction makesskill_dir.exists()true), and the documented way out of a 409 is to retry withoverwrite: true— which is the branch that 500s. A user who lands on a junctionedskill dir has no path forward from the dashboard, and the response they get is an
unhandled server error rather than anything actionable.
What changed (motivation → approach → change)
Symptom: a junctioned skill dir makes bundle install answer 500.
Root cause: the leaf-link defence asks
is_symlink(), which does not report ajunction, so the link is never removed and the
rmtreebelow inherits it.Change: route the defence through the repo's canonical pair.
The unlink half matters as much as the predicate. The obvious "fix" — reaching
for
shutil.rmtreeonce the junction is detected — would delete through it.unlink_link_or_junctiondetaches a junction withrmdir, which removes thereparse point and leaves the target's contents alone, exactly as
unlinkleaves asymlink's. Both properties are asserted.
Scope kept to that one guard. The per-file
file_path.parent.is_symlink()checkfurther down is deliberately not touched: the
file_path.resolve().relative_to( resolved_root)check immediately above it already resolves the whole parent chain,junctions included, so that guard is genuinely belt-and-suspenders and changing it
would be a swap with no behaviour behind it.
platform_compatis imported (one line); no other import path grew.Tests
test/test_skill_discover.py, two tests added toTestDiscoverInstall, siblings ofthe existing
test_install_overwrite_replaces_symlinked_skill_dir:test_install_overwrite_replaces_junctioned_skill_dirtest_the_junctions_target_survives_being_replacedThe links use
conftest.make_dir_link, which yields a real junction on Windows, sothe platform the blind spot lives on is exercised rather than skipped.
Guard-the-guard. Each test asserts the planted shape through an oracle before
asserting anything about the handler:
platform_compat.is_link_or_junction(link)istrue, and
link.exists()is true (if it were not followable,rmtreewould neverrun and the test would pass for the wrong reason).
The second test's property is distinct from the first's on purpose: the first proves
nothing was written outside the root, the second proves nothing was deleted
outside it.
Red-before, measured on unpatched
origin/main:2 failed, bothassert 500 == 200, withOSError: Cannot call rmtree on a symbolic linkin thecaptured server log. After the fix:
test_skill_discover.pyis 21 passed, 1skipped, and the sibling
test_discover_handlers_cov80.pyis 35 passed.Gates on this head:
flake8clean,isort --check-onlyclean,mypy --platform linuxreports nothing indiscover.py, black and subprocess-encoding gates bothpass scoped
origin/main...HEAD(2 files). Both touched files are in.github/black-baseline.txtand were deliberately not reformatted.Manual verification
N/A — unit coverage sufficient: the tests drive the real HTTP endpoint through
aiohttp's test client against a real junction on the affected platform, which isthe same path the dashboard uses.
Related Issues
None — found by inspection while auditing
is_symlink-based defences for theWindows junction blind spot, the same family as #7881.
Pattern harvest
Rule candidate:
semgrepPattern:
is_symlink()/os.path.islink()used as a link defence immediatelyabove a
shutil.rmtree— on Windows the predicate misses a junction whilermtreestill refuses one, so the guard silently stops guarding and the refusal it was meant
to prevent surfaces as an unhandled
OSError. The pairplatform_compat.is_link_or_junction/unlink_link_or_junctionalready exists forexactly this; a grep for
islink/is_symlinkwithin a few lines ofrmtreefindsthe remaining sites.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code