cc-safe-setup 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/examples/README.md +2 -1
- package/examples/block-database-wipe.sh +6 -0
- package/examples/path-traversal-guard.sh +44 -0
- package/index.mjs +5 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -159,11 +159,13 @@ Or browse all available examples in [`examples/`](examples/):
|
|
|
159
159
|
- **env-var-check.sh** — Block hardcoded API keys (sk-, ghp_, glpat-) in export commands
|
|
160
160
|
- **timeout-guard.sh** — Warn before long-running commands (npm start, rails s, docker-compose up)
|
|
161
161
|
- **branch-name-check.sh** — Warn on non-conventional branch names (feature/, fix/, etc.)
|
|
162
|
+
- **todo-check.sh** — Warn when committing files with TODO/FIXME/HACK markers
|
|
163
|
+
- **path-traversal-guard.sh** — Block Edit/Write with `../../` path traversal and system directories
|
|
162
164
|
|
|
163
165
|
## Learn More
|
|
164
166
|
|
|
165
167
|
- [Official Hooks Reference](https://code.claude.com/docs/en/hooks) — Claude Code hooks documentation
|
|
166
|
-
- [Hooks Cookbook](https://github.com/yurukusa/claude-code-hooks/blob/main/COOKBOOK.md) —
|
|
168
|
+
- [Hooks Cookbook](https://github.com/yurukusa/claude-code-hooks/blob/main/COOKBOOK.md) — 18 ready-to-use recipes from real GitHub Issues
|
|
167
169
|
- [Japanese guide (Qiita)](https://qiita.com/yurukusa/items/a9714b33f5d974e8f1e8) — この記事の日本語解説
|
|
168
170
|
- [The incident that inspired this tool](https://github.com/anthropics/claude-code/issues/36339) — NTFS junction rm -rf
|
|
169
171
|
|
package/examples/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Example Hooks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
25 hooks beyond the 8 built-in ones, organized by category.
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
@@ -22,6 +22,7 @@ npx cc-safe-setup --examples
|
|
|
22
22
|
| **env-var-check.sh** | Block hardcoded API keys in export commands | |
|
|
23
23
|
| **git-config-guard.sh** | Block git config --global | [#37201](https://github.com/anthropics/claude-code/issues/37201) |
|
|
24
24
|
| **network-guard.sh** | Warn on suspicious network commands | [#37420](https://github.com/anthropics/claude-code/issues/37420) |
|
|
25
|
+
| **path-traversal-guard.sh** | Block Edit/Write with ../ path traversal | |
|
|
25
26
|
| **protect-dotfiles.sh** | Block changes to ~/.bashrc, ~/.aws/, ~/.ssh/ | [#37478](https://github.com/anthropics/claude-code/issues/37478) |
|
|
26
27
|
| **scope-guard.sh** | Block operations outside project directory | [#36233](https://github.com/anthropics/claude-code/issues/36233) |
|
|
27
28
|
| **test-before-push.sh** | Block git push without tests | [#36970](https://github.com/anthropics/claude-code/issues/36970) |
|
|
@@ -61,6 +61,12 @@ if echo "$COMMAND" | grep -qiE 'DROP\s+(DATABASE|TABLE|SCHEMA)|TRUNCATE\s+TABLE|
|
|
|
61
61
|
exit 2
|
|
62
62
|
fi
|
|
63
63
|
|
|
64
|
+
# Symfony/Doctrine destructive commands
|
|
65
|
+
if echo "$COMMAND" | grep -qiE 'doctrine:(fixtures:load|schema:drop|database:drop)' && ! echo "$COMMAND" | grep -qE '\-\-append'; then
|
|
66
|
+
echo "BLOCKED: Destructive Doctrine command (use --append for fixtures:load)" >&2
|
|
67
|
+
exit 2
|
|
68
|
+
fi
|
|
69
|
+
|
|
64
70
|
# Prisma destructive commands
|
|
65
71
|
if echo "$COMMAND" | grep -qiE 'prisma\s+migrate\s+reset|prisma\s+db\s+push\s+--force-reset'; then
|
|
66
72
|
echo "BLOCKED: Destructive Prisma database command" >&2
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# path-traversal-guard.sh — Block path traversal in Edit/Write operations
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude writing files using ../../../ to escape the project
|
|
5
|
+
# directory via Edit/Write tools (not caught by scope-guard which
|
|
6
|
+
# only watches Bash commands).
|
|
7
|
+
#
|
|
8
|
+
# Usage: Add to settings.json as a PreToolUse hook
|
|
9
|
+
#
|
|
10
|
+
# {
|
|
11
|
+
# "hooks": {
|
|
12
|
+
# "PreToolUse": [{
|
|
13
|
+
# "matcher": "Edit|Write",
|
|
14
|
+
# "hooks": [{ "type": "command", "command": "~/.claude/hooks/path-traversal-guard.sh" }]
|
|
15
|
+
# }]
|
|
16
|
+
# }
|
|
17
|
+
# }
|
|
18
|
+
|
|
19
|
+
INPUT=$(cat)
|
|
20
|
+
TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
|
|
21
|
+
FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
|
|
22
|
+
|
|
23
|
+
[[ "$TOOL" != "Edit" && "$TOOL" != "Write" ]] && exit 0
|
|
24
|
+
[[ -z "$FILE" ]] && exit 0
|
|
25
|
+
|
|
26
|
+
# Block path traversal patterns
|
|
27
|
+
if echo "$FILE" | grep -qE '\.\./\.\./|/\.\.\./'; then
|
|
28
|
+
echo "BLOCKED: Path traversal detected: $FILE" >&2
|
|
29
|
+
exit 2
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
# Block writing to system directories
|
|
33
|
+
if echo "$FILE" | grep -qE '^/(etc|usr|bin|sbin|var|boot|proc|sys)/'; then
|
|
34
|
+
echo "BLOCKED: Cannot write to system directory: $FILE" >&2
|
|
35
|
+
exit 2
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
# Block writing to other users' home directories
|
|
39
|
+
if echo "$FILE" | grep -qE '^/home/[^/]+/' && ! echo "$FILE" | grep -qE "^$HOME/"; then
|
|
40
|
+
echo "BLOCKED: Cannot write to another user's directory: $FILE" >&2
|
|
41
|
+
exit 2
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
exit 0
|
package/index.mjs
CHANGED
|
@@ -79,7 +79,7 @@ if (HELP) {
|
|
|
79
79
|
npx cc-safe-setup --verify Test each hook with sample inputs
|
|
80
80
|
npx cc-safe-setup --dry-run Preview without installing
|
|
81
81
|
npx cc-safe-setup --uninstall Remove all installed hooks
|
|
82
|
-
npx cc-safe-setup --examples List
|
|
82
|
+
npx cc-safe-setup --examples List 25 example hooks (5 categories)
|
|
83
83
|
npx cc-safe-setup --install-example <name> Install a specific example
|
|
84
84
|
npx cc-safe-setup --help Show this help
|
|
85
85
|
|
|
@@ -185,8 +185,8 @@ function status() {
|
|
|
185
185
|
'auto-approve-git-read.sh', 'auto-approve-python.sh', 'auto-approve-ssh.sh',
|
|
186
186
|
'auto-checkpoint.sh', 'auto-snapshot.sh', 'block-database-wipe.sh', 'branch-name-check.sh', 'commit-message-check.sh', 'env-var-check.sh',
|
|
187
187
|
'deploy-guard.sh', 'edit-guard.sh', 'enforce-tests.sh', 'git-config-guard.sh',
|
|
188
|
-
'large-file-guard.sh', 'network-guard.sh', 'notify-waiting.sh',
|
|
189
|
-
'protect-dotfiles.sh', 'scope-guard.sh', 'test-before-push.sh', 'timeout-guard.sh',
|
|
188
|
+
'large-file-guard.sh', 'network-guard.sh', 'notify-waiting.sh', 'path-traversal-guard.sh',
|
|
189
|
+
'protect-dotfiles.sh', 'scope-guard.sh', 'test-before-push.sh', 'timeout-guard.sh', 'todo-check.sh',
|
|
190
190
|
];
|
|
191
191
|
const installedExamples = exampleFiles.filter(f => existsSync(join(HOOKS_DIR, f)));
|
|
192
192
|
if (installedExamples.length > 0) {
|
|
@@ -283,6 +283,7 @@ function examples() {
|
|
|
283
283
|
'deploy-guard.sh': 'Block deploy when uncommitted changes exist',
|
|
284
284
|
'env-var-check.sh': 'Block hardcoded API keys in export commands',
|
|
285
285
|
'network-guard.sh': 'Warn on suspicious network commands (data exfiltration)',
|
|
286
|
+
'path-traversal-guard.sh': 'Block Edit/Write with path traversal (../../)',
|
|
286
287
|
'protect-dotfiles.sh': 'Block modifications to ~/.bashrc, ~/.aws/, ~/.ssh/',
|
|
287
288
|
'scope-guard.sh': 'Block file operations outside project directory',
|
|
288
289
|
'test-before-push.sh': 'Block git push when tests have not passed',
|
|
@@ -315,7 +316,7 @@ function examples() {
|
|
|
315
316
|
|
|
316
317
|
console.log();
|
|
317
318
|
console.log(c.bold + ' cc-safe-setup --examples' + c.reset);
|
|
318
|
-
console.log(c.dim + '
|
|
319
|
+
console.log(c.dim + ' 25 hooks beyond the 8 built-in ones' + c.reset);
|
|
319
320
|
console.log();
|
|
320
321
|
|
|
321
322
|
for (const [cat, hooks] of Object.entries(CATEGORIES)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safe-setup",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "One command to make Claude Code safe for autonomous operation. 8 built-in hooks +
|
|
3
|
+
"version": "2.0.7",
|
|
4
|
+
"description": "One command to make Claude Code safe for autonomous operation. 8 built-in hooks + 25 installable examples. Destructive blocker, branch guard, database wipe protection, dotfile guard, and more.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"cc-safe-setup": "index.mjs"
|