Skip to content

fix: fold letter case when checking a trusted file path for a link - #38906

Merged
KiroCrewCaptain merged 2 commits into
mainfrom
fix/38610-case-insensitive-path-trust
Nov 18, 2026
Merged

KiroCrewCaptain merged 2 commits into
mainfrom
fix/38610-case-insensitive-path-trust

Conversation

@JLargent42

@JLargent42 JLargent42 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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.realpath returns the case stored on disk, so path_trust_unresolved read 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

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) != path compares the on-disk case with the call's spelling. Change: when realpath differs from the path, compare os.path.normcase(realpath) with os.path.normcase(path). normcase is 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 with platform_compat.is_link_or_junction and its ancestors with the existing platform_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 link proj -> 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 (normcase is 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.path backed by ntpath.normcase and 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 link proj -> Proj returns 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_junction and first_linked_ancestor through the platform_compat facade, 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.txt and a junction to Proj, path_trust_unresolved should be False for c:\w\Proj\Allow.txt, C:\w\PROJ\Allow.txt and C:\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 realpath output against a caller's spelling; #37236 tracks the other sites.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@JLargent42
JLargent42 requested review from a team and KiroCrewCaptain as code owners November 18, 2026 01:57
@JLargent42 JLargent42 self-assigned this Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 43536bd41ed63add06404defd4b21374ae768027 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The diff changes only trust_patterns.py and a test file, so it adds or changes no user-visible control. The screenshots in the evidence list show a different surface and don't affect this verdict.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 43536bd41ed63add06404defd4b21374ae768027 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 platform_compat helpers.

Not checked: whether Windows realpath returns the on-disk case. The PR asks a maintainer to check this on Windows.

What this change ships

Inventory (2 items) — 2 justified

Intent: 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.

  1. A Windows write card offers the file grant when the path differs from the disk only in letter case — justified
  2. A path differing only in case still withholds the grant if the file or a parent folder is a link — justified

[FIRST-PRINCIPLES-REVIEWED] 43536bd

Description read

[DESCRIPTION-READ] c84f67b537c71beaae080244949d7b06f44495a9327873a21e335c5358c2f2a9

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 43536bd41ed63add06404defd4b21374ae768027 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • The Windows result rests on fakes and a manual check someone else still has to run. Windows CI runs the full suite, so a real-filesystem test marked skipif(os.name != "nt") would run there and could replace that manual step. It would create a file, probe c:\ and folder/file case variants, and make a junction with mklink /J.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 43536bd41ed63add06404defd4b21374ae768027 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 43536bd

Verdict parsed from the review's SHA-scoped output markers for commit 43536bd41ed63add06404defd4b21374ae768027.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 43536bd41ed63add06404defd4b21374ae768027 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 43536bd41ed63add06404defd4b21374ae768027 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 43536bd

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 43536bd41ed63add06404defd4b21374ae768027 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 18, 2026
@JLargent42
JLargent42 force-pushed the fix/38610-case-insensitive-path-trust branch from bd942bd to b1c57b0 Compare November 18, 2026 02:42
@JLargent42

Copy link
Copy Markdown
Contributor Author

GPT 6.1 finding (symlink to a case-variant sibling in a case-sensitive NTFS directory): fixed in b1c57b0. When only the case differs, path_trust_unresolved now walks the path and each ancestor with is_link_or_junction before returning False. Test: test_a_symlink_to_a_case_variant_sibling_withholds_the_grant_on_windows. Still needs a check on a real Windows host. Also fixed the isort failure in the test file.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 18, 2026
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.
@JLargent42
JLargent42 force-pushed the fix/38610-case-insensitive-path-trust branch from b1c57b0 to 2ad2608 Compare November 18, 2026 07:52
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 18, 2026
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.
@JLargent42

Copy link
Copy Markdown
Contributor Author

First Principles finding (second spelling of the ancestor-link walk): fixed in 43536bd. _chain_has_link is deleted; path_trust_unresolved now calls platform_compat.is_link_or_junction(path) or platform_compat.first_linked_ancestor(path) is not None, so the ancestors are walked root-first by the existing helper. The tests patch both through the platform_compat facade (this also clears the test_facade_mirror_guards red on the earlier head). New test test_a_folder_link_to_a_case_variant_sibling_withholds_the_grant_on_windows fails if the ancestor check is dropped. Still needs a check on a real Windows host.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 18, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: 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 43536bd41e · 84 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 18, 2026 11:10

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 #38610 will close the issue, but its Expected also covers 8.3 short names, which this PR leaves out of scope. Part of #38610 or 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.

@KiroCrewCaptain
KiroCrewCaptain merged commit b8b1a88 into main Nov 18, 2026
112 of 118 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/38610-case-insensitive-path-trust branch November 18, 2026 11:10
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: a lowercase drive letter or other case difference withholds the file grant as if the path were a link

2 participants