Skip to content

fix(security): close symlink containment gaps in link and image sinks - #502

Merged
mtskf merged 18 commits into
mainfrom
fix/close-sink-census-gaps
Nov 20, 2026
Merged

mtskf merged 18 commits into
mainfrom
fix/close-sink-census-gaps

Conversation

@mtskf

@mtskf mtskf commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the ARCH-08a sink-census gaps G1–G4 (TODO SINK-01): relative links and pasted images now check the real (symlink-resolved) path, not just the lexical one.

Changes

  • G1 open-link: a file-scheme target is refused when its realpath lies outside both the workspace folder and the document folder (each checked against its own real root). The handler is now async, stays quiet after dispose, and toasts on failure.
  • G2 image-write: the target is checked against the document folder's realpath before assets/ is created. An existing <sha>.png is accepted only as a single-link regular file, so a symlink or hardlink leaf (e.g. pointing at the document) is refused.
  • G3 code reference: codeReferenceFileExistsWithinRoot uses the same realpath containment, pinned by real temp-dir symlink tests.
  • G4: a real-browser test proves rich paste of a remote <img> (src + srcset) issues no request, via a request-recording probe in the browser test server.
  • Shared parent-aware realpath predicate (real-containment.ts, nearest existing ancestor for missing targets) plus a per-segment .. comparator fix.
  • CHANGELOG: one Unreleased → Changed line.

Related

  • Plan: .claude/plans/sink-01-close-census-gaps.md (review-plan APPROVED, stamp c3e3328aa8ef)
  • TODO: SINK-01 / ARCH-08a census

Test Plan

  • pnpm compile, pnpm lint → exit 0
  • pnpm vitest run → 6546/6549. The 3 failures (test/webview/editor.test.ts fold reseed, test/webview/shell.test.ts oversized-switch ×2) are in files this PR doesn't touch; all 216 tests in those files pass when the files run alone (load flake)
  • pnpm test:browser → 99/100. The one failure (outline-sidebar-layout pin grace window) is untouched by this PR; the file passes 7/7 alone. The new rich-paste-no-fetch file passes 2/2
  • env -u ELECTRON_RUN_AS_NODE pnpm test:e2e → 134 passing (re-run after the rebase onto main)
  • pnpm package → audit-vsix: no violations
  • Revert-checks (each restored afterwards):
    • open-link containment off: 4 unit rows go red; the E2E symlink row goes red
    • image-write verdict check removed: 4 outside rows go red; leaf rule removed: the symlink-to-doc and hardlink rows go red; nlink === 1 dropped: the hardlink row goes red
    • rich paste switched to a live-document innerHTML parse: red, with src.png in the diff; git diff src/ empty after restore

Docs follow-up (for the parent session)

  • .claude/docs/ARCHITECTURE.md image-write rows (the two "content-hash 名で assets/ へ書込" lines, currently near :357 and :376): append "realpath containment in the document folder, symlink leaf refused". ARCHITECTURE has no open-link containment description to change.
  • .claude/docs/LEARNING.md "2026-11-05: ARCH-08a sink census": in the census table update the guard and test columns of the G1–G3 rows and clear the gap column; in the Gap section end each G1–G4 line with closed by SINK-01 (PR #<n>) (<n> stays a literal placeholder in the PR body; the parent session fills in this PR's number after merge); fix the .. component comparator note.
  • SECURITY.md has no symlink, realpath or lexical wording (grep confirmed), so it is unchanged.

mtskf added 18 commits November 20, 2026 15:37
@mtskf
mtskf merged commit 198ee82 into main Nov 20, 2026
2 checks passed
@mtskf
mtskf deleted the fix/close-sink-census-gaps branch November 20, 2026 05:05
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.

1 participant