Repository navigation
fix(terminal): count paths under a drive-root project as agent-writable - #24694
Conversation
The completion probe's _within tested `real.startswith(root + os.sep)`. realpath keeps the separator a drive root already ends in (H:\, or /), so with the project directory or workspace root at a drive root the prefix became H:\\ and no PATH entry below it counted as agent-writable, and _sanitized_path no longer dropped them for being agent-writable. Route the test through sandbox_plan.path_within, which already treats a root ending in a separator as its own prefix: the helper kirodotdev#24504 routes validate_cwd through for the same defect. Part of kirodotdev#24475 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: both [DESIGN-REVIEWED] ac29c23 Description read[DESCRIPTION-READ] ed921eb063c1ea7a77ebadc6c6214c8b39e304dd9e1c8d1823b69e7f9cf52fe6 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix calls the existing containment helper at both readers of the agent-writable roots, so nothing blocks. One note: the sibling sweep leaves out two sites that its own regex matches. Notes
What this change shipsInventory (3 items) — 2 justifiedIntent: under a drive-root project, keep agent-writable PATH entries out of command completion and refuse name grants for programs planted there. FIX.
[FIRST-PRINCIPLES-REVIEWED] ac29c23 Description read[DESCRIPTION-READ] 3afe8df1f7daa69ef7162e7bb5a34d322f5f23d2db6e7b8ebfb09a9b8918417b That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
…able name_grant._within compared against root + os.sep, the same test the previous commit replaced in terminal_commands._within, over the same agent_writable_roots(). A drive root (H:\ or /) already ends in a separator, so no path below it counted as inside, and a program planted under a drive-root project was honoured by a name grant instead of being refused as agent-tree. Route it through sandbox_plan.path_within so one containment rule serves both sites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The new test lives in |
|
Hold at ac29c23 for human review. Both I found no defect. For any root that does not end in a separator, — crew-pr-reviewer (r129) |
iamwhatever
left a comment
There was a problem hiding this comment.
APPROVE (security-sensitive scope, maintainer-accepted)
This PR touches a security-sensitive area, so it was held for a human decision. A maintainer reviewed the deep-check notes for this exact head (ac29c23189d3) and accepted it. This approval supersedes any earlier HOLD from crew-pr-reviewer.
Why it is safe: fixes two path-containment checks for projects at a drive root; the change only makes the writable-path check stricter. CI is green on this head, the base is main, and there is no conflict.
— crew-pr-reviewer (r132)
Problem / Motivation
Goal: Terminal command completion treats a PATH entry under a drive-root project directory (
H:\, or/) as agent-writable, as it already does under any other project directory.#24475 reports that
validate_cwdcannot admit anything below a drive-root allow-list entry, becauserealpath("H:\\")keeps its trailing separator androot + os.sepbecomesH:\\. #24504 fixesvalidate_cwdby routing it throughsandbox_plan.path_within. The same test,real.startswith(root + os.sep), is indashboard/terminal_commands.py::_within, which decides which PATH entries the command-completion probe must drop because the agent can write them. WithKIROCREW_PROJECT_DIRor the workspace root at a drive root, no entry below it counts as inside, so_sanitized_pathstops dropping them for that reason.Why it matters
_withinis the check that keeps an agent-writable directory out of the PATH the completion probe resolves commands from. Measured on a Windows 11 host onorigin/main:_within("C:\\...\\repo\\bin", ("C:\\",))isFalse. An operator who opens a project at a drive root (a common Windows layout for a dedicated work drive) silently loses that filter for every PATH entry on the drive.Not a goal
validate_cwdand the subagent allow-list: fix(subagent): let a drive-root cwd allow-list entry admit its subtree #24504 owns that fix; this PR does not touchsubagent_parts/._is_trusted_diraccepts, or how the roots are collected (_agent_writable_roots).startswith(x + os.sep)prefix tests whose roots cannot be a drive root (see Sibling sweep).What changed (motivation → approach → change)
root + os.sepassumesrootdoes not already end in a separator.realpathstrips a trailing separator from every path except a root, where it is part of the name (H:\,/)._withinnow askssandbox_plan.path_within(real, root), which comparesnormpath(root).rstrip(os.sep) + os.sep, the helper fix(subagent): let a drive-root cwd allow-list entry admit its subtree #24504 uses forvalidate_cwd. One containment rule for both sites instead of a second hand-rolled prefix test. Equality, the sibling-name guard (…/workspace-othervs…/workspace) and the fail-closedNone/OSErrorbranches are unchanged.sandbox_planimports only the standard library, so the new import adds no dependency to the dashboard module.name_grant._withinran the identicalreal.startswith(root + os.sep)over the sameagent_writable_roots()(KIROCREW_PROJECT_DIRplusworkspace_root()). Under a drive-root project a program planted below the root was not counted as agent-tree, so a name grant honoured it instead of refusing it withAGENT_TREE. It now askssandbox_plan.path_withintoo, so one containment rule serves both readers of those roots. The First Principles review on29e1177377named this site; the original sweep regex matched it and the list below left it out.Backwards compatibility
Compatible: for every root that does not end in a separator
path_withingives the same answer as the old test. For a drive root or/it now reports the paths below the root as inside, which only removes entries from the probe's PATH, and makes a name grant refuse a program resolved below that root.Removes nothing: no key, route or function is removed; the change can only make
_sanitized_pathdrop more agent-writable entries and a name grant refuse more agent-tree programs, never fewer.Tests
Proof: PROVEN test/test_terminal_commands.py::TestSanitizedPath::test_a_drive_root_contains_every_path_below_it (head 29e1177)
Proof: PROVEN test/test_name_grant_windows.py::TestAgentWritableRootContainment::test_a_drive_root_contains_every_path_below_it (head ac29c23)
test_terminal_commands.py::TestSanitizedPath::test_a_drive_root_contains_every_path_below_it(new): a directory below the drive root oftmp_path(C:\on Windows,/on POSIX) is inside that root. Fails onmain(False).test_a_sibling_of_a_root_is_not_inside_it(sibling-name, root itself, path inside) andtest_an_undetermined_root_set_refuses_every_entry(fail closed).test_terminal_commands.py,test_terminal_facade.py,test_terminal_handler.py,test_api_health.py,test_facade_mirror_guards.py: 327 passed; the 19 failures (POSIX shell resolution intest_terminal_handler.py) fail identically onmainon this host, which passes 326.test_name_grant_windows.py::TestAgentWritableRootContainment(new, runs on every host;test_name_grant.pyis skipped on Windows): the drive-root case fails onmain(False); the sibling-name / root-itself / inside case passes before and after.ac29c23189:test_name_grant.py,test_name_grant_windows.py,test_name_grant_facade.py,test_name_grant_surfaces.py,test_terminal_commands.py,test_facade_mirror_guards.py: all pass (POSIX-only modules skip here).--baseline-commit) on the first commit only.Manual verification
N/A — unit coverage sufficient: the defect is a string-prefix test, and the new test drives it with the real drive root of the host it runs on.
Related Issues
Part of #24475 (the
validate_cwdhalf is #24504)Sibling sweep
Swept:
git grep -nE "startswith\([a-z_]+ ?\+ ?(os\.sep|\"/\"|os\.path\.sep)\)" -- src/kiro_crewSibling: src/kiro_crew/subagent_parts/agent_policy.py -- tracked in #24504 -- validate_cwd, the reported site
Sibling: src/kiro_crew/name_grant.py:534 -- fixed in this PR --
_within, same roots as the terminal site (second commit)Sibling: src/kiro_crew/dashboard/file_api/pinned_io.py:430 -- tracked in #24742 -- project-relative resolve under a drive-root project
Sibling: src/kiro_crew/dashboard/file_api/path_complete.py:266 -- tracked in #24742 -- path-completion witness check
Sibling: src/kiro_crew/folder_steering.py:339 -- tracked in #24743 -- memory-silo fence, both directions
Sibling: src/kiro_crew/apps/module_loader.py:199 -- not affected -- roots are app source directories, never a drive root
Sibling: src/kiro_crew/dashboard/token_auth.py:110 -- not affected -- URL paths, no trailing-separator root
Sibling: src/kiro_crew/acp/kas_agents.py:299 -- not affected -- the roots are the fixed /proc, /sys and /dev, none of them /
Sibling: src/kiro_crew/apps/agent_launch.py:221 -- not affected -- roots are an app agent's launch directory (launch_cwd_roots), which sits under the data home, never at a drive root
Pattern harvest
Rule candidate: semgrep
Pattern:
x.startswith(root + os.sep)whererootcame fromrealpath/abspathof a configured directory; usesandbox_plan.path_within, since a drive root or/already ends in a separatorChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code