Repository navigation
fix(notes): open notes in a vault at a drive root - #24788
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. The change is small and fixes the root cause. Linux CI runs the same branch, because the vault root [DESIGN-REVIEWED] 4efe0eb Description read[DESCRIPTION-READ] 1e576f2cae4c8aeb8903e40c7cf6e789397a9654dfecade6f5277be49485389c 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 This is a one-line fix to the code that caused the bug, and it has a test that fails on main. The four sibling sites it leaves alone already have their own issues (#24742, #24743, #24694). What this change shipsInventory (2 items) — 2 justifiedIntent: let a Notes vault set to a drive root or a share root open, read and save its notes. FIX.
[FIRST-PRINCIPLES-REVIEWED] 4efe0eb Description read[DESCRIPTION-READ] 72206ca2469412637a4d6524353793b19b52db23b4eb20ed686570f89438c58c That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
|
CI attribution for the red checks on this head. None of them comes from this diff, which only changes the Notes vault path code.
Bringing this branch up to date with Failing checks on head
|
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
safe_join compared the note realpath against root_resolved + os.sep. A vault at a drive or share root keeps its trailing separator through realpath, so the prefix became D:\\ and every note, and every subfolder content root, was refused as escaping the vault. Strip the separator first, the rule sandbox_plan.path_within uses; every escape is still refused. Closes kirodotdev#24785 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7cf2af2 to
4efe0eb
Compare
|
CI attribution for head |
|
Holding for a human reviewer under the sensitive-change rule, not because of a defect. This PR changes the containment check in The code looks correct to me. What clears it: a human maintainer's review of the guard change. Reviewed head: — crew-pr-reviewer (r141) |
bolichen97
left a comment
There was a problem hiding this comment.
Approving at head 4efe0eb.
What changed: safe_join in md_notebook/server_paths.py now strips a trailing separator from the resolved vault root before appending os.sep. A drive-root vault (D:\ or /) keeps its separator through realpath, so the old root + os.sep check became D:\\ or // and rejected every note inside the vault.
Containment check: this cannot widen access outside the vault.
os.path.realpathonly returns a trailing separator for a filesystem or drive root, so for any non-root vaultrstrip(os.sep)is a no-op and the check is byte-identical to before.- For a root vault, the prefix becomes exactly
/orD:\, which is the vault itself. Every path below a root is by definition inside it. - The earlier
path escapes vaultguard on the candidate and theresolved != root_resolvedequality are unchanged. - Plain string prefix handling, no pattern matching added. This also matches how
sandbox_plan.path_withinhandles the same case.
Test: the new test_safe_join_admits_a_note_below_a_drive_root_vault builds a drive root from the real tmp path and asserts the nested note resolves, which fails on the old prefix.
Gates at this head: 92 checks passed, 0 red, 0 pending, including E2E, both E2E Gateway Boot jobs and PR Readiness; readiness label passed; all AI lanes green; no other open change requests; mergeable.
Problem / Motivation
Goal: A Notes vault whose folder is a drive root (
D:\) or a share root opens, reads and saves its notes instead of refusing every one as escaping the vault.md_notebook.server_paths.safe_joinrefuses a note unless its realpath starts withroot_resolved + os.sep.os.path.realpathkeeps a root's trailing separator, so for a vault atD:\the prefix isD:\\and no path matches. Attaching the folder succeeds (it passes the sensitive-path floor), then every note request answers400 path escapes vault, and so does a subfolder content root, which also goes throughsafe_join.Why it matters
A dedicated notes drive, or a mapped share whose root is the git checkout, is a normal Windows layout. The vault looks attached but is unusable, and the error blames the note path rather than the check.
Not a goal
.., drive letter, UNC) and the symlink-resolving realpath check stay as they are.root + os.sepsites outside the Notes app (see Sibling sweep).\\?\extended-length prefix mismatch tracked in Twelve path-containment checks reject a legitimate path when one operand carries the Windows \\?\ extended-length prefix #15210.What changed (motivation → approach → change)
Symptom: every note in a drive-root vault is refused. Cause: the containment prefix doubles the separator a root already ends with. Change: strip the trailing separator before appending one, the rule
sandbox_plan.path_withinuses. The check stays an inlinestartswithon the realpath, because the function's docstring records that this shape is thepy/path-injectionbarrier for the returned value. For every non-root vault the prefix is unchanged, since a realpath ends in a separator only at a root.Backwards compatibility
Compatible: the check now admits paths under a root vault that it wrongly refused. For any other vault the comparison is byte-identical.
Removes nothing: no path, key or record is hidden or removed.
Tests
Proof: not provable -- other: prove.py on this Windows host reported INCONCLUSIVE (its mutated run errored at collection); the manual revert below shows the test red without the fix
test_md_notebook_git_trust.py::test_safe_join_admits_a_note_below_a_drive_root_vaultuses the drive root oftmp_pathas the vault and asserts a note below it resolves. On main it fails withApiError: path escapes vault(server_paths.py:547). The six existingtest_safe_join_rejects_escapes_before_touching_the_filesystemcases still pass, so every escape is still refused.Related tests on Windows / Python 3.13:
test_md_notebook_git_trust.py,test_md_notebook_notes.py,test_md_notebook.py: 170 passed, 17 skipped (-n 4). flake8, isort, black, comment-history, brand, subprocess-encoding andtest_flake_pattern_ratchet.py(62 passed) are clean. Not run locally: semgrep (not installed on this host; CI's SAST job runs it).mypyon this host reports one error, inpublish_governance.py:299, a file this diff does not touch.Manual verification
N/A — unit coverage sufficient: the defect is pure path arithmetic in one function, and the test runs it against a real drive root.
Related Issues
Closes #24785
Sibling sweep
Swept: git grep -nE "startswith(.{0,70}(+ ?os.sep|+ ?os.path.sep)" origin/main -- 'src/*.py'
Sibling: src/kiro_crew/apps/builtins/md_notebook/server_paths.py:546 -- changed here
Sibling: src/kiro_crew/dashboard/file_api/pinned_io.py:430 -- tracked in #24742
Sibling: src/kiro_crew/dashboard/file_api/path_complete.py:266 -- tracked in #24742
Sibling: src/kiro_crew/folder_steering.py:339 -- tracked in #24743
Sibling: src/kiro_crew/dashboard/terminal_commands.py:472 -- tracked in #24694
Sibling: src/kiro_crew/edition_install_fence.py:42 -- not affected -- each root is rstripped of separators before the separator is appended
Sibling: src/kiro_crew/apps/agent_launch.py:221 -- not affected -- its roots are the launch directory the crew chose, never a drive root
Sibling: src/kiro_crew/apps/module_loader.py:199 -- not affected -- its roots are app source directories, never a drive root
Pattern harvest
Rule candidate: semgrep
Pattern:
x.startswith(<realpath or normpath result> + os.sep)without anrstrip(os.sep), which refuses everything under a drive rootChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code