Repository navigation
Conversation
GPT 5.6 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- src/kiro_crew/mcp_gateway/spill.py:65 -- Link checks remain vulnerable to a swap race (origin: validation) Adjudication (Opus 4.8) — is blocking on each finding proportionate?The adjudicable block is empty (0 findings). Only fenced finding F1 remains. F1 — TOCTOU swap race on the spill directory. The diff hardens the check by adding junction detection ( Harm is unbounded of the security kind: arbitrary file deletion (cleanup path) or disclosure of a full tool response — a payload that may carry secrets — into an attacker-chosen location (write path). To FLAG I would need to show the swap-and-win condition combination is so extreme a human would accept the residual risk. I cannot complete that record: an agent controlling its own execution timing can retry the race, and I cannot establish from code opened in this run that swapping a directory inside the data home is unreachable — that precondition is precisely the pre-existing filesystem state the residual concerns. When torn on an unbounded-harm fenced finding, the contract requires UPHOLD-FENCED. |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of All claims verified against the base tree: Design-Verdict: PASS Real cross-platform bypass of two existing containment guards, closed at the right layer with the helper built for exactly this, minimally and verifiably. Suggestions
[DESIGN-REVIEWED] 1ed5741 |
First Principles Review (Fable 5, fork) — 🟡 CONCERNSPremise-level review of All verification done. The change reuses existing mechanisms, the defect is derived from a documented platform rule the repo itself pins in First-Principles-Verdict: CONCERNS The exact Not justified as shipped
What this change shipsIntent: stop the gateway deleting or writing files through a junction planted as its spill directory on Windows — a FIX.
Watch
[FIRST-PRINCIPLES-REVIEWED] 1ed5741 |
f7f70d4 to
e03a62e
Compare
`spill.py` guards its spill directory in two places, and BOTH tested only `spill_dir.is_symlink()`. A Windows junction is a directory reparse point, not a symlink: `is_symlink()` answers False for one and `is_dir()` answers True, so both guards admitted it and both operated through the link. 1. `cleanup_old_spill_files()` — the 24h sweep iterated the junction's TARGET and called `entry.unlink()` on every 24h-old regular file there. Its docstring names this exact threat: "an agent that swapped the spill dir ... could otherwise aim this sweep at an arbitrary directory and have the gateway delete 24h-old files there (confused deputy)". The per-entry `lstat`/`S_ISREG` screen does not help — it skips links INSIDE the directory, while here the directory itself is the link. 2. `maybe_spill_response()` — the write path wrote the spilled payload into the junction's target. Its comment states the stake: "an attacker-planted link would redirect the write outside the data home". What lands there is a full tool response, exactly the content that may carry secrets. The `O_EXCL`/`O_NOFOLLOW` open does not cover it: those constrain the FINAL component, not the directory the path resolves through, and `os.O_NOFOLLOW` does not exist on Windows — the only platform with junctions. Both now go through `platform_compat.is_link_or_junction`, which the module already imports. It tries `os.path.islink` first, so symlink behaviour is unchanged and this strictly widens what each guard refuses. Tests: `test_cleanup_refuses_a_linked_spill_dir` and `test_spill_refuses_a_linked_spill_dir` build the link with `conftest.make_dir_link`. Measured on Windows against the unpatched tree, both fail — the sweep deletes the victim's file (`assert 1 == 0`) and the write path leaves a spill file in the victim directory. Both pass after. On POSIX `make_dir_link` yields a symlink, which the original checks already refused, so there they are no-regression checks; `test_make_dir_link_yields_a_junction_on_windows` pins the seam property that makes them load-bearing on Windows without restating what `test_junction_is_recognised_and_removable` already covers. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
e03a62e to
1ed5741
Compare
|
Rebased onto main Clean rebase, no conflicts. No content changes to the PR's diff. Gates run locally on the changed files only: Please review the rebase result. Note that a maintainer push makes the maintainer the last pusher, so under the repo's last-push rule a second approver is needed. Reply here if anything looks wrong. |
|
Kiro Crew [operator: chenmingwei23#de330d0c] Triaged as solvable and claimed for the drive-to-green pipeline. No conflict. Design PASS, Opus clean. Two blockers:
The First Principles CONCERNS about the same pattern at two other call sites is a Content security scan passed with no findings. |
|
Thank you for this, @leonlaiyc — a careful fix with a clearly-reasoned write-up and real red-before/green-after Windows evidence. While this was open,
Those lines match the two you proposed here, and no live Since the bug is already fixed on |
Problem / Motivation
src/kiro_crew/mcp_gateway/spill.pyguards its spill directory in twoplaces, and both tested only
spill_dir.is_symlink().A Windows junction is a directory reparse point, not a symlink:
is_symlink()answers
Falsefor one whileis_dir()answersTrue. So both guards admitteda junction and both then operated through it.
1. The cleanup path —
cleanup_old_spill_files():The 24h sweep iterated the junction's target and called
entry.unlink()onevery 24h-old regular file there. Its docstring names this exact threat:
The per-entry screen does not compensate —
lstat/S_ISREGskips linksinside the directory, while here the directory itself is the link and the
entries reached through it are ordinary regular files.
2. The write path —
maybe_spill_response():The spilled payload was written into the junction's target. What lands there is
a full tool response — exactly the content that may carry secrets. The
O_EXCL/O_NOFOLLOWopen below it does not cover this: those constrain thefinal path component, not the directory the path resolves through, and
os.O_NOFOLLOWdoes not exist on Windows at all — the only platform that hasjunctions.
Both were measured end to end on Windows against the unpatched tree: the sweep
reported
deleted == 1with the victim's file gone, and the write path left aspill file inside the victim directory.
Why it matters
One root cause, two consequences, both outside the data home and both performed
by the gateway rather than by whatever planted the link — the confused deputy
these guards were written to prevent, reached through a link kind neither could
see:
secrets, written to an attacker-chosen directory.
Neither needs user action.
gatewayd.py:496schedulescleanup_old_spill_fileson the maintenance executor at gateway startup, and the write path runs on any
oversized tool result.
The worst part is that the protection reads as present. Each site has an
explicit link check and a comment describing this attack, so a reviewer
concludes the path is hardened — while on Windows neither is.
What changed (motivation → approach → change)
Observed symptom — with the spill directory replaced by a junction, the
startup sweep deletes files in the junction's target, and an oversized tool
result is written there.
Root cause —
Path.is_symlink()isFalsefor a Windows junction whileis_dir()isTrue, so the directory-level check passes at both sites. Everydownstream defence is scoped to something else:
S_ISREGto directoryentries,
O_EXCL/O_NOFOLLOWto the final component.Change — route both checks through
platform_compat.is_link_or_junction,which this module already imports:
That helper tries
os.path.islinkfirst and only then tests for a junction, sosymlink behaviour is byte-identical and each change strictly widens what the
guard refuses. Two production lines, plus comments recording which link kinds
are covered and why the downstream defences are not substitutes.
grep -n 'is_symlink()' src/kiro_crew/mcp_gateway/spill.pynow returns onlyprose — no live call site remains.
Deliberately not changed.
platform_compat.first_linked_ancestordocumentsan adjacent gap — a link in an ancestor of the path, e.g. a junctioned
config_dir(). That is outside the threat these comments model ("swapped thespill dir, or planted a link inside it") and outside what was measured, so it is
named here rather than folded in.
Tests
TestSpillCleanup::test_cleanup_refuses_a_linked_spill_dir— plants a25h-old file in the link target; asserts cleanup returns
0and that thefile still exists. The second assertion is the load-bearing one: a count of 0
alone would also be satisfied by a sweep that found nothing.
TestSpillToFile::test_spill_refuses_a_linked_spill_dir— sends anoversized tool result through
maybe_spill_response; asserts the link targetis still empty and that the original line is forwarded unmodified.
test_make_dir_link_yields_a_junction_on_windows— guards the guard.What a junction is is already pinned by
test_junction_is_recognised_and_removable, so this asserts only the propertythat is pinned nowhere else and that the two tests above depend on: that this
seam yields a junction rather than a symlink. Were
make_dir_linkever tohand back a symlink on Windows, both would pass against the original guards
and prove nothing.
Red-before / green-after, measured on Windows with the tests in place and
spill.pyreverted toorigin/main:After the fix:
292 passed, 1 skippedacrosstest_mcp_gateway_oversize.py+test_mcp_gateway_backend_coverage.py(the skip is the pre-existingwindows-expected-failures.txtentry, not new).Platform honesty.
make_dir_linkcreates a junction on Windows and asymlink on POSIX. The original checks already refused symlinks, so on Linux CI
the two containment tests are no-regression checks rather than red-befores —
only Windows exercises the fix. The third test exists so that distinction is
pinned in the suite rather than living only in this description.
Gates run locally:
flake8clean,isort --check-onlyclean,mypyreportsnothing for
spill.py, andscripts/check_black_formatting.pypasses scoped toorigin/main...HEAD— both touched files were already in the 1166-fileknown-unformatted baseline, so no new offender and no unrelated reformatting.
Manual verification
N/A — unit coverage sufficient: both behaviours are filesystem-level guards, and
the tests create a real junction and assert on a real deletion and a real write,
so there is no integration surface the automated tests cannot reach.
Related Issues
None. Found while auditing link-containment guards; no existing issue covers
this file.
Pattern harvest
Rule candidate:
semgrepPattern: a link-containment guard that tests only
is_symlink()/os.path.islink()before acting on a path — a Windows junction is invisible toboth and passes as an ordinary directory, so the guard silently does not hold
there. Any such site that then walks, reads, hashes, writes or unlinks through
the path should go through
platform_compat.is_link_or_junction.Two corollaries this PR is direct evidence for:
spill_dirwas guarded twicewith the same blind spot; fixing only the site that surfaced first would have
left the disclosure half live.
S_ISREGscreen and anO_EXCL/O_NOFOLLOWopen both sat downstream of these guards and neitherhelped, because each is scoped to a component rather than to the directory the
path resolves through.
The inverse is not a defect:
shutil.rmtreerefuses a junction on its own, soan
rmtree-based site is already safe.Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code