#23473: Hooks/Plugins: enforce discovery root containment
size: S
trusted-contributor
Cluster:
Plugin Management Enhancements
## Summary
- enforce realpath containment for hook discovery roots and discovered hook directories
- enforce allowed-root containment for plugin discovery directories to block symlink escapes
- add regression tests for workspace/global symlink escape cases in hook/plugin discovery
## Testing
- pnpm test src/hooks/workspace.test.ts src/plugins/discovery.test.ts
- pnpm check
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added symlink escape prevention for hook and plugin discovery to prevent malicious code execution via symlink attacks. The changes enforce realpath containment checks at two levels: validating discovery roots stay within allowed boundaries, and ensuring discovered entries don't escape via symlinks. Test coverage includes workspace and global symlink escape scenarios.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The security hardening is well-implemented with two-level symlink escape prevention, follows existing code patterns using `isPathInsideWithRealpath`, includes comprehensive test coverage for both workspace and global symlink scenarios, and applies defense-in-depth by checking both discovery directories and individual entries
- No files require special attention
<sub>Last reviewed commit: 32b0052</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19542: security: sandbox dynamic import in hook transforms with symlink va...
by Mozzzaic · 2026-02-17
79.1%
#21245: fix(plugins): harden symlinked extension discovery
by victorGPT · 2026-02-19
78.9%
#3564: fix(plugins): follow symlinks in plugin and hook discovery
by mollywires · 2026-01-28
78.6%
#19021: fix(hooks): reject path traversal in hook pack manifest entries dur...
by moxunjinmu · 2026-02-17
77.0%
#20424: Fix plugin extension path traversal in discovery/install
by markmusson · 2026-02-18
77.0%
#8846: fix(tools): block LLM writes to hooks directories
by yubrew · 2026-02-04
75.8%
#23294: fix(security): OC-201 Hook Transform RCE - Symlink-Safe Path Contai...
by aether-ai-agent · 2026-02-22
74.8%
#14112: test(security): harden plugin install against script execution
by davidahmann · 2026-02-11
73.7%
#21660: fix(plugins): require explicit allowlist for non-bundled plugins
by AI-Reviewer-QS · 2026-02-20
72.9%
#6405: feat(security): Add HTTP API security hooks for plugin scanning
by masterfung · 2026-02-01
72.6%