@jeremyy_prt/cc-config 1.0.0
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 +159 -0
- package/agents/corriger-orthographe.md +49 -0
- package/agents/explorer-code.md +63 -0
- package/agents/explorer-docs.md +87 -0
- package/agents/recherche-web.md +46 -0
- package/cli.js +213 -0
- package/commands/commit.md +47 -0
- package/commands/corriger-orthographe.md +59 -0
- package/commands/creer-agent.md +126 -0
- package/commands/creer-commande.md +225 -0
- package/commands/liste-commande.md +103 -0
- package/commands/memoire-claude.md +190 -0
- package/commands/surveiller-ci.md +65 -0
- package/package.json +44 -0
- package/scripts/statusline/CLAUDE.md +178 -0
- package/scripts/statusline/README.md +105 -0
- package/scripts/statusline/biome.json +34 -0
- package/scripts/statusline/bun.lockb +0 -0
- package/scripts/statusline/data/.gitignore +5 -0
- package/scripts/statusline/fixtures/test-input.json +25 -0
- package/scripts/statusline/package.json +21 -0
- package/scripts/statusline/src/commands/CLAUDE.md +3 -0
- package/scripts/statusline/src/commands/spend-month.ts +60 -0
- package/scripts/statusline/src/commands/spend-today.ts +42 -0
- package/scripts/statusline/src/index.ts +199 -0
- package/scripts/statusline/src/lib/context.ts +103 -0
- package/scripts/statusline/src/lib/formatters.ts +218 -0
- package/scripts/statusline/src/lib/git.ts +100 -0
- package/scripts/statusline/src/lib/spend.ts +119 -0
- package/scripts/statusline/src/lib/types.ts +25 -0
- package/scripts/statusline/src/lib/usage-limits.ts +147 -0
- package/scripts/statusline/statusline.config.ts +125 -0
- package/scripts/statusline/test.ts +20 -0
- package/scripts/statusline/tsconfig.json +27 -0
- package/scripts/validate-command.js +707 -0
- package/scripts/validate-command.readme.md +283 -0
- package/settings.json +42 -0
- package/song/finish.mp3 +0 -0
- package/song/need-human.mp3 +0 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# Claude Code Security Hooks - Command Validation System
|
|
2
|
+
|
|
3
|
+
A comprehensive command validation system that protects against harmful shell commands in Claude Code using PreToolUse hooks.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This security system automatically validates all Bash commands before execution, blocking dangerous operations like:
|
|
8
|
+
- System destruction (rm -rf, dd, mkfs)
|
|
9
|
+
- Privilege escalation (sudo, passwd, chmod)
|
|
10
|
+
- Command injection (; && || | `)
|
|
11
|
+
- Remote code execution (wget|bash, curl|sh)
|
|
12
|
+
- Network attacks (nc, nmap, ssh-keygen)
|
|
13
|
+
- Sensitive file access (/etc/passwd, /etc/shadow)
|
|
14
|
+
- And 50+ other dangerous patterns
|
|
15
|
+
|
|
16
|
+
## Components
|
|
17
|
+
|
|
18
|
+
### 1. Validation Script
|
|
19
|
+
- **File:** `validate-command.js`
|
|
20
|
+
- **Function:** Bun script that validates commands against comprehensive security rules
|
|
21
|
+
- **Dependencies:** None (standalone bun script)
|
|
22
|
+
- **Exit Codes:** 0 = allow, 1 = block
|
|
23
|
+
|
|
24
|
+
### 2. Hook Configuration
|
|
25
|
+
- **File:** `settings.json`
|
|
26
|
+
- **Section:** `hooks.PreToolUse`
|
|
27
|
+
- **Trigger:** Before any Bash tool execution
|
|
28
|
+
- **Action:** Calls validation script with command data
|
|
29
|
+
|
|
30
|
+
### 3. Command Interface
|
|
31
|
+
- **File:** `commands/before-tools.md`
|
|
32
|
+
- **Purpose:** Manual testing and management interface
|
|
33
|
+
- **Usage:** Run `/before-tools` in Claude Code
|
|
34
|
+
|
|
35
|
+
### 4. Security Logging
|
|
36
|
+
- **File:** `security.log`
|
|
37
|
+
- **Format:** JSON logs with timestamps, commands, violations, severity
|
|
38
|
+
- **Retention:** Persistent (manual cleanup required)
|
|
39
|
+
|
|
40
|
+
## How It Works
|
|
41
|
+
|
|
42
|
+
1. **User triggers Bash command** in Claude Code
|
|
43
|
+
2. **PreToolUse hook fires** before command execution
|
|
44
|
+
3. **Validation script receives** JSON input with command details
|
|
45
|
+
4. **Security rules evaluate** command against threat patterns
|
|
46
|
+
5. **Decision made:** Allow (exit 0) or Block (exit 1)
|
|
47
|
+
6. **Event logged** to security.log
|
|
48
|
+
7. **Command executes** or error shown to user
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
The system is already installed and active in your Claude Code configuration:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"hooks": {
|
|
57
|
+
"PreToolUse": [
|
|
58
|
+
{
|
|
59
|
+
"matcher": "Bash",
|
|
60
|
+
"hooks": [
|
|
61
|
+
{
|
|
62
|
+
"type": "command",
|
|
63
|
+
"command": "bun /Users/melvynx/.claude/validate-command.js"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Testing
|
|
73
|
+
|
|
74
|
+
### Manual Testing
|
|
75
|
+
|
|
76
|
+
Use the `/before-tools` command in Claude Code for interactive testing, or run tests manually:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Test safe command (should pass)
|
|
80
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"ls -la"}}' | bun validate-command.js
|
|
81
|
+
|
|
82
|
+
# Test dangerous command (should be blocked)
|
|
83
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"rm -rf /"}}' | bun validate-command.js
|
|
84
|
+
|
|
85
|
+
# Test command injection (should be blocked)
|
|
86
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"ls; rm -rf *"}}' | bun validate-command.js
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Test Results
|
|
90
|
+
```bash
|
|
91
|
+
# Safe command output
|
|
92
|
+
Command validation passed
|
|
93
|
+
[SECURITY] ALLOWED: ls -la
|
|
94
|
+
|
|
95
|
+
# Dangerous command output (to stderr)
|
|
96
|
+
[SECURITY] BLOCKED: rm -rf /
|
|
97
|
+
Command validation failed: Critical dangerous command: rm, Dangerous pattern detected: rm\s+.*(-rf|--recursive.*--force)
|
|
98
|
+
Severity: CRITICAL
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Security Rules Database
|
|
102
|
+
|
|
103
|
+
### Critical Commands (Always Blocked)
|
|
104
|
+
- `rm`, `del`, `format`, `mkfs`, `shred`, `dd`
|
|
105
|
+
- `fdisk`, `parted`, `gparted`, `cfdisk`
|
|
106
|
+
|
|
107
|
+
### Privilege Escalation (Always Blocked)
|
|
108
|
+
- `sudo`, `su`, `passwd`, `chpasswd`, `usermod`
|
|
109
|
+
- `chmod`, `chown`, `chgrp`, `setuid`, `setgid`
|
|
110
|
+
|
|
111
|
+
### Network/Remote Access (Always Blocked)
|
|
112
|
+
- `nc`, `netcat`, `nmap`, `telnet`, `ssh-keygen`
|
|
113
|
+
- `iptables`, `ufw`, `firewall-cmd`, `ipfw`
|
|
114
|
+
|
|
115
|
+
### System Services (Always Blocked)
|
|
116
|
+
- `systemctl`, `service`, `kill`, `killall`, `pkill`
|
|
117
|
+
- `mount`, `umount`, `swapon`, `swapoff`
|
|
118
|
+
|
|
119
|
+
### Pattern Detection (50+ Regex Rules)
|
|
120
|
+
- File system destruction: `/rm\s+.*(-rf|--recursive.*--force)/i`
|
|
121
|
+
- Fork bombs: `/:\(\)\{\s*:\|:&\s*\};:/`
|
|
122
|
+
- Command injection: `/;\s*(rm|dd|mkfs|format)/i`
|
|
123
|
+
- Remote execution: `/\|\s*(sh|bash|zsh|fish)$/i`
|
|
124
|
+
- Sensitive files: `/cat\s+\/etc\/(passwd|shadow|sudoers)/i`
|
|
125
|
+
- And many more...
|
|
126
|
+
|
|
127
|
+
### Shell Metacharacters
|
|
128
|
+
Blocks dangerous usage of: `;` `&` `|` `` ` `` `$` `(` `)` `{` `}` `[` `]` `<` `>` `*` `?` `~` `!`
|
|
129
|
+
|
|
130
|
+
## Security Logging
|
|
131
|
+
|
|
132
|
+
All validation events are logged to `security.log` in JSON format:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"timestamp": "2025-07-15T04:58:16.099Z",
|
|
137
|
+
"sessionId": null,
|
|
138
|
+
"toolName": "Bash",
|
|
139
|
+
"command": "rm -rf /",
|
|
140
|
+
"blocked": true,
|
|
141
|
+
"severity": "CRITICAL",
|
|
142
|
+
"violations": [
|
|
143
|
+
"Critical dangerous command: rm",
|
|
144
|
+
"Dangerous pattern detected: rm\\s+.*(-rf|--recursive.*--force)"
|
|
145
|
+
],
|
|
146
|
+
"source": "claude-code-hook"
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Log Analysis
|
|
151
|
+
```bash
|
|
152
|
+
# View recent security events
|
|
153
|
+
tail -f security.log
|
|
154
|
+
|
|
155
|
+
# Count blocked commands by severity
|
|
156
|
+
cat security.log | jq '.severity' | sort | uniq -c
|
|
157
|
+
|
|
158
|
+
# Find all blocked rm commands
|
|
159
|
+
cat security.log | jq 'select(.command | contains("rm"))'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Maintenance
|
|
163
|
+
|
|
164
|
+
### Log Rotation
|
|
165
|
+
```bash
|
|
166
|
+
# Archive old logs (monthly recommended)
|
|
167
|
+
mv security.log security-$(date +%Y%m).log
|
|
168
|
+
|
|
169
|
+
# Or clear logs (lose audit trail)
|
|
170
|
+
> security.log
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Rule Updates
|
|
174
|
+
Edit `validate-command.js` to modify security rules:
|
|
175
|
+
- Add new dangerous commands to `SECURITY_RULES.CRITICAL_COMMANDS`
|
|
176
|
+
- Add new regex patterns to `SECURITY_RULES.DANGEROUS_PATTERNS`
|
|
177
|
+
- Modify severity levels or validation logic
|
|
178
|
+
|
|
179
|
+
### Performance
|
|
180
|
+
- Script executes in ~50ms per validation
|
|
181
|
+
- No noticeable impact on Claude Code performance
|
|
182
|
+
- Logs grow ~200 bytes per validation event
|
|
183
|
+
|
|
184
|
+
## Advanced Configuration
|
|
185
|
+
|
|
186
|
+
### Whitelist Override
|
|
187
|
+
To allow specific dangerous commands in controlled scenarios, modify the `isExplicitlyAllowed()` function:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
isExplicitlyAllowed(command, allowedPatterns = []) {
|
|
191
|
+
// Add custom whitelist logic here
|
|
192
|
+
if (command === "sudo systemctl restart myapp") {
|
|
193
|
+
return true; // Allow this specific command
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Custom Severity Levels
|
|
200
|
+
Modify severity calculation in `validate()` method:
|
|
201
|
+
|
|
202
|
+
```javascript
|
|
203
|
+
// Add custom severity rules
|
|
204
|
+
if (command.includes("production")) {
|
|
205
|
+
result.severity = 'CRITICAL'; // Extra protection for production
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Integration with External Systems
|
|
210
|
+
The validation script can be extended to integrate with:
|
|
211
|
+
- SIEM systems (Splunk, ELK)
|
|
212
|
+
- Alerting platforms (PagerDuty, Slack)
|
|
213
|
+
- Audit databases
|
|
214
|
+
- Corporate security tools
|
|
215
|
+
|
|
216
|
+
## Troubleshooting
|
|
217
|
+
|
|
218
|
+
### Hook Not Working
|
|
219
|
+
1. **Check hook configuration:**
|
|
220
|
+
```bash
|
|
221
|
+
cat settings.json | grep -A 10 "PreToolUse"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
2. **Verify script permissions:**
|
|
225
|
+
```bash
|
|
226
|
+
ls -la validate-command.js
|
|
227
|
+
chmod +x validate-command.js # If needed
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
3. **Test script directly:**
|
|
231
|
+
```bash
|
|
232
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | bun validate-command.js
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Performance Issues
|
|
236
|
+
- Check log file size: `du -h security.log`
|
|
237
|
+
- Rotate logs if >10MB
|
|
238
|
+
- Monitor script execution time in Claude Code debug output
|
|
239
|
+
|
|
240
|
+
### False Positives
|
|
241
|
+
If safe commands are being blocked:
|
|
242
|
+
1. Check the specific violation in logs
|
|
243
|
+
2. Modify regex patterns if too broad
|
|
244
|
+
3. Add whitelist exceptions for specific use cases
|
|
245
|
+
|
|
246
|
+
## Security Considerations
|
|
247
|
+
|
|
248
|
+
### Limitations
|
|
249
|
+
- Only validates Bash commands (other tools bypass validation)
|
|
250
|
+
- Regex-based detection can have false positives/negatives
|
|
251
|
+
- Local execution means user could disable hooks
|
|
252
|
+
- No protection against social engineering
|
|
253
|
+
|
|
254
|
+
### Best Practices
|
|
255
|
+
- Regularly review security logs
|
|
256
|
+
- Update threat patterns based on new attack vectors
|
|
257
|
+
- Use principle of least privilege in permissions
|
|
258
|
+
- Combine with other security layers (user training, system hardening)
|
|
259
|
+
- Monitor for attempts to disable or bypass the validation system
|
|
260
|
+
|
|
261
|
+
### Threat Model
|
|
262
|
+
This system protects against:
|
|
263
|
+
- ✅ Accidental destructive commands
|
|
264
|
+
- ✅ Basic command injection attacks
|
|
265
|
+
- ✅ Common malware/script patterns
|
|
266
|
+
- ✅ Privilege escalation attempts
|
|
267
|
+
- ❌ Advanced persistent threats
|
|
268
|
+
- ❌ Zero-day exploits
|
|
269
|
+
- ❌ Social engineering
|
|
270
|
+
- ❌ Hardware/firmware attacks
|
|
271
|
+
|
|
272
|
+
## Support
|
|
273
|
+
|
|
274
|
+
For issues or enhancements:
|
|
275
|
+
1. Check security logs for specific error details
|
|
276
|
+
2. Test validation logic manually using test commands
|
|
277
|
+
3. Review Claude Code hooks documentation
|
|
278
|
+
4. Modify security rules as needed for your environment
|
|
279
|
+
|
|
280
|
+
## Version History
|
|
281
|
+
|
|
282
|
+
- **v1.0** - Initial implementation with comprehensive security rules
|
|
283
|
+
- **Features:** 50+ threat patterns, JSON logging, Bun execution, PreToolUse integration
|
package/settings.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "Bash",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "bun /Users/jeremy/.claude/scripts/validate-command.js"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"Stop": [
|
|
15
|
+
{
|
|
16
|
+
"matcher": "",
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "afplay -v 0.1 /Users/jeremy/.claude/song/finish.mp3"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"Notification": [
|
|
26
|
+
{
|
|
27
|
+
"matcher": "",
|
|
28
|
+
"hooks": [
|
|
29
|
+
{
|
|
30
|
+
"type": "command",
|
|
31
|
+
"command": "afplay -v 0.1 /Users/jeremy/.claude/song/need-human.mp3"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"statusLine": {
|
|
38
|
+
"type": "command",
|
|
39
|
+
"command": "bun /Users/jeremy/.claude/scripts/statusline/src/index.ts",
|
|
40
|
+
"padding": 0
|
|
41
|
+
}
|
|
42
|
+
}
|
package/song/finish.mp3
ADDED
|
Binary file
|
|
Binary file
|