Repository navigation
fix: pin the two remaining bare-name kiro-cli spawns off PATH - #11209
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify no documented install method leaves kiro-cli PATH-only, since [DESIGN-REVIEWED] ea04b26 |
Opus 4.8 Review — ✅ no blocking findingsReviewed 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: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Confirm #8495 itself asks to refuse a PATH-only install: Not justified as shipped
What this change shipsInventory (7 items) — 5 justifiedIntent: stop
[FIRST-PRINCIPLES-REVIEWED] ea04b26 |
|
[worker note on the GPT 5.6 BLOCKING for Finding: "PATH exclusion still selects agent-writable home binaries" — Why this PR does not adopt that fix (measured, not argued):
The lane withheld this security-class finding from adjudication, so the blocking verdict stands until a repository writer records a judgment for this head. No |
`kirocrew update` (`cli_server._update`) and the diagnostics support bundle
(`diagnostics._kiro_cli_version`) both spawned `"kiro-cli"` by bare name, so
the lookup that decides which file runs happened inside `exec` against the
process's inherited `PATH`. That `PATH` can lead with an agent-writable
directory (a worktree venv's `bin`); anything able to drop an executable of
that name there runs as the gateway user. The update path also gated on
`shutil.which("kiro-cli")` and threw the answer away, so the probe and the
spawn could resolve to different files. The diagnostics probe is reached from
the dashboard's `POST /api/diagnostics/collect`, so it fires on a click.
Both sites now resolve through `kiro_cli.pin_kiro_cli`, the sync form of the
pin the gateway's unattended spawns use: `resolve_kiro_cli` with the inherited
`PATH` excluded, leaving the fixed known install directories plus the
operator's own `KIROCREW_KIRO_BIN`. `None` fail-closes to skipping the spawn.
As in the gateway, a refusal is distinguished from an absent backend: an
install that exists only through `PATH` is reported with the override that
puts it back (`PATH_ONLY_INSTALL_NOTE`), so `kirocrew update` says why the
backend step was skipped and `versions.txt` does not misreport a working
install as absent.
Tests: the pinned absolute path reaches `subprocess.run` at both sites, the
deciding lookup excludes the inherited `PATH`, an unresolvable kiro-cli spawns
nothing while the rest of the update runs, a PATH-only install is refused AND
reported at both sites, an absent backend is refused quietly, a raising
lookup degrades like a failed spawn in diagnostics, and two end-to-end tests
with the real resolver prove a shim first on `PATH` is never spawned. An
AST-based structural guard keeps the count of bare-name kiro-cli spawns
(and `which("kiro-cli")` probes) under `src/kiro_crew` at zero.
Closes #8495
Two First Principles review items on the first commit, both subtraction: The gateway's `_kiro_cli_pin_probe` was byte-identical to the new `kiro_cli.pin_kiro_cli`, and its warning spelled `PATH_ONLY_INSTALL_NOTE`'s sentence a third way. The gateway copy is deleted; `_pinned_kiro_cli` hands `pin_kiro_cli` to `asyncio.to_thread` and logs the shared note. The eleven gateway tests that bound the resolver through the gateway module now bind it through `kiro_crew.kiro_cli.resolve_kiro_cli`, which is where the lookup lives. The structural guard hand-rolled an `rglob` + `ast.parse` walk over the whole package. It now iterates `source_corpus.parsed_candidates` pre-filtered on the `"kiro-cli"` literal, like `test_spawn_audit.py`: one cached corpus read, a handful of parses. Behaviour is unchanged at every site; the gateway's pin tests, the new pin tests, and the restart-respawn tests all pass unmodified in assertion.
907155c to
ea04b26
Compare
…tdev#11209) * fix: pin the two remaining bare-name kiro-cli spawns off PATH `kirocrew update` (`cli_server._update`) and the diagnostics support bundle (`diagnostics._kiro_cli_version`) both spawned `"kiro-cli"` by bare name, so the lookup that decides which file runs happened inside `exec` against the process's inherited `PATH`. That `PATH` can lead with an agent-writable directory (a worktree venv's `bin`); anything able to drop an executable of that name there runs as the gateway user. The update path also gated on `shutil.which("kiro-cli")` and threw the answer away, so the probe and the spawn could resolve to different files. The diagnostics probe is reached from the dashboard's `POST /api/diagnostics/collect`, so it fires on a click. Both sites now resolve through `kiro_cli.pin_kiro_cli`, the sync form of the pin the gateway's unattended spawns use: `resolve_kiro_cli` with the inherited `PATH` excluded, leaving the fixed known install directories plus the operator's own `KIROCREW_KIRO_BIN`. `None` fail-closes to skipping the spawn. As in the gateway, a refusal is distinguished from an absent backend: an install that exists only through `PATH` is reported with the override that puts it back (`PATH_ONLY_INSTALL_NOTE`), so `kirocrew update` says why the backend step was skipped and `versions.txt` does not misreport a working install as absent. Tests: the pinned absolute path reaches `subprocess.run` at both sites, the deciding lookup excludes the inherited `PATH`, an unresolvable kiro-cli spawns nothing while the rest of the update runs, a PATH-only install is refused AND reported at both sites, an absent backend is refused quietly, a raising lookup degrades like a failed spawn in diagnostics, and two end-to-end tests with the real resolver prove a shim first on `PATH` is never spawned. An AST-based structural guard keeps the count of bare-name kiro-cli spawns (and `which("kiro-cli")` probes) under `src/kiro_crew` at zero. Closes kirodotdev#8495 * refactor: converge the gateway pin and the spawn guard onto shared code Two First Principles review items on the first commit, both subtraction: The gateway's `_kiro_cli_pin_probe` was byte-identical to the new `kiro_cli.pin_kiro_cli`, and its warning spelled `PATH_ONLY_INSTALL_NOTE`'s sentence a third way. The gateway copy is deleted; `_pinned_kiro_cli` hands `pin_kiro_cli` to `asyncio.to_thread` and logs the shared note. The eleven gateway tests that bound the resolver through the gateway module now bind it through `kiro_crew.kiro_cli.resolve_kiro_cli`, which is where the lookup lives. The structural guard hand-rolled an `rglob` + `ast.parse` walk over the whole package. It now iterates `source_corpus.parsed_candidates` pre-filtered on the `"kiro-cli"` literal, like `test_spawn_audit.py`: one cached corpus read, a handful of parses. Behaviour is unchanged at every site; the gateway's pin tests, the new pin tests, and the restart-respawn tests all pass unmodified in assertion.
What
Pins the two remaining bare-name
kiro-clispawns to an absolute path resolved with the inheritedPATHexcluded, refusing rather than falling back to the bare name:src/kiro_crew/cli_server.py—_update(thekirocrew updatecommand):shutil.which("kiro-cli")as a discarded existence test, thensubprocess.run(["kiro-cli", "update"]).src/kiro_crew/diagnostics.py—_kiro_cli_version:subprocess.run(["kiro-cli", "--version"]), unguarded, reached from the dashboard'sPOST /api/diagnostics/collect.Both now call
kiro_crew.kiro_cli.pin_kiro_cli(), the sync form of the pin the gateway's unattended spawns use (slack/gateway._pinned_kiro_cli). An AST-based structural guard keeps the count of bare-namekiro-clispawns (andwhich("kiro-cli")probes) undersrc/kiro_crewat zero.Closes #8495
Why
argv0 is re-resolved off the inherited
PATHinsideexec, and a gatewayPATHcan lead with an agent-writable directory (a worktree venv'sbin). Anything able to drop an executable namedkiro-clithere runs as the gateway user — onkirocrew update, or on a diagnostics click. An operator being present lowers likelihood, not harm; nobody watchesexecresolve. In the update path thewhichprobe's answer was thrown away, so the probe and the spawn could resolve to different files.Live count on
mainbefore this change: 2 (cli_server.py:1711/1715,diagnostics.py:803).How
kiro_cli.pin_kiro_cli()returns(pinned path or None, an unpinned install exists):resolve_kiro_cli(include_inherited_path=False)— the fixed known install directories plus the operator's ownKIROCREW_KIRO_BIN— and, only when that is empty, aPATH-inclusive lookup that decides the WORDING of the refusal and never names what gets spawned. Absolute or nothing: a relativeKIROCREW_KIRO_BIN(e.g.kiro-cli) passes the resolver's existence check against the current directory whileexecwould re-resolve that bare argv0 offPATH, so a relative pin is refused and reported like aPATH-only install.kiro_cli.PATH_ONLY_INSTALL_NOTEis the shared sentence naming the override (absolute path).cli_server._update:Noneskips the step (fail-closed, like the git spawns beside it whentrusted_git_bin()returnsNone). APATH-only install prints a one-line warning with the override; an absent backend prints nothing (it is optional). Thewhichprobe is gone.diagnostics._kiro_cli_version: three answers forversions.txtand the bug-report footer — the version, plainunavailable(not installed / probe failed), andnot pinned (...)namingKIROCREW_KIRO_BINwhen kiro-cli exists only throughPATH, so a working install is not misreported as absent. The lookup sits inside the existing containment: a raising resolver degrades like a failed spawn._kiro_cli_pin_probeis deleted:_pinned_kiro_clihandspin_kiro_clitoasyncio.to_threadand logs the sharedPATH_ONLY_INSTALL_NOTE; its eleven tests now bind the resolver throughkiro_crew.kiro_cli.resolve_kiro_cli, where the lookup lives. One spelling of the pin, three consumers.Tests
test/test_kiro_cli_pin.py(new, 17 tests), all RED on the unmodified base except the two detector self-checks:pin_kiro_cli: pinned install returned and not flagged; PATH-only install refused and flagged (first lookup isinclude_inherited_path=False, the second only decides wording); absent backend refused quietly.cli_server._update(reusing the coverage module's_GitStub/git_checkoutharness): argv0 is the resolved absolute path; the deciding lookup excludes the inheritedPATH; unresolvable → step skipped, rest of the update runs, nothing printed; PATH-only → skipped AND reported withKIROCREW_KIRO_BIN; end-to-end with the REAL resolver against a fake home and aPATHleading with a shim — the shim is never spawned (POSIX; PATH shadowing with achmod +xshim is a POSIX shape).diagnostics._kiro_cli_version: argv0 is the resolved absolute path; deciding lookup excludesPATH; absent →unavailablewithout spawning; PATH-only → a distinct line namingPATHandKIROCREW_KIRO_BIN; failed spawn →unavailable; raising resolver →unavailable; end-to-end real-resolver shim test as above.source_corpus(RED-before: exactly the two sites), seeing both spellings of the name — the literal and theKIRO_CLI_BIN/KIRO_CLI_NAMEconstants — insubprocess.*list argv,create_subprocess_execvarargs andshutil.whichprobes, attributed to the enclosing function. A shrink-only known set admits the three INTERACTIVE sites (cli_doctor._kiro_cli_signed_in,cli_doctor._doctor,cli_setup._ensure_prerequisites, see Other); any other hit fails, and an entry whose site stops spawning by bare name must be deleted. Self-check pins every shape the detector must see and the two it must ignore ([binary, ...],which("git")).pin_kiro_cli: a relative override is refused and flagged (unit, plus an end-to-end test with the real resolver:KIROCREW_KIRO_BIN=kiro-cliwith a shim in the current directory and first onPATHyields no pin).Adapted:
test/test_cli_server_more_coverage.py(stub matches argv0 by basename; thegit_checkoutfixture pins the resolver to "nothing installed" so the host's own install cannot leak in; three tests resolve/usr/bin/kiro-cliexplicitly and assert the absolute argv).test/test_spawn_audit.py: allowlist comment fordiagnostics.py::_kiro_cli_versionupdated to describe the pinned path (entry key unchanged).Ran by path with
-n0:test/test_kiro_cli_pin.py test/test_cli_server_more_coverage.py test/test_diagnostics.py test/test_spawn_audit.py→ 192 passed.test/test_windows_logs_and_diagnostics.pyalso green. isort / flake8 / mypy clean on the changed files;check_black_formatting.py,check_subprocess_encoding.pyandcheck_comment_history.pypass againstorigin/main.Other
no-screenshotsapplies. The only visible text change is one CLI warning line inkirocrew updateand theversions.txtline in the diagnostics bundle.diagnostics._kiro_cli_versionbut resolves viaresolve_kiro_cli()WITH the inheritedPATH, which is the shape this issue asks to refuse; it also does not touchcli_server. That PR is currently CONFLICTING againstmain; whichever lands second rebases onto the other. This PR also resolves Diagnostics reports "kiro-cli: unavailable" for a working install: the version probe spawns a bare name instead of resolve_kiro_cli() #7674's complaint for the pinned case (a real install in the known directories is no longer reportedunavailable) and names the operator override for the PATH-only case.resolve_kiro_clialready owns (os.path.isabsfor the relative-override refusal); the three shim tests are POSIX-only by marker.kirocrew doctor(cli_doctor._kiro_cli_signed_in,cli_doctor._doctor) andkirocrew setup(cli_setup._ensure_prerequisites) still probe and spawn kiro-cli by bare name throughKIRO_CLI_BIN. They are interactive TTY commands run by the operator, where the inheritedPATHis the documented default (resolve_kiro_clidocstring) and the exposure this issue names — an unattended or click-reachable spawn — does not apply; doctor's rows exist to report what a session would run. They are NOT hidden: the guard sees them and admits exactly those three, shrink-only. Converging them onresolve_kiro_cli()(absolute argv0, PATH kept) is a separate change because ~15 doctor/setup tests pinshutil.whichas their seam.Pattern harvest
Rule candidate: semgrep
Pattern:
subprocess.run([ "kiro-cli", ... ])/create_subprocess_exec("kiro-cli", ...)/shutil.which("kiro-cli")undersrc/kiro_crew— a bare argv0 or a probe whose answer is discarded; route throughkiro_cli.pin_kiro_cli(sync) or_pinned_kiro_cli(async). The AST guard intest/test_kiro_cli_pin.pyis the in-repo form of the same rule.