harden(plugin): enforce plugin-root containment for manifest paths#760
Merged
danielmeppiel merged 5 commits intomainfrom Apr 19, 2026
Merged
harden(plugin): enforce plugin-root containment for manifest paths#760danielmeppiel merged 5 commits intomainfrom
danielmeppiel merged 5 commits intomainfrom
Conversation
Marketplace plugin normalization (_map_plugin_artifacts) accepts custom component paths from plugin.json for agents, skills, commands, and hooks. Previously the resolver only checked existence and symlink status, so a manifest entry pointing outside the plugin directory would still be copied into .apm/. Route every manifest-controlled path through ensure_path_within(), matching the existing pattern in _read_mcp_file. Entries that escape the plugin root are skipped with a warning; in-root paths continue to work unchanged. Adds regression coverage for absolute paths, traversal sequences in both list and string forms, and the hooks string-config branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens marketplace/Claude plugin normalization by ensuring manifest-specified artifact paths cannot escape the plugin root before being copied into .apm/, aligning plugin handling with existing path-containment practices (ensure_path_within).
Changes:
- Add
_is_within_plugin()helper and apply containment checks to manifest-providedagents/skills/commandspaths and thehooksstring-config file path branch. - Add unit tests covering absolute paths,
..traversal, hooks string-config traversal, and a positive in-root case. - Add a changelog entry under Fixed for the hardening.
Show a summary per file
| File | Description |
|---|---|
src/apm_cli/deps/plugin_parser.py |
Introduces containment guard for manifest-controlled component paths during plugin artifact mapping. |
tests/unit/test_plugin_parser.py |
Adds regression tests ensuring escaped paths are rejected and legitimate in-root paths still work. |
CHANGELOG.md |
Documents the security hardening under the Unreleased Fixed section. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Apply containment + symlink check to default component branch in _resolve_sources so a plugin shipping 'agents'/'skills'/'commands'/ 'hooks' as a symlink to an external target is rejected without needing a manifest override. Add regression test. - Demote the rejected-path detail to debug logging and keep the user-facing warning generic, addressing the CodeQL clear-text logging finding on manifest-controlled values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CodeQL py/clear-text-logging-sensitive-data flagged manifest-controlled path strings flowing into _logger calls. Drop the rejected raw value and exception from logging entirely; the component name alone is enough to identify the rejected manifest field. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tightens
_map_plugin_artifactsso every manifest-controlled component path (agents,skills,commands,hooks) is verified to resolve inside the plugin root before it's copied into.apm/. Today the helper only checksexists()/is_symlink(); if a custom path points outside the plugin directory it gets copied anyway, which is inconsistent with the trust boundary we already enforce for MCP config files (_read_mcp_file) and with the rest of the codebase's use ofensure_path_within.Changes
src/apm_cli/deps/plugin_parser.py: introduce_is_within_pluginhelper that wrapsensure_path_withinwith a warning-and-skip behaviour, and apply it inside_resolve_sources(list + string forms) and thehooksstring-config branch.tests/unit/test_plugin_parser.py: newTestPathTraversalProtectionclass covering absolute paths,..traversal, and the hooks string-config branch, plus a positive case to confirm legitimate in-root paths still work.CHANGELOG.md: hardening note underFixed.Validation
uv run pytest tests/unit/test_plugin_parser.py-> 67 passed (61 existing + 6 new)uv run pytest tests/unit tests/test_console.py-> 3939 passedNotes
Behaviour change is conservative: only paths escaping the plugin root are dropped, and a warning is logged identifying the offending component. No public API changes.