cc-safe-setup 29.6.15 → 29.6.17
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/examples/disk-partition-guard.sh +61 -0
- package/examples/dns-config-guard.sh +31 -0
- package/examples/git-history-rewrite-guard.sh +61 -0
- package/examples/log-truncation-guard.sh +28 -0
- package/examples/network-interface-guard.sh +39 -0
- package/examples/user-account-guard.sh +39 -0
- package/package.json +2 -2
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# disk-partition-guard.sh — Block disk partitioning and mount operations
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude Code running disk operations that can cause data loss
|
|
5
|
+
# or system instability. Mounting/unmounting, partitioning, and
|
|
6
|
+
# formatting are irreversible on production systems.
|
|
7
|
+
#
|
|
8
|
+
# Detects:
|
|
9
|
+
# mount / umount (filesystem mount operations)
|
|
10
|
+
# fdisk / parted / gdisk (partition table editors)
|
|
11
|
+
# mkfs / mkswap (filesystem/swap creation)
|
|
12
|
+
# dd if= (raw disk writes)
|
|
13
|
+
# swapon / swapoff (swap management)
|
|
14
|
+
#
|
|
15
|
+
# Does NOT block:
|
|
16
|
+
# df / lsblk / blkid (read-only disk info)
|
|
17
|
+
# mount (no args) (list mounts)
|
|
18
|
+
#
|
|
19
|
+
# TRIGGER: PreToolUse MATCHER: "Bash"
|
|
20
|
+
|
|
21
|
+
INPUT=$(cat)
|
|
22
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
23
|
+
|
|
24
|
+
[ -z "$COMMAND" ] && exit 0
|
|
25
|
+
|
|
26
|
+
# Block partition editors
|
|
27
|
+
if echo "$COMMAND" | grep -qE '\b(fdisk|parted|gdisk|cfdisk|sfdisk)\b'; then
|
|
28
|
+
echo "BLOCKED: Disk partitioning tool detected." >&2
|
|
29
|
+
echo " Partitioning can cause irreversible data loss." >&2
|
|
30
|
+
exit 2
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# Block filesystem creation
|
|
34
|
+
if echo "$COMMAND" | grep -qE '\b(mkfs|mkswap|mke2fs)\b'; then
|
|
35
|
+
echo "BLOCKED: Filesystem creation/formatting detected." >&2
|
|
36
|
+
exit 2
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# Block mount/umount with arguments
|
|
40
|
+
if echo "$COMMAND" | grep -qE '\bumount\b|\bumount\b'; then
|
|
41
|
+
echo "BLOCKED: Unmounting filesystem can cause data loss." >&2
|
|
42
|
+
exit 2
|
|
43
|
+
fi
|
|
44
|
+
if echo "$COMMAND" | grep -qE '\bmount\s+\S' && ! echo "$COMMAND" | grep -qE '\bmount\s*$'; then
|
|
45
|
+
echo "BLOCKED: Mounting filesystem requires administrator oversight." >&2
|
|
46
|
+
exit 2
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# Block dd (raw disk writes)
|
|
50
|
+
if echo "$COMMAND" | grep -qE '\bdd\s+if='; then
|
|
51
|
+
echo "BLOCKED: Raw disk write (dd) detected." >&2
|
|
52
|
+
exit 2
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# Block swap management
|
|
56
|
+
if echo "$COMMAND" | grep -qE '\b(swapon|swapoff)\b'; then
|
|
57
|
+
echo "BLOCKED: Swap management operation detected." >&2
|
|
58
|
+
exit 2
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
exit 0
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# dns-config-guard.sh — Block DNS/hosts file modifications
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude Code modifying /etc/hosts or /etc/resolv.conf which
|
|
5
|
+
# can redirect traffic, break name resolution, or create
|
|
6
|
+
# security vulnerabilities.
|
|
7
|
+
#
|
|
8
|
+
# TRIGGER: PreToolUse MATCHER: "Bash|Edit|Write"
|
|
9
|
+
|
|
10
|
+
INPUT=$(cat)
|
|
11
|
+
TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
|
|
12
|
+
|
|
13
|
+
case "$TOOL" in
|
|
14
|
+
Bash)
|
|
15
|
+
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
16
|
+
[ -z "$CMD" ] && exit 0
|
|
17
|
+
if echo "$CMD" | grep -qE '(echo|tee|sed|awk).*(/etc/hosts|/etc/resolv\.conf|/etc/nsswitch)'; then
|
|
18
|
+
echo "BLOCKED: DNS configuration modification detected." >&2
|
|
19
|
+
exit 2
|
|
20
|
+
fi
|
|
21
|
+
;;
|
|
22
|
+
Edit|Write)
|
|
23
|
+
FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
|
|
24
|
+
if echo "$FILE" | grep -qE '/etc/hosts$|/etc/resolv\.conf$|/etc/nsswitch\.conf$'; then
|
|
25
|
+
echo "BLOCKED: Cannot modify DNS configuration file: $FILE" >&2
|
|
26
|
+
exit 2
|
|
27
|
+
fi
|
|
28
|
+
;;
|
|
29
|
+
esac
|
|
30
|
+
|
|
31
|
+
exit 0
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# git-history-rewrite-guard.sh — Block git history rewriting commands
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude Code rewriting git history which can cause permanent
|
|
5
|
+
# data loss and break shared branches. History rewriting on
|
|
6
|
+
# pushed commits requires force-push and affects all collaborators.
|
|
7
|
+
#
|
|
8
|
+
# Detects:
|
|
9
|
+
# git filter-branch (legacy history rewriter)
|
|
10
|
+
# git filter-repo (modern history rewriter)
|
|
11
|
+
# git rebase -i (interactive rebase, can reorder/squash)
|
|
12
|
+
# git reset --hard HEAD~N (discards recent commits)
|
|
13
|
+
# git reflog expire --all (destroys reflog recovery data)
|
|
14
|
+
#
|
|
15
|
+
# Does NOT block:
|
|
16
|
+
# git rebase <branch> (non-interactive, covered by no-git-rebase-public)
|
|
17
|
+
# git reset --soft (safe, keeps changes staged)
|
|
18
|
+
# git reset --mixed (safe, keeps changes in working tree)
|
|
19
|
+
# git reflog (read-only, viewing history)
|
|
20
|
+
#
|
|
21
|
+
# TRIGGER: PreToolUse MATCHER: "Bash"
|
|
22
|
+
|
|
23
|
+
INPUT=$(cat)
|
|
24
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
25
|
+
|
|
26
|
+
[ -z "$COMMAND" ] && exit 0
|
|
27
|
+
|
|
28
|
+
# Block filter-branch (legacy, dangerous)
|
|
29
|
+
if echo "$COMMAND" | grep -qE '\bgit\s+filter-branch\b'; then
|
|
30
|
+
echo "BLOCKED: git filter-branch rewrites entire repository history." >&2
|
|
31
|
+
echo " This is irreversible on shared branches." >&2
|
|
32
|
+
exit 2
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# Block filter-repo
|
|
36
|
+
if echo "$COMMAND" | grep -qE '\bgit\s+filter-repo\b'; then
|
|
37
|
+
echo "BLOCKED: git filter-repo rewrites repository history." >&2
|
|
38
|
+
exit 2
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# Block interactive rebase
|
|
42
|
+
if echo "$COMMAND" | grep -qE '\bgit\s+rebase\s+-i\b'; then
|
|
43
|
+
echo "BLOCKED: Interactive rebase can reorder, squash, or drop commits." >&2
|
|
44
|
+
echo " Use non-interactive rebase instead." >&2
|
|
45
|
+
exit 2
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Block git reset --hard with commit count
|
|
49
|
+
if echo "$COMMAND" | grep -qE '\bgit\s+reset\s+--hard\s+(HEAD|origin)'; then
|
|
50
|
+
echo "BLOCKED: git reset --hard discards commits permanently." >&2
|
|
51
|
+
echo " Use 'git reset --soft' to keep changes staged." >&2
|
|
52
|
+
exit 2
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# Block reflog destruction
|
|
56
|
+
if echo "$COMMAND" | grep -qE '\bgit\s+reflog\s+(expire|delete)\b'; then
|
|
57
|
+
echo "BLOCKED: Destroying reflog removes the safety net for recovering commits." >&2
|
|
58
|
+
exit 2
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
exit 0
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# log-truncation-guard.sh — Block log file truncation/deletion
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude Code truncating or deleting log files which destroys
|
|
5
|
+
# audit trails and makes debugging incidents impossible.
|
|
6
|
+
#
|
|
7
|
+
# Detects:
|
|
8
|
+
# > /var/log/syslog (truncation via redirect)
|
|
9
|
+
# truncate -s 0 <logfile> (explicit truncation)
|
|
10
|
+
# rm /var/log/* (log deletion)
|
|
11
|
+
# echo "" > <logfile> (content erasure)
|
|
12
|
+
#
|
|
13
|
+
# TRIGGER: PreToolUse MATCHER: "Bash"
|
|
14
|
+
|
|
15
|
+
INPUT=$(cat)
|
|
16
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
17
|
+
|
|
18
|
+
[ -z "$COMMAND" ] && exit 0
|
|
19
|
+
|
|
20
|
+
# Block log file truncation
|
|
21
|
+
if echo "$COMMAND" | grep -qE '>\s*/var/log/|truncate.*(/var/log/|\.log)|rm\s+.*(/var/log/|\.log)'; then
|
|
22
|
+
echo "BLOCKED: Log file truncation/deletion detected." >&2
|
|
23
|
+
echo " Destroying logs removes audit trails." >&2
|
|
24
|
+
echo " Use log rotation instead: logrotate." >&2
|
|
25
|
+
exit 2
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
exit 0
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# network-interface-guard.sh — Block network interface modifications
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude Code modifying network interfaces which can cause
|
|
5
|
+
# immediate loss of connectivity on remote servers.
|
|
6
|
+
#
|
|
7
|
+
# Detects:
|
|
8
|
+
# ifconfig <iface> down (disable interface)
|
|
9
|
+
# ip link set <iface> down (modern equivalent)
|
|
10
|
+
# ip addr del (remove IP address)
|
|
11
|
+
# ip route del (remove route)
|
|
12
|
+
# nmcli connection delete (NetworkManager)
|
|
13
|
+
#
|
|
14
|
+
# TRIGGER: PreToolUse MATCHER: "Bash"
|
|
15
|
+
|
|
16
|
+
INPUT=$(cat)
|
|
17
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
18
|
+
|
|
19
|
+
[ -z "$COMMAND" ] && exit 0
|
|
20
|
+
|
|
21
|
+
# Block interface disable
|
|
22
|
+
if echo "$COMMAND" | grep -qE '\bifconfig\s+\S+\s+down\b'; then
|
|
23
|
+
echo "BLOCKED: Disabling network interface will cause connectivity loss." >&2
|
|
24
|
+
exit 2
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
# Block ip link/addr/route destructive operations
|
|
28
|
+
if echo "$COMMAND" | grep -qE '\bip\s+(link\s+set\s+\S+\s+down|addr\s+del|route\s+del)\b'; then
|
|
29
|
+
echo "BLOCKED: Network configuration change can cause connectivity loss." >&2
|
|
30
|
+
exit 2
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# Block NetworkManager connection deletion
|
|
34
|
+
if echo "$COMMAND" | grep -qE '\bnmcli\s+connection\s+delete\b'; then
|
|
35
|
+
echo "BLOCKED: Deleting NetworkManager connection." >&2
|
|
36
|
+
exit 2
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
exit 0
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# user-account-guard.sh — Block user/group account modifications
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude Code creating, deleting, or modifying system user
|
|
5
|
+
# accounts which can create security backdoors or lock out
|
|
6
|
+
# legitimate users.
|
|
7
|
+
#
|
|
8
|
+
# Detects:
|
|
9
|
+
# useradd / adduser (create user)
|
|
10
|
+
# userdel / deluser (delete user)
|
|
11
|
+
# usermod (modify user)
|
|
12
|
+
# passwd (change password)
|
|
13
|
+
# groupadd / groupdel (group management)
|
|
14
|
+
# visudo / sudoers editing (privilege escalation)
|
|
15
|
+
#
|
|
16
|
+
# TRIGGER: PreToolUse MATCHER: "Bash"
|
|
17
|
+
|
|
18
|
+
INPUT=$(cat)
|
|
19
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
20
|
+
|
|
21
|
+
[ -z "$COMMAND" ] && exit 0
|
|
22
|
+
|
|
23
|
+
if echo "$COMMAND" | grep -qE '\b(useradd|adduser|userdel|deluser|usermod|groupadd|groupdel|groupmod)\b'; then
|
|
24
|
+
echo "BLOCKED: User/group account modification detected." >&2
|
|
25
|
+
echo " Creating or modifying system accounts requires administrator oversight." >&2
|
|
26
|
+
exit 2
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
if echo "$COMMAND" | grep -qE '\bpasswd\b'; then
|
|
30
|
+
echo "BLOCKED: Password change detected." >&2
|
|
31
|
+
exit 2
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
if echo "$COMMAND" | grep -qE '\bvisudo\b|/etc/sudoers'; then
|
|
35
|
+
echo "BLOCKED: Sudoers modification (privilege escalation risk)." >&2
|
|
36
|
+
exit 2
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
exit 0
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safe-setup",
|
|
3
|
-
"version": "29.6.
|
|
4
|
-
"description": "One command to make Claude Code safe.
|
|
3
|
+
"version": "29.6.17",
|
|
4
|
+
"description": "One command to make Claude Code safe. 440 example hooks + 8 built-in. 52 CLI commands. 5855 tests. Works with Auto Mode.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"cc-safe-setup": "index.mjs"
|