Skip to content

fix: follow links in the existing part of a path that does not exist yet - #85

Merged
kkdev92 merged 2 commits into
mainfrom
fix/validate-new-paths-through-links
Sep 28, 2026
Merged

kkdev92 merged 2 commits into
mainfrom
fix/validate-new-paths-through-links

Conversation

@kkdev92

@kkdev92 kkdev92 commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Makes the workspace-containment check follow links for paths that do not exist yet, at any depth.

Why

validatePathInsideWorkspace resolved a path through realpath only when the path itself or its parent existed. When neither did — a save directory with folders still to be created — it compared the path as written and resolved nothing:

  • A link in the existing part of the path that leads out of the workspace went unseen. writeAtomic validates and then creates the folders with mkdir -p, so with a save directory like assets/new where assets is a link to somewhere else, the folders and the image were created on the far side of the link. With the default .clipshot (one level) the parent exists, so the default was not affected.
  • A workspace opened through a link refused its own new folders. The workspace side is compared as a real path; for a workspace reached through a symlinked home directory, macOS's /var or an 8.3 short name on Windows, the unresolved target never lined up with it, so a nested save directory that did not exist yet was rejected as outside.

The extension runs only in trusted workspaces (untrustedWorkspaces.supported: false), so this is a check that did less than it claimed rather than an exposure to an untrusted workspace.

What changed

  • resolveExistingPrefix walks up to the nearest ancestor that exists, resolves it with realpath, and appends the missing segments. The containment comparison itself is unchanged.
  • A relative path is now taken from the workspace root on every branch; before, the first attempt resolved it from the process's working directory. The only caller (path-generator.ts) builds absolute paths.
  • CHANGELOG.md: an [Unreleased] entry under Fixed.

Verification

  • New test/security/path-validator-workspace.test.ts builds a real directory tree: a link (a junction on Windows) out of the workspace, and a workspace reached through a link. Eight cases, accepting and rejecting.
  • On the previous code, two of them fail — new folders under the outward link are accepted (resolved "true" instead of rejecting), and new folders under the linked workspace are refused. The other six pass on both, so they show the tree behaves as the tests assume.
  • With the fix: npm run lint, npm run compile, npm run typecheck:test and the whole Vitest suite (495 tests) pass locally on Windows; CI runs the new tests on Linux and macOS as well.

🤖 Generated with Claude Code

kkdev92 and others added 2 commits September 28, 2026 14:04
validatePathInsideWorkspace resolved a path through realpath only when the
path itself or its parent existed. When neither did - a save directory with
folders still to be created - it compared the path as written, resolving
nothing. Two things followed:

- A link in the existing part of the path that leads out of the workspace
  went unseen. writeAtomic validates and then creates the folders with
  mkdir -p, so the folders and the image were created on the far side of
  the link.
- In a workspace opened through a link (a symlinked home directory, macOS's
  /var, an 8.3 short name on Windows) the workspace side is a real path and
  the target side was not, so new nested folders were refused as outside.

Resolve the nearest ancestor that exists and append the missing segments to
it, at any depth. A relative path is now taken from the workspace root on
every branch; before, the first attempt resolved it from the process's
working directory. The only caller builds absolute paths.

The extension runs only in trusted workspaces, so this is a check that did
less than it claimed, not an exposure to an untrusted workspace.

The new tests build a real tree with a link out of the workspace and a
workspace reached through a link. Two of them fail on the previous code:
new folders under the outward link were accepted, and new folders under the
linked workspace were refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kkdev92
kkdev92 merged commit d0a51be into main Sep 28, 2026
16 checks passed
@kkdev92
kkdev92 deleted the fix/validate-new-paths-through-links branch September 28, 2026 05:14
@kkdev92 kkdev92 mentioned this pull request Sep 28, 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.

1 participant