Commit 5f5f5d9
fix: harden example hook validation scripts against bypass attacks (#164)
## Summary
Hardens the example hook validation scripts to prevent security bypass
patterns that users might inadvertently copy when creating their own
hooks.
## Problem
Fixes #161
The example hook validation scripts in
`skills/hook-development/examples/` had security gaps:
1. **validate-bash.sh**: The "safe command" allowlist (ls, pwd, echo,
etc.) could be bypassed with command chaining:
- `echo $(rm -rf /)` - command substitution
- `ls; rm -rf /` - semicolon chaining
- `pwd && malicious` - AND chaining
2. **validate-write.sh**: The path traversal check only detected literal
`..` without documenting limitations like URL-encoding or symlink
traversal.
## Solution
### validate-bash.sh
Added command chaining detection **before** the safe command allowlist:
- Checks for `;`, `|`, `$(`, `` ` ``, `&&`, `||`
- Returns `"permissionDecision": "ask"` to require user review
- Added comment explaining this is the critical ordering
### validate-write.sh
Added comprehensive documentation about limitations:
- Notes that literal `..` check doesn't catch URL-encoded or symlink
traversal
- Provides guidance for production hardening using `realpath`
- Suggests comparing against allowed directory prefixes
### Alternatives Considered
1. **More comprehensive bash validation** - Could add newline, null
byte, and shell-specific syntax detection. Decided against to keep
examples teachable rather than production-ready.
2. **Add realpath resolution to validate-write.sh** - Decided
documentation is more appropriate for an example script, as realpath
behavior varies across systems.
## Changes
-
`plugins/plugin-dev/skills/hook-development/examples/validate-bash.sh`:
Added command chaining detection block with explanatory comments
-
`plugins/plugin-dev/skills/hook-development/examples/validate-write.sh`:
Added documentation comments about path traversal limitations
## Testing
- [x] Verified semicolon chaining now caught: `echo '{"tool_input":
{"command": "echo; malicious"}}' | bash validate-bash.sh` → exit 2
- [x] Verified simple commands still pass: `echo '{"tool_input":
{"command": "echo hello"}}' | bash validate-bash.sh` → exit 0
- [x] shellcheck passes on both modified scripts
- [x] markdownlint passes on related documentation
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 444ed21 commit 5f5f5d9
3 files changed
Lines changed: 28 additions & 0 deletions
File tree
- plugins/plugin-dev/skills/hook-development
- examples
- references
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
19 | 32 | | |
| 33 | + | |
20 | 34 | | |
21 | 35 | | |
22 | 36 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
111 | 118 | | |
112 | 119 | | |
113 | 120 | | |
| |||
0 commit comments