#19021: fix(hooks): reject path traversal in hook pack manifest entries during install
size: XS
Cluster:
Plugin Management Enhancements
## Problem
The `installHookPackageFromDir` function in `src/hooks/install.ts` resolves `openclaw.hooks[]` entries from the package manifest via `path.resolve(params.packageDir, entry)` without verifying the resolved path stays within the package directory. A crafted hook pack can reference `../outside` or absolute paths to load and execute arbitrary code from outside the package root.
This is a path traversal vulnerability (CWE-22) with CVSS 7.8 (High).
Note: `src/hooks/workspace.ts` already has a `resolveContainedDir` guard for the same pattern — this fix closes the gap in the install path.
Closes #18922
## Solution
Added a path containment check in `installHookPackageFromDir` that validates each resolved hook entry stays within `params.packageDir` using `path.relative`. Entries that escape the package directory are rejected with a clear error message.
## Test Plan
- Added regression test in `install.test.ts`: creates a hook pack with `../outside` in `openclaw.hooks[]` and verifies the install is rejected with "path traversal" error
- All 12 tests in `install.test.ts` pass
- All 2 tests in `workspace.test.ts` pass (no regression)
- Verified with `npx vitest run src/hooks/install.test.ts src/hooks/workspace.test.ts`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added path traversal validation to `installHookPackageFromDir` in `src/hooks/install.ts:216-222` to prevent malicious hook packs from loading code outside the package directory. The fix validates each `openclaw.hooks[]` entry using `path.relative` to ensure the resolved path stays within `params.packageDir`, matching the existing pattern from `resolveContainedDir` in `workspace.ts:55-63`.
- Closes a CWE-22 path traversal vulnerability where crafted manifests could reference `../outside` or absolute paths
- Added regression test validating the fix rejects traversal attempts with clear error messages
- Implementation is consistent with existing security patterns across the codebase
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The security fix correctly addresses a path traversal vulnerability using a well-established pattern from workspace.ts, includes comprehensive test coverage, and has no logical flaws or edge case issues
- No files require special attention
<sub>Last reviewed commit: 72af1ff</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23294: fix(security): OC-201 Hook Transform RCE - Symlink-Safe Path Contai...
by aether-ai-agent · 2026-02-22
79.3%
#11339: fix: resolve bundled hooks path on npm global install
by matthewpoe · 2026-02-07
79.1%
#20424: Fix plugin extension path traversal in discovery/install
by markmusson · 2026-02-18
78.9%
#11817: fix(build): compile bundled hook handlers into dist
by AnonO6 · 2026-02-08
77.3%
#23473: Hooks/Plugins: enforce discovery root containment
by bmendonca3 · 2026-02-22
77.0%
#8846: fix(tools): block LLM writes to hooks directories
by yubrew · 2026-02-04
77.0%
#11432: fix(security): add --ignore-scripts to npm install in hook and plug...
by coygeek · 2026-02-07
76.9%
#9914: fix(hooks): resolve bundled hook dist paths and packaging checks
by zimmra · 2026-02-05
76.3%
#21954: Prevent bootstrap hook truncation crash in prompt report
by graysurf · 2026-02-20
75.9%
#21039: Fix npm-spec plugin installs when npm pack output is empty
by graysurf · 2026-02-19
75.5%