Repository navigation
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
Conversation
…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)
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
roboomp
left a comment
There was a problem hiding this comment.
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.
…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).
|
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: 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 ../.
|
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: (a) Passing after: (b) Passing after: the same test, which also checks that (c) New test for a plugin with no skills declaration: the conventional Whole file, The body's not-covered list now names: a symlinked entry inside a checked Code review on |
…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.
…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>
dd04b25 to
c571bff
Compare
… 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)
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/andcommands/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.resolvePluginTargetruns a lexical check, then resolves the real target against the real root. It returnsmissing,outside, orokwith the canonical path. A declared MCP file that is missing keeps its warning.packages/coding-agent/src/discovery/contained-path.tsnow usespathIsWithinLexicalfrompackages/utils/src/dirs.ts, which accepts a child named..sharedand refuses only a parent segment.packages/coding-agent/test/discovery/claude-plugins.test.tsgains tests and a stricter branch assertion, and one CHANGELOG line now names the residual race.Why
isWithinPluginRootcompared lexical paths withpath.relativeand never resolved a symlink. Soskills -> /outsideinside a plugin root loaded/outside/escaped/SKILL.md, and anmcp.jsonlink loaded its servers (outputs below).realpathIfExistsreturns 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.isContainedalso refused a child named..shared.The Agent Plugins path already resolves links before it checks containment (
agent-plugin-format.ts,classifyUncached, with the helpers incontained-path.ts). This change reuses theContainedPathResolutionshape from those helpers.resolvePluginTargetis 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:222states 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 pluginotherwise lists only install-time links intonode_modules(docs/marketplace.md:18,:242), anddocs/lsp-config.md:96says 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:
skills/directory is judged by its resolvedSKILL.md(isLoadableSkillFileinpackages/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.*.mdfiles in a checkedcommands/directory still load. The commands loader keeps any file a link resolves to.rules/,hooks/andtools/directories, read byloadRules,loadHooksandloadTools, have no containment check. They are passed toloadFilesFromDir(packages/coding-agent/src/discovery/helpers.ts:569), which has none.plugin.jsonandmarketplace.jsonare read through symlinks with no containment check (claude-plugins.ts:100,:510, and the marketplace reader at:123). An inlinemcpServersobject in a linkedplugin.jsonloads.Testing
Review round, head 6b0e1c3
Failing before the fix, on
6f5da9d5296, with the new testa declared MCP config whose target appears after the containment check is not loaded. The test makes the danglingmcp.jsontarget appear right after the containment check resolves it as missing: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):Acceptance,
bun test packages/coding-agent/test/discovery/claude-plugins.test.tson6b0e1c3e5b3:Discovery folder,
bun test test/discoveryinpackages/coding-agenton6b0e1c3e5b3:204 pass,0 fail,Ran 204 tests across 25 files.Also run:
bun check --no-script -p tsconfig.jsoninpackages/coding-agentreportsNo type errors in 5,881 files,oxfmt --checkpasses andoxlintreportsFound 0 warnings and 0 errorson the two changed TypeScript files.bun checkfor 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:Passing after, on that round's head:
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 callsisWithinPluginRoot, 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 on1013de727d:agent-plugins discovery > namespaces colliding plugin skills by manifest name, stable across version bumps (#12151), threecontextFiles.extratests, anddisabledExtensions 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 --checkon the three touched files: exit 0.bunx oxlinton them: 0 warnings, 0 errors, exit 0.bun checkas a whole was not run.bun checkpasses