Repository navigation
fix(file-api): let a drive-root project contain the paths below it - #24742
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Both containment checks now call the existing What this change shipsInventory (4 items) — 4 justifiedIntent: let the dashboard file viewer and
[FIRST-PRINCIPLES-REVIEWED] 354c1c8 Description read[DESCRIPTION-READ] 91c29603d98ca47c6e7ca5f1400a320b738a24c3efe7ce15ebedf6c38f94f1df That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Narrow fix at the actual cause. Both checks now use the containment helper the codebase already has, and the new tests drive the real root of whatever host they run on, so POSIX CI covers the [DESIGN-REVIEWED] 354c1c8 Description read[DESCRIPTION-READ] fff7a8fdc186b43c797caaddc1b846a771818c65532fdccf4405ab4337bb0a2d 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 |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
10c3bec to
5e0b7c3
Compare
_resolve_project_relative and the path-completion witness check tested containment with startswith(root + os.sep). realpath keeps the separator of a root, so for a project at H:\ or / the prefix became a doubled separator and every relative path or subdirectory under the project was refused as outside it. Both now ask sandbox_plan.path_within, the helper the validate_cwd and terminal sites use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5e0b7c3 to
354c1c8
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Approving at 354c1c8. All checks pass and there are no change requests.
What I checked:
sandbox_plan.path_withingives the same answer as the oldroot + os.septest for every project except one at a drive root. It strips the trailing separator before adding one, soH:\and/no longer double it. Equal paths still count as inside.- Both callers keep their other checks.
_complete_path_listingstill runsis_sensitive_resolved_pathon the witness._resolve_project_relativestill usesrealpathon both sides. files.pyonly addssandbox_planto the module names the file API reads through.- Each call site has a test for a drive-root project.
- No new regex, and no new refusal.
…24742) _resolve_project_relative and the path-completion witness check tested containment with startswith(root + os.sep). realpath keeps the separator of a root, so for a project at H:\ or / the prefix became a doubled separator and every relative path or subdirectory under the project was refused as outside it. Both now ask sandbox_plan.path_within, the helper the validate_cwd and terminal sites use. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit eaf92fc)
Problem / Motivation
Goal: The dashboard's file viewer and path completion work under a project opened at a drive root (
H:\, or/), as they already do under any other project directory.Two dashboard file-API checks decide "is this inside the project?" with
x.startswith(root + os.sep), whererootisrealpath(project).realpathkeeps the trailing separator of a root (H:\,/), soroot + os.sepbecomesH:\\(or//) and prefixes nothing real:file_api/pinned_io.py::_resolve_project_relative(theresolve=1path of file read / stream / download / office preview): every relative path under a drive-rootKIROCREW_PROJECT_DIRis refused asoutside_project.file_api/path_complete.py::_complete_path_listing: the witness check on the opened directory refuses every subdirectory of a drive-root project asoutside, so@-path completion offers nothing below the project's top level.Measured on Windows 11 / Python 3.13 at
origin/main: withKIROCREW_PROJECT_DIR=C:\,_resolve_project_relative("Users/…/clip.mp4")returns("", "outside_project"), and completing./Users/…/under a known projectC:\returnsoutside: truewith no rows.Why it matters
An operator who keeps work on a dedicated drive and opens it at its root (the layout #24475 reports,
H:\) finds that relative file links in chat do not open and path completion lists nothing below the top level. Nothing says why: the refusal is the sameoutside_project/outsideanswer a real escape gets. Both checks fail closed, so this is a broken feature, not a leak.Not a goal
validate_cwdallow-list (fix(subagent): let a drive-root cwd allow-list entry admit its subtree #24504) and terminal completion's agent-writable PATH filter / name grants (fix(terminal): count paths under a drive-root project as agent-writable #24694): same class, other owners._completion_segments, the lexical containment pass in path completion: it compares segment lists, not prefixes, and already handles a drive root.startswith(x + os.sep)whose root cannot be a drive root (see Sibling sweep).What changed (motivation → approach → change)
root + os.sepassumesrootdoes not already end in a separator; a drive root or/always does.sandbox_plan.path_within(path, root), which compares againstnormpath(root).rstrip(os.sep) + os.sepand keeps the equality case. It is the helper fix(subagent): let a drive-root cwd allow-list entry admit its subtree #24504 and fix(terminal): count paths under a drive-root project as agent-writable #24694 route their sites through, so the file API does not carry a third hand-rolled prefix test. Equality, the sibling-name guard (…/proj-othervs…/proj) and every refusal branch are unchanged.sandbox_planimports only the standard library. Thefile_apiowners run ondashboard/handlers/files.py's globals (_facade_compose), so the facade bindssandbox_planand each owner names it underTYPE_CHECKING, the same way they reachpinned_fsandplatform_compat.Backwards compatibility
Compatible: for every project root that does not end in a separator,
path_withingives the same answer as the old test. For a drive root or/it now admits the paths below the root, which every later gate (the validator's sensitive-path fence, the per-entry fence in completion) still screens.Removes nothing: no key, route, response field or function is removed; the change only stops refusing paths that are inside the project.
Tests
Proof: PROVEN test/test_file_stream.py::test_resolve_admits_a_path_below_a_drive_root_project test/test_path_complete.py::TestPathComplete::test_a_drive_root_project_completes_below_itself (head 10c3bec99459)
test_file_stream.py::test_resolve_admits_a_path_below_a_drive_root_project(new): withKIROCREW_PROJECT_DIRset to the drive root oftmp_path(C:\on Windows,/on POSIX), a relative path to a real file resolves to that file. Fails onmain(outside_project).test_path_complete.py::TestPathComplete::test_a_drive_root_project_completes_below_itself(new): through the real/api/path-completeroute, a known project at the drive root completes a directory below it and lists its entries. Fails onmain(outside: true, no rows).test_a_witness_outside_the_root_is_refused, the../outside/and../<project>/src/cases, the UNC / drive-absolute pass-through, and theoutside_projectrefusals intest_file_download.py/test_file_office_preview.py.test_path_complete.py,test_file_stream.py,test_dashboard_files_composition_contract.py,test_dashboard_files_onloop_fs.py,test_file_office_preview.py,test_file_download.py,test_validation.py,test_pathres_loop_starvation.py: 499 passed; the 7 failures (symlink creation needs a privilege this host lacks, CRLF and content-type differences) fail identically onmainon this host, which passes 497.Manual verification
N/A — unit coverage sufficient: the defect is a string-prefix test, and both new tests drive it with the real drive root of the host they run on, one of them through the HTTP route.
Related Issues
Related to #24475 (same
root + os.sepdrive-root defect; that issue'svalidate_cwdsite is #24504, the terminal sites are #24694)Sibling sweep
Swept:
git grep -nE "startswith\(.{0,60}(\+ ?os\.sep|\+ ?os\.path\.sep)" -- src/kiro_crew(wider than #24694's sweep, which only matched a bare identifier before+ os.sep)Sibling: src/kiro_crew/dashboard/file_api/pinned_io.py:430 -- changed here -- resolve=1 project-relative paths
Sibling: src/kiro_crew/dashboard/file_api/path_complete.py:266 -- changed here -- the completion witness check
Sibling: src/kiro_crew/subagent_parts/agent_policy.py:941 -- tracked in #24504 -- validate_cwd allow-list
Sibling: src/kiro_crew/dashboard/terminal_commands.py:472 -- tracked in #24694 -- agent-writable PATH filter
Sibling: src/kiro_crew/name_grant.py:534 -- tracked in #24694 -- name-grant agent-tree refusal
Sibling: src/kiro_crew/folder_steering.py:339 -- not affected -- by this PR; the memory-silo fence is fixed in its own PR
Sibling: src/kiro_crew/folder_steering.py:176 -- not affected -- skip roots are
.kiro/steeringdirs, never a drive rootSibling: src/kiro_crew/dashboard/handlers/worktree.py:835 -- not affected -- already strips the separator before appending one
Sibling: src/kiro_crew/artifact_source.py:199 -- not affected -- already strips the separator before appending one
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