Repository navigation
fix(diagnostics): reject a junctioned log dir, not just a symlinked one - #8165
Conversation
`_usable_dir` is the collector's one guard against enumerating THROUGH a linked log directory: `Path.is_dir()` follows the link, and the real files on the other side are not themselves links, so they pass the per-file check and get packaged into the support bundle. It tested `p.is_symlink()`, which does not report a Windows junction — and a junction is the only directory link an unprivileged Windows user can create, since a symlink needs SeCreateSymbolicLinkPrivilege. So the guard was open on exactly the platform where planting one is easiest, and what leaks through is a bundle the user attaches to a public issue. Route it through `platform_compat.is_link_or_junction`, per the AGENTS.md cross-platform table. All three directories this module globs — the kiro-log dirs, macOS DiagnosticReports, and `logs/crash-dumps` — go through this one predicate, so the guard closes at every site at once. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS A real Windows-privilege asymmetry closed at the single funnel all three globbed directories already route through — root cause, right layer, correctly scoped. [DESIGN-REVIEWED] fc048fc |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of All claims verified against the base: the guard is the single funnel for all three globbed directories (diagnostics.py:196, 264, 516), First-Principles-Verdict: PASS A derived one-predicate fix at the single funnel all three globbed directories route through, using the mandated existing helper — nothing rides along. What this change shipsIntent: stop a Windows junction planted at a log directory from leaking its target's files into a support bundle destined for a public issue — a FIX.
No new surface: no config key, flag, or public symbol; WatchSibling count is understated: grepping [FIRST-PRINCIPLES-REVIEWED] fc048fc |
bolichen97
left a comment
There was a problem hiding this comment.
Approving on the strength of a full readiness audit of every open PR against main, not a
line-by-line reading of this diff — recording that plainly so the next reader knows what this
stamp does and does not cover.
Verified against this exact head SHA:
readiness: passedpresent, andPR Readiness— the one required status context onmain
(rulesetprotected-branches) — issuccesson this head.- No check run on this head is
failure,cancelled,timed_outor still in flight. Skipped
jobs are path-filtered conditionals, none of them required. mergeable: true, and the head is not far enough behindmainfor its green CI to describe a
base that no longer exists.- No surviving reviewer
CHANGES_REQUESTED: any such review is on an older commit and therefore
already dismissed bydismiss_stale_reviews_on_push. - Every issue comment, inline review comment and review thread was read and classified. Nothing
left is an unresolved human change request — the remainder is bot review-lane output, resolved
or outdated threads, explicitly non-blocking suggestions, and author status notes.
Auto-merge (squash) is armed, so this lands once every other ruleset requirement is met.
Problem / Motivation
diagnostics._usable_diris the support-bundle collector's one guard againstenumerating through a linked log directory. Its own docstring states the
reason precisely:
The guard is in the right place. Its predicate is not: it tested
p.is_symlink(), which does not report a Windows junction.This is worse than an even trade on Windows, because the two link types are not
equally available to an attacker there. A directory symlink needs
SeCreateSymbolicLinkPrivilege— the repo's own test fixtures document this andskip on it (
requires_symlinks). A junction needs no privilege at all, and isfollowed by the same reparse machinery:
is_dir(),globandresolvealltraverse it identically. So on Windows the only directory link an unprivileged
process can plant is precisely the one the guard did not see.
Why it matters
Everything
_usable_dirprotects is then enumerated and packaged. The threedirectories this module globs all route through it:
_kiro_log_dirs→_usable_dirat the dedup step),DiagnosticReports,<data home>/logs/crash-dumps.A junction planted at any of them makes the collector read the target's files
and write them into
kirocrew-diagnostics-*.zip. That bundle is not a privateartifact: the dashboard flow hands it to the user to attach to a public issue,
and the module already treats this as the threat model it is defending —
_kiro_cli_chat_logrefuses aKIRO_CHAT_LOG_FILEpointing at a sensitive pathwith the comment "would copy plaintext logins into a bundle destined for a
public issue. Redaction is not a backstop for that." A junction reaches the
same outcome without touching that env var.
What changed (motivation → approach → change)
Symptom: a link guard that a Windows junction walks straight past. Root cause:
Path.is_symlink()whereAGENTS.md's cross-platform table names aplatform_compatpredicate —platform_compat)is_link_or_junction(path)/unlink_link_or_junction(path)path.is_symlink()(misses a Windows junction)Change:
_usable_dirreturnsp.is_dir() and not platform_compat.is_link_or_junction(p). One predicate, one line — and becauseevery globbed directory in this module already funnels through this single
function, the gap closes at all three sites at once rather than needing a guard
added per call site.
Deliberately not widened here:
platform_compat.first_linked_ancestorcoversthe neighbouring case where the path itself is a real directory but an
ancestor is a link. That is a different defect with a different blast radius
(an ancestor link to
\\host\shareturns anis_dir()into an authenticatedoutbound SMB connection), it needs its own reasoning about which of the
collector's paths are attacker-influenced, and folding it in would make this
diff a survey rather than a fix. It is named under Pattern harvest instead.
The per-file checks (
_usable_log, the.ipsfilter, the crash-dump filter)are left on
is_symlink(): a file symlink IS reported on Windows, and ajunction is a directory-only reparse point, so there is nothing for the wider
predicate to add there.
Tests
TestUsableDirRejectsEveryDirLinkintest/test_diagnostics.py, three tests:test_a_real_directory_link_is_not_usable— the end-to-end one, and it uses areal link, not a mock:
conftest.make_dir_linkcreates an actual junctionon Windows (
_winapi.CreateJunction) and a real directory symlink on POSIX,so the behaviour is exercised on Windows instead of skipped there. It first
asserts the two facts that make the link dangerous —
link.is_dir()isTrueand
link.glob("*")reaches the target's files — and then that_usable_dirrefuses it. Red on
997d59421with a live junction on Windows 11:AssertionError: assert True is False.test_a_plain_directory_stays_usable— the guard does not reject the ordinarycase it exists to allow (passes before and after; it is what stops the fix
from being "return False").
test_guard_routes_through_the_shared_link_predicate— pins the seam as wellas the behaviour, so this guard cannot drift from the rest of the tree on
which reparse types count as a link. Red on
997d59421.Green:
test_diagnostics.py46 passed, 3 skipped. Directly relevant siblingstest_strict_identity_diagnostics.py+test_portability.py: 61 passed, 3skipped.
blackmeasured against a regenerated control at this PR's own base —both files carry a pre-existing 224-line baseline and this diff adds no new
finding;
flake8,isort,git diff --check, modulemypyand thediff-scoped brand-name gate are clean.
Manual verification
N/A — unit coverage sufficient, and it is not the usual "unit tests are enough"
claim: the Windows leg is verified against a real junction created by
_winapi.CreateJunctionon a Windows 11 host, which is the exact artifact thedefect turns on. A mocked
isjunctionwould have proved nothing about whetheris_dir()andglobactually traverse it.Related Issues
None — found by auditing
AGENTS.md'splatform_compat"use this / NOT that"table against current
main.Pattern harvest
Rule candidate:
semgrepPattern:
path.is_symlink()(oros.path.islink) used as a directory linkguard — the shape is an
is_dir()/iterdir()/glob()gated onnot is_symlink(). It is only ever correct for files; for directories it is blind tothe one reparse type an unprivileged Windows user can create. Two adjacent
residuals this diff deliberately leaves alone, both worth their own look:
platform_compat.first_linked_ancestor, for a realdirectory reached through a linked parent;
is_dir() and not is_symlink()sites still onmain, e.g.dashboard/theme_validate.py:1159andapps/builtins/pptx_maker/backend/engine_source.py:413.Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Merge note: open PR #7692 also touches
src/kiro_crew/diagnostics.pyandtest/test_diagnostics.py. The two are semantically independent — #7692 rewrites_kiro_cli_version(line ~276) and appends tests at the end of the file, anddoes not touch
_usable_diror any of its call sites. The only textual contactis the
from kiro_crew import ...line, two lines above where #7692 inserts itsnew imports; whichever lands second may need that one-line import merge.
🤖 Generated with Claude Code