Repository navigation
fix: fold letter case when checking a trusted file path for a link - #38906
Conversation
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff changes only [UX-REVIEWED] 43536bd Description read[DESCRIPTION-READ] b7efcbe19b191e3bbb8236701e0b050de62b32503188a994859491b95751369b That sha256 names everything this verdict read: the PR description, plus the 9 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) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: this is a mechanism-level fix for a linked defect (#38610), and the follow-up link check reuses existing Not checked: whether Windows What this change shipsInventory (2 items) — 2 justifiedIntent: when the agent spells a path in a different letter case from the disk, Windows users still get the "trust this file" grant, so they aren't asked again on every write. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 43536bd Description read[DESCRIPTION-READ] c84f67b537c71beaae080244949d7b06f44495a9327873a21e335c5358c2f2a9 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the case-only branch falls back to real link and junction checks on the path and every ancestor, so the grant is only loosened for regular files. Notes
[DESIGN-REVIEWED] 43536bd Description read[DESCRIPTION-READ] 71fb0b74f6f8886538029e9b367562a93e2ae5e4a4c01044a4291793fe07cb2b 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 — ✅ 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 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
bd942bd to
b1c57b0
Compare
|
GPT 6.1 finding (symlink to a case-variant sibling in a case-sensitive NTFS directory): fixed in b1c57b0. When only the case differs, |
On Windows realpath answers the case stored on disk, so a lower-case drive letter or a folder or file name in another case read as a link and withheld the file grant. Fold case on both sides, and walk the chain for a link when only the case differs, so a symlink to a case-variant sibling still withholds it.
b1c57b0 to
2ad2608
Compare
First Principles review: the private ancestor walk duplicated platform_compat.first_linked_ancestor and walked leaf-first. Check the leaf with is_link_or_junction and the ancestors root-first with first_linked_ancestor. A new test covers a folder link to a case-variant sibling.
|
First Principles finding (second spelling of the ancestor-link walk): fixed in 43536bd. |
Code change approver recommendation: A person should decideWhy: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: being reviewed. On Windows, path_trust_unresolved now treats a path whose only difference from disk is letter case as a regular file, so the card offers the file grant. A case-only difference still falls back to real link and junction checks on the file itself and on every parent folder (root first, using the platform_compat helpers). Errors still return True, and Linux and macOS behave as before because normcase changes nothing there. Both callers (offering the grant and re-checking it before use) still fail closed when a link is present. Grant keys still use the exact spelling. The new tests would fail on main, and the folder-link test fails if the parent-folder check is dropped. CI is green, including Windows. Tier: pending: being reviewed. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved. On head 43536bd the review read the full diff, both callers (the grant offer in permission_prompt.py and the grant check in tool_approval.py), and the platform_compat link helpers it uses. The review ran the selected tests at head: 8 passed. It also ran mutations. Reverting the fix fails the 4 tests named on the Proof line, and dropping the leaf check or the ancestor check fails 1 test each. Neither file has changed on main since the merge base, and no other open PR covers #38610.
Security: this loosens when the per-file grant is offered, but only for a Windows path that differs from its realpath purely by letter case. It returns False in that case only when the file is not a link or junction and no ancestor is one. The ancestor check uses the existing root-first first_linked_ancestor walk. On Linux and macOS normcase changes nothing, so the result is the same as on main. OSError, ValueError, 8.3 names, subst drives and any other difference beyond case still withhold the grant. path_trust_key still encodes the exact spelling, so a grant made for one spelling never matches another.
Done well: the change reuses the shared platform_compat helpers instead of adding a second link walk, and each new branch has a test that fails if that branch is removed.
Optional:
Fixes #38610will close the issue, but its Expected also covers 8.3 short names, which this PR leaves out of scope.Part of #38610or a follow-up issue would keep that leg tracked.- The Windows behaviour is proven only against a faked ntpath. A real file system test under
skipif(os.name != "nt")would run on the Windows CI shards and replace the manual Windows check the body asks for. - The folder-link test puts the link at the immediate parent. A grandparent-link case would also pin how deep the ancestor walk goes.
Problem / Motivation
Goal: A Windows file-write card still offers the file grant when the path's letter case differs from the case on disk.
On Windows
os.path.realpathreturns the case stored on disk, sopath_trust_unresolvedread a lower-case drive letter, or a folder or file name in another case, as a link. The card then withheld the file grant and every later write asked again.Why it matters
Windows users whose agent spells a path in another case (
c:\...) get no "trust this file" option, so each write re-prompts. That is the repeated prompting the file grant (#33031) exists to remove. Writes are never blocked.Not a goal
path_trust_targetorpath_trust_key; the grant still keys on the exact spelling.What changed (motivation → approach → change)
Symptom:
path_trust_unresolved("c:\\w\\Proj\\Allow.txt")is True for a regular file. Cause:os.path.realpath(path) != pathcompares the on-disk case with the call's spelling. Change: whenrealpathdiffers from the path, compareos.path.normcase(realpath)withos.path.normcase(path).normcaseis the identity on Linux and macOS and lower-cases on Windows. A differing name (a junction or symlink elsewhere) still returns True. When only the case differs, the path is checked withplatform_compat.is_link_or_junctionand its ancestors with the existingplatform_compat.first_linked_ancestor(root-first), so a symlink to a case-variant sibling in a case-sensitive NTFS directory (allow.txt->Allow.txt), or a folder linkproj->Proj, still withholds the grant (GPT review finding).Files:
src/kiro_crew/trust_patterns.py(a few lines plus a comment),test/test_kas_reject_reason_and_path_trust.py.Backwards compatibility
Compatible: Linux and macOS results are unchanged (
normcaseis the identity there). On Windows only case-only spellings change, from True to False.Removes nothing: the check only returns False for more regular-file spellings; a link still returns True.
Tests
Four new tests use a fake
os.pathbacked byntpath.normcaseand a modelled disk (one file, one junction), so they run on Linux:test_a_case_only_difference_is_not_a_link_on_windows: four spellings return False.test_a_junction_still_withholds_the_grant_on_windows: a junction still returns True, in any case.test_a_symlink_to_a_case_variant_sibling_withholds_the_grant_on_windows: a symlink to a sibling that differs only in case returns True; the regular file returns False.test_a_folder_link_to_a_case_variant_sibling_withholds_the_grant_on_windows: a file under a folder linkproj->Projreturns True (fails if the ancestor check is dropped).Proof: PROVEN test/test_kas_reject_reason_and_path_trust.py::test_a_case_only_difference_is_not_a_link_on_windows[c:\w\Proj\Allow.txt], test/test_kas_reject_reason_and_path_trust.py::test_a_case_only_difference_is_not_a_link_on_windows[C:\w\PROJ\Allow.txt], test/test_kas_reject_reason_and_path_trust.py::test_a_case_only_difference_is_not_a_link_on_windows[C:\w\Proj\allow.txt], test/test_kas_reject_reason_and_path_trust.py::test_a_symlink_to_a_case_variant_sibling_withholds_the_grant_on_windows (head 43536bd; the tests patch
is_link_or_junctionandfirst_linked_ancestorthrough theplatform_compatfacade, as test_facade_mirror_guards requires)Manual verification
Not run on Windows (written on an aarch64 Linux host). A maintainer must check this on Windows: with a regular file
C:\w\Proj\Allow.txtand a junction toProj,path_trust_unresolvedshould be False forc:\w\Proj\Allow.txt,C:\w\PROJ\Allow.txtandC:\w\Proj\allow.txt, and True through the junction.Screenshots / video
N/A: no UI change.
Related Issues
Fixes #38610
Sibling sweep
Swept: git grep -nE "realpath([^)]*) *(!=|==)" -- src
Siblings: none -- the other hits compare two resolves with each other or are not trust-grant link checks; the case-only macOS sites are #37236.
Pattern harvest
Not generalizable: a one-off case-sensitive comparison of
realpathoutput against a caller's spelling; #37236 tracks the other sites.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.