Skip to content

fix(coding-agent): a symlinked skills or commands dir, or a manifest-declared skills, commands or MCP path, outside the plugin root no longer loads - #20405

Open
JamieJ5926 wants to merge 43 commits into
can1357:mainfrom
JamieJ5926:fix/plugin-symlink-containment

Conversation

@JamieJ5926

@JamieJ5926 JamieJ5926 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Plugin roots now judge a symlinked skills or commands directory, and a skills, commands or MCP path that a plugin manifest declares, by where it really points. Such a path that resolves outside its plugin root is refused with a warning and no longer loads its skills, commands or MCP servers. The conventional skills/ and commands/ directories are judged the same way. A path that cannot be resolved for a reason other than a missing file is refused too. A missing or dangling target is never read. A resolved MCP config is read from its canonical path.

Changed: packages/coding-agent/src/discovery/claude-plugins.ts. resolvePluginTarget runs a lexical check, then resolves the real target against the real root. It returns missing, outside, or ok with the canonical path. A declared MCP file that is missing keeps its warning. packages/coding-agent/src/discovery/contained-path.ts now uses pathIsWithinLexical from packages/utils/src/dirs.ts, which accepts a child named ..shared and refuses only a parent segment. packages/coding-agent/test/discovery/claude-plugins.test.ts gains tests and a stricter branch assertion, and one CHANGELOG line now names the residual race.

Why

isWithinPluginRoot compared lexical paths with path.relative and never resolved a symlink. So skills -> /outside inside a plugin root loaded /outside/escaped/SKILL.md, and an mcp.json link loaded its servers (outputs below). realpathIfExists returns null for every error, so a target that failed to resolve for another reason passed as if it were missing. A dangling target therefore passed, and its later read used the lexical path. isContained also refused a child named ..shared.

The Agent Plugins path already resolves links before it checks containment (agent-plugin-format.ts, classifyUncached, with the helpers in contained-path.ts). This change reuses the ContainedPathResolution shape from those helpers. resolvePluginTarget is a separate check because it must also distinguish a missing target from an outside one.

Docs: no page states the symlink rule for Claude plugin roots. docs/skills.md:222 states the realpath rule for Agent Plugins and Skillshare skills, not for the Claude plugin roots this change covers. grep -rn -i 'symlink' docs/ | grep -i plugin otherwise lists only install-time links into node_modules (docs/marketplace.md:18, :242), and docs/lsp-config.md:96 says marketplace LSP config paths are "contained within the plugin root" without saying how a link is judged. So no docs change.

Left as is, found while reading. These are not covered by this change:

  • A symlinked skill directory inside a checked skills/ directory is judged by its resolved SKILL.md (isLoadableSkillFile in packages/coding-agent/src/discovery/helpers.ts:436-441), then read through the lexical path. The swap window between those two steps is the race named below.
  • Symlinked *.md files in a checked commands/ directory still load. The commands loader keeps any file a link resolves to.
  • The rules/, hooks/ and tools/ directories, read by loadRules, loadHooks and loadTools, have no containment check. They are passed to loadFilesFromDir (packages/coding-agent/src/discovery/helpers.ts:569), which has none.
  • plugin.json and marketplace.json are read through symlinks with no containment check (claude-plugins.ts:100, :510, and the marketplace reader at :123). An inline mcpServers object in a linked plugin.json loads.
  • The check and the read are separate calls. A target that changes between them is read unchecked. This covers skill files, directory scans and MCP configs.

Testing

Review round, head 6b0e1c3

Failing before the fix, on 6f5da9d5296, with the new test a declared MCP config whose target appears after the containment check is not loaded. The test makes the dangling mcp.json target appear right after the containment check resolves it as missing:

error: expect(received).toBeUndefined()

Received: {
  name: "late-mcp:escaped",
  command: "echo",
  ...
(fail) listClaudePluginRoots > a declared MCP config whose target appears after the containment check is not loaded [37.96ms]
 0 pass
 1 fail

The fallback branch assertion now names the branch warning. A local mutation that makes that branch accept the unchecked skills/ directory fails it (not committed):

Expected: true
Received: false
(fail) listClaudePluginRoots > a plugin with no skills declaration does not load a conventional skills/ symlink that points outside the plugin root

Acceptance, bun test packages/coding-agent/test/discovery/claude-plugins.test.ts on 6b0e1c3e5b3:

 26 pass
 0 fail
 54 expect() calls
Ran 26 tests across 1 file. [1462.00ms]

Discovery folder, bun test test/discovery in packages/coding-agent on 6b0e1c3e5b3: 204 pass, 0 fail, Ran 204 tests across 25 files.

Also run: bun check --no-script -p tsconfig.json in packages/coding-agent reports No type errors in 5,881 files, oxfmt --check passes and oxlint reports Found 0 warnings and 0 errors on the two changed TypeScript files. bun check for the whole repo was not run.

Earlier round, at 1013de727d (stale)

The numbers below come from an earlier round and do not match the current head.

Failing before, on the pre-fix source (1013de727d) with the new tests:

$ bun test test/discovery/claude-plugins.test.ts   (in packages/coding-agent)
error: expect(received).toBe(expected)

Expected: true
Received: false
(fail) listClaudePluginRoots > a declared skills path that cannot be resolved for a reason other than a missing file is refused [3.02ms]
error: expect(received).toBeDefined()

Received: undefined
(fail) listClaudePluginRoots > a skills path named ..shared inside the plugin root loads, and a ../ path outside it is refused [3.71ms]
 28 pass
 2 fail
exit 1

Passing after, on that round's head:

 30 pass
 0 fail
 71 expect() calls
Ran 30 tests across 1 file.
exit 0

The no-declaration fallback test (a plugin with no skills declaration does not load a conventional skills/ symlink that points outside the plugin root) passes before and after. The fallback branch already calls isWithinPluginRoot, so that test guards it against regression.

Discovery folder (bun test test/discovery): before 262 pass and 7 fail, after 264 pass and 5 fail. The 5 failures left are in other files and fail the same way on 1013de727d: agent-plugins discovery > namespaces colliding plugin skills by manifest name, stable across version bumps (#12151), three contextFiles.extra tests, and disabledExtensions runtime filtering > can include disabled context files for dashboard-style loads. This change does not cause them.

bun run --cwd=packages/coding-agent check:types: No type errors in 5,820 files, exit 0. bunx oxfmt --check on the three touched files: exit 0. bunx oxlint on them: 0 warnings, 0 errors, exit 0. bun check as a whole was not run.


  • bun check passes
  • Tested locally
  • CHANGELOG updated with the required attribution (if user-facing; internal issue fixes use issue links, external contributions add the PR link and contributor credit after creation)

…e it must not load

Skills and MCP servers reached through a manifest path, or the conventional skills
directory, are judged by their lexical path only, so a link inside the plugin root
that points outside it loads files from outside the root. Both new tests fail on
origin/main 03597e3: the outside skill and the outside MCP server both load.
…ints

isWithinPluginRoot compared lexical paths only, so a symlink inside a plugin root
(manifest skills, commands or mcpServers path, or the conventional skills
directory) pointing outside it was accepted and its skills and MCP servers
loaded. A path now passes only when it stays inside the root lexically and,
when it exists, its real path stays inside the real root. A missing path still
passes lexically, since nothing is read from it. The conventional fallback
directory is judged the same way, and a refused one warns.

Source: none (new code)
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T19:02:52.234111Z
We couldn’t complete this review. Comment @codex review to try again.
1fa373c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@roboomp roboomp added agent Agent runtime planning and orchestration fix review:p3 triaged labels Nov 24, 2026

@roboomp roboomp 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.

P3 — not ready as a containment fix. The entry-point checks help, but skill discovery still reads unchecked descendants, the conventional MCP config is unchecked, and resolution failures still permit later reads.
Keep this scoped to declared paths and checked entry points, with a narrower changelog, or enforce containment at the affected reads. Add coverage for the no-declaration skills fallback.
Verified: four focused existing skill-discovery tests passed. Thanks for the patch, @JamieJ5926.

Comment thread packages/coding-agent/CHANGELOG.md Resolved
…ds and manifest paths it covers

The line said every symlink inside a plugin root no longer loads files from outside it. The code covers less: a symlinked skills or commands directory, and a skills, commands or MCP config path declared in the plugin manifest, that points outside the plugin root. Symlinked entries under skills/, the .mcp.json fallback and the rules, hooks and tools reads are not checked; they stay in the PR body as follow-ups. Narrows the changelog line only; the code is unchanged (roboomp P3 review on 190c3e0).
@JamieJ5926 JamieJ5926 changed the title fix(coding-agent): a symlink inside a plugin root no longer loads files from outside it fix(coding-agent): a symlinked skills or commands dir, or a manifest-declared skills, commands or MCP path, outside the plugin root no longer loads Nov 24, 2026
@JamieJ5926

Copy link
Copy Markdown
Contributor Author

Narrowed the changelog line and the PR title to what the code covers. The code is unchanged: the head only changes packages/coding-agent/CHANGELOG.md on top of 190c3e0.

Title, before: fix(coding-agent): a symlink inside a plugin root no longer loads files from outside it
Title, after: fix(coding-agent): a symlinked skills or commands dir, or a manifest-declared skills, commands or MCP path, outside the plugin root no longer loads

The changelog line now covers a symlinked skills or commands directory, and a skills, commands or MCP config path declared in the plugin manifest, that points outside the plugin root.

The body follow-up list now names what is not covered: a symlinked entry inside skills/ still loads through scanSkillsFromDir (helpers.ts:530), and the .mcp.json fallback and the rules, hooks and tools reads are not checked. This takes the narrower-changelog option from the review.

… the fix

Adds three cases to claude-plugins.test.ts. Before the fix, the self-referencing skills link (ELOOP) produces no containment warning, and a skills path named ..shared is refused as outside the root. The no-declaration conventional skills/ symlink case passes on the head already; it covers the fallback branch so that branch cannot go back to loading an unchecked directory. Fixes follow in their own commits.
… other than a missing file is refused

isWithinPluginRoot used realpathIfExists, which returns null for every resolution error. A null target counted as a missing file and passed, so a declared path that failed to resolve for another reason (a symlink loop, a permission error) reached the read unchecked. Only ENOENT now passes; any other failure means the path is not contained and nothing is read. A declared MCP config that is missing keeps its existing warning.
…not a child named ..shared

isContained rejected any relative path that began with two dots, so a plugin skills directory named ..shared inside the root was refused as outside it. It now rejects only a path whose first component is the parent directory: relative equal to .. or beginning with ../.
@JamieJ5926

Copy link
Copy Markdown
Contributor Author

Follow-up to my earlier comment, which said the code was unchanged. That was wrong: the branch now has code fixes for points (a) and (b), and a test for (c). The earlier comment is superseded.

Head: 76a3e079fe. Commits on top of the wording commit 1013de727d: 789c32bf03 (the three failing-first tests), a4e918fb65 (point a), 76a3e079fe (point b).

(a) realpathIfExists returns null for every error, so a target that failed to resolve for another reason passed as if it were missing. Only ENOENT passes now.
Failing before (pre-fix source):

error: expect(received).toBe(expected)
Expected: true
Received: false
(fail) listClaudePluginRoots > a declared skills path that cannot be resolved for a reason other than a missing file is refused [3.02ms]

Passing after: (pass) listClaudePluginRoots > a declared skills path that cannot be resolved for a reason other than a missing file is refused

(b) isContained refused every relative path beginning with .., so a child named ..shared was refused. It now refuses only .. and ../....
Failing before (pre-fix source):

error: expect(received).toBeDefined()
Received: undefined
(fail) listClaudePluginRoots > a skills path named ..shared inside the plugin root loads, and a ../ path outside it is refused [3.71ms]

Passing after: the same test, which also checks that ../x is refused with the outside-root warning.

(c) New test for a plugin with no skills declaration: the conventional skills/ symlink to a directory outside the root yields no skill and emits the warning. It passes on the pre-fix source too, because the fallback branch already calls the check. The test guards that branch against regression.

Whole file, bun test test/discovery/claude-plugins.test.ts in packages/coding-agent: before 28 pass, 2 fail, exit 1; after 30 pass, 0 fail, exit 0.

The body's not-covered list now names: a symlinked entry inside a checked skills/ directory (scanSkillsFromDir still follows it), symlinked *.md files in a checked commands/ directory, the .mcp.json fallback, the rules, hooks and tools reads, plugin.json and marketplace.json read through symlinks, and the gap between the containment check and the read. The title and the changelog line are narrowed to the declared and conventional paths. The 03135b9b7c1 citation is gone.

Code review on 76a3e079fe: VERDICT: PASS.

…mcp.json outside the plugin root must not load

The skill scan and the conventional .mcp.json fallback read these paths with no containment check, so both cases fail on the PR head.
…mcp.json outside the plugin root no longer loads

scanSkillsFromDir checked a skill's SKILL.md only for existence, so a symlink inside a plugin's skills directory loaded content from outside the plugin root. The conventional .mcp.json fallback was returned with no containment check. Claude plugin skills now pass the existing isWithinPluginRoot check for each SKILL.md before it is read, and the fallback .mcp.json is refused the same way, as the Agent Plugins provider does for its skill descendants and mcp.json.
…le must not warn that it is outside the plugin root

Review of the containment fix: the check ran before the existence check, so a symlink to a regular file gave ENOTDIR on SKILL.md and warned on every discovery.
…e no longer warns that it is outside the plugin root

The containment check ran before the existence check, so a SKILL.md under a symlink to a regular file (ENOTDIR) was reported as outside the root. The check now runs only on a candidate that exists, so the entry skips silently as it did before.
# Conflicts:
#	packages/coding-agent/src/discovery/claude-plugins.ts
#	packages/coding-agent/src/discovery/contained-path.ts
… the plugin root no longer loads

The root SKILL.md branch of loadSkills scanned without the plugin-root containment check, so a symlinked root SKILL.md could load from outside the root. It now passes the same isWithinPluginRoot guard as the other skill scans.
…ands dir, or a manifest-declared skills, commands or MCP path, outside the plugin root no longer loads

Upstream rewrote claude-plugins.test.ts after the PR's merge base; its nine added tests are re-placed in the rewritten listClaudePluginRoots describe, using ctx.home. Source files merged without conflict.
JamieJ5926 added a commit to JamieJ5926/oh-my-pi that referenced this pull request Nov 29, 2026
…ands dir, or a manifest-declared skills, commands or MCP path, outside the plugin root no longer loads

Upstream rewrote claude-plugins.test.ts after the PR's merge base; its nine added tests are re-placed in the rewritten listClaudePluginRoots describe, using ctx.home. Source files merged without conflict.

Co-authored-by: Jo Hughes <284454611+JamieJ5926@users.noreply.github.com>
@JamieJ5926
JamieJ5926 force-pushed the fix/plugin-symlink-containment branch from dd04b25 to c571bff Compare November 30, 2026 22:57
… target resolves

A manifest-declared or conventional MCP config that is a dangling symlink passed the containment check, and the read then used the lexical path, so a target created in between loaded from outside the plugin root. An unresolved target is now a no-read result. A declared missing file keeps its warning, and a resolved config is read from its canonical path. Skill directories use the same resolution, so a missing one is skipped without a warning as before.

Source: none (no code copied; reuses the ContainedPathResolution type from packages/coding-agent/src/discovery/contained-path.ts)
…the checks that run

The entry read as file-level containment. The checks run at entry points: plugin directories and declared or conventional MCP configs through resolvePluginTarget in packages/coding-agent/src/discovery/claude-plugins.ts (lines 218, 227, 237, 540, 576), and each SKILL.md before it loads through isLoadableSkillFile in packages/coding-agent/src/discovery/helpers.ts (lines 436-441). The SKILL.md reads and directory scans still use the lexical path, so a check-then-read race remains and is named as a known limit.

Source: none (no code copied)
…lugin with no skills declaration

The test matched the generic outside-root text, which the skill file check also emits, so it passed when the manifest-less fallback branch in resolvePluginDir accepted an unchecked skills directory. It now asserts the branch warning Ignoring skills directory outside plugin root. A local mutation that makes that branch accept the directory fails the assertion.

Source: none (no code copied)
Wraps two assertion lines that oxfmt --check flagged in claude-plugins.test.ts. No behavior changes.

Source: none (no code copied)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Agent runtime planning and orchestration fix review:p3 triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants