Repository navigation
fix(mcp): keep the policy for a long-path, relative or missing handler on another drive - #20746
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix was checked once on a real Windows runner, and that test was then removed. A human should confirm that a real file on another drive still answers False. What this change shipsInventory (6 items) — 6 justifiedIntent: stop a Windows tool handler from skipping Kiro Crew's managed tool policy just because its location shows a different drive, when that location doesn't prove the file is on another drive. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] ff7a8bc Description read[DESCRIPTION-READ] e4606b80d2f0fff81c9d4007955871cdab2a60a4ed02c8bc93b7c266790dcde0 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 Verify before merge: the only native-Windows proof (the [DESIGN-REVIEWED] ff7a8bc Description read[DESCRIPTION-READ] 5fd7319c48aa551841c1ca048a39f26600c65ee882d2d0b8f9093b761dbbf8ca 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. |
7760e91 to
2ec385f
Compare
|
New head Fixed: fail-closed on an unestablished different drive (
Fixed: comment now names the UNC and Fixed: symlink pin. Mutations, each failing a named test: Gates on this head: |
2ec385f to
4e566e5
Compare
4e566e5 to
e7430a3
Compare
|
Backend Tests (Windows) (7) on 4e566e5: Fixed in the test, First-pass check: R1-R8 OK |
|
Status on |
|
HOLD (policy-sensitive) at 4a91dc3. This changes the fail-closed managed tool policy check in src/kiro_crew/mcp_shared.py (serves_managed_tools and _path_is_under), which decides whether an MCP handler's calls are governed by the policy. Changes to that control are reserved for a human reviewer, so this review does not approve it even though I found no defect. Why it looks sound: a drive mismatch now proves 'not managed' only for an existing file under an absolute name with a drive, after folding the long-path prefix on both sides (mcp_shared.py#L1508-L1547). Relative, rooted-without-drive, missing and unresolvable inputs return True, matching the function's fail-closed contract, and #20802's real cross-drive answer is unchanged. The new ntpath-based tests cover each branch and are reported to fail on main. To clear before a human approves:
— crew-pr-reviewer (r106) |
4a91dc3 to
88c4674
Compare
|
Reply to the r106 HOLD. New head 88c4674 (HEAD amended, still 2 commits). The only change is one Windows-only test; 1. Design: a handler loaded from a zip or frozen bundle on another drive. No supported install path loads a handler that way. On every one, the handler's
For that shape, main's behaviour depends on the drive:
That True is the intended contract. The docstring says every answer the check cannot establish is True, and a drive mismatch on a name that does not exist on disk proves nothing about where the code lives. The cost is that an archive-loaded app on another drive keeps the policy and has its calls refused. The body already states this cost for a handler file that cannot be found. 2. First Principles: native 3. The macOS (3) re-run, where only the log upload failed with ENOTFOUND, needs a maintainer. The new head starts fresh runs anyway. Gates on 88c4674 (Linux, Python 3.12): the scope file, |
88c4674 to
7e1fbd1
Compare
|
New head 7e1fbd1 (HEAD amended, still 2 commits). GPT 6.1 at 88c4674, Update to item 2 of the r106 HOLD reply (native Gates on 7e1fbd1 (Linux, Python 3.12): the scope file, |
…r on another drive kirodotdev#20802 answers "not managed" for any drive mismatch, so the managed tool policy is skipped. That is right for an existing app file named by an absolute path, but it also fires for inputs that do not prove the handler is on another drive: a \\?\ long-path spelling on one side only (the same drive written another way), a relative co_filename (resolved against the cwd at call time) and a file that does not exist. serves_managed_tools now tells _path_is_under whether the handler is an existing file under an absolute name, and passes its own os.path so the module's path rules decide both checks. _path_is_under answers "not managed" on a drive mismatch only for such a file with no \\?\ prefix on either side; every other mismatch keeps the policy. Related: kirodotdev#20800, kirodotdev#20682
Fold \\?\X:\ and \\?\UNC\server\share on both sides before the drive check with platform_compat.strip_extended_length_prefix, so a deep real app on another drive is not managed and a long-path spelling of Kiro Crew's own file still is. Drops the prefixed branch. The test fake resolves paths lexically so no case reaches a native realpath on a UNC host. A drive-relative name such as C:app\mcp_server.py has a drive but no root, so it resolves against that drive's cwd at call time and keeps the policy. A test pins the absolute-name check that decides it.
7e1fbd1 to
ff7a8bc
Compare
|
New head Mutation pin. A mutation check on every line of the drive decision found one condition no test pinned: deleting Body. Backend Tests (Windows) (5) on Gates on First-pass check: R1-R8 OK. |
|
|
|
HOLD (policy-sensitive) at ff7a8bc. This still changes the fail-closed managed tool policy check in Since r106:
The current Design and First Principles headlines both ask a human to accept that the one-time Windows run is the only native proof. That is part of the human sign-off below. To clear: a human reviewer signs off on the policy-check change. — crew-pr-reviewer (r107) |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved by a maintainer. Every review lane is clean, the change matches its description, and the automation held this on a category, path or size rule only.
Problem / Motivation
Goal: A handler on another Windows drive skips the managed tool policy only when that drive is proven: an existing file named by an absolute path with a drive. Both sides are compared without the
\\?\long-path prefix, which only spells a path.This is a follow-up to #20802, which fixed the cross-drive
ValueErrorbehind #20800 / #20682. #20802's_path_is_underanswers False ("not managed", so the policy read is skipped) for any drive mismatch. That is the right answer for the case it fixed: a real app file onC:with Kiro Crew onD:. But a drive mismatch also shows up for inputs that do not prove the handler is on another drive:\\?\long-path spelling on one side only:\\?\D:\...\kiro_crew\mcp_core.pysplits to drive\\?\D:, which differs fromD:, so Kiro Crew's own file reads as foreign (Windowsrealpathkeeps that prefix on deep paths);co_filename: it resolves against whatever the cwd is at call time, so its drive says nothing about where the code lives;\app\mcp_server.py): it resolves against the drive of the cwd at call time, and on Python 3.12ntpath.isabsstill calls it absolute;The long-path case is fixed by folding the prefix. The other three cannot be located, so they keep the policy. Before #20802 all of these kept the policy (the
ValueErrorarm returned True). On current main they skip it.Why it matters
serves_managed_toolsis the fail-closed side of a governance control: every answer it cannot establish is True. These are not established, so they keep the policy. No normal pip, wheel or desktop install produces them: hardening, not a live bypass.Not a goal
normcase, or thecommonpathlogic.splitdrivereturns no drive there.What changed (motivation → approach → change)
A drive mismatch means "not managed" only when the check finds the handler's file on disk under an absolute name with a drive; every other mismatch keeps the policy.
src/kiro_crew/mcp_shared.py, two small hunks:serves_managed_toolsworks outlocatedinside the existingtry(OSErrorstill answers True): the original name, with any\\?\prefix folded, has a drive and is absolute, and itsrealpathis an existing file. It passeslocatedand its ownos.pathto_path_is_under, so both checks use one set of path rules and the tests can run Windows rules on every OS._path_is_underfolds both sides with the existingplatform_compat.strip_extended_length_prefix(\\?\UNC\server\share\...becomes\\server\share\...,\\?\X:\...becomesX:\...), then on a drive mismatch returnsnot located.locateddefaults to True, as fix(mcp): treat an app on another Windows drive as outside the package #20802's direct tests call it; the one production caller passes it.src/kiro_crew/platform_compat.py:strip_extended_length_prefixis typed with aTypeVar, sostrin givesstrout. Its body is unchanged.Why not locate archives or sourceless pycs too: no supported install produces them (see the sweep below), so that would be machinery for an input nothing ships.
Backwards compatibility
Breaking: on Windows, a handler on another drive whose
co_filenamecannot be located (relative, drive-relative, rooted with no drive, a zip-imported or sourceless.pycmodule, a missing file) keeps the managed tool policy again, as it did before #20802. An app served that way has its calls refused where no identity can be attested. An existing file under an absolute name on another drive stays not managed (#20802), and a\\?\spelling compares as its plain path.Writer sweep on origin/main @ 12835a8: no supported writer produces that shape.
install_appcopies a local directory as loose files, registry apps arrive bygit clone, app dependencies install withpip --target, builtin apps live under the package, and the desktop builds keep each source beside its pyc (packaging/precompile_windows.py,packaging/build-desktop.sh), so the source loader setsco_filenameto the real file. Only an app whose own manifest command runs an archive or a sourceless.pycgets the refusal.Reader: src/kiro_crew/mcp_shared.py:_run_stdio_dispatch_loop -- app -- test_app_mcp_tool_policy_scope.py::TestAppServerSkipsThePolicyRead
Tests
test/test_app_mcp_tool_policy_scope.py.TestAnotherDriveNeedsProofswapsmcp_shared.osfor one whosepathisntpath(lexicalrealpath,isfilefrom the files a test lists, relative names againstC:\work), with the package on the CI checkout'sD:path, and asksserves_managed_tools:\\?\D:\...\kiro_crew\mcp_core.py; a plain package file with the package spelled\\?\D:\...\\server\share\...: handler\\?\UNC\..., or the package spelled\\?\UNC\...\\?\unc\...(Windowsrealpathnever writes it): folds to a name with no drive, not locatedapp\..., drive-relativeC:app\..., rooted\app\..., missing filerealpathraisingOSErrorC:(#20802's case) or at\\?\C:\..., an app at\\?\UNC\server\share\..., or an app onC:with the package spelled\\?\D:\...D:TestServesManagedTools::test_a_link_into_the_package_is_managed: a handler under amake_dir_linklink to the package is managed.Mutation check, each red: drop any of the four
locatedconditions (drive,isabs,isfile, folding the original name), read the drive orisabsfrom the resolved path, stop folding either side in_path_is_under, answer False or True on every mismatch, defaultlocatedto False.Determinism: the file passes 20 runs at
-n0, 10 at-n 4 --dist loadgroupbesidetest_managed_tool_policy_include.pyandtest_app_mcp_session_identity.py, and a shuffled order (seed 20746). Linux, Python 3.12: the file and theserves_managed_tools/strip_extended_length_prefixneighbours at-n 4, 553 passed, 1 skipped; the ratchets and facade guards, 543 passed. Black gate, isort, flake8, mypysrc/kiro_crew(no issues), comment-history, subprocess-encoding, the flake-pattern ratchet and Semgrep with the repo rules on the diff (0 findings) pass.Manual verification
A native test ran once and passed on a Windows runner (Backend Tests (Windows) (7)): a real handler past 260 characters on another drive resolved through
realpathto an existing file and answered False. It was removed because its skip guards broke a-ratchet-may-only-tighten. The fake resolves lexically, so no case reaches a nativerealpathon a UNC host.Related Issues
Related: #20800, #20682. Follow-up to #20802.
Pattern harvest
Not generalizable: the rule is specific to this fail-closed check. A drive mismatch proves "elsewhere" only for an existing file under an absolute name with a drive, once any
\\?\prefix is folded; othercommonpathusers ask other questions.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)docs/architecture/mcp.mddescribes the check at the level this does not changeContribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.