hooks: Globale Bash-Sicherheitsprüfungen hinzufügen

pre-bash-checks.sh als PreToolUse-Hook auf Bash:
- Blockiert direkten git commit auf main (Pflicht: Feature-Branch)
- Blockiert apt mit -y Flag (verboten, User soll selbst bestätigen)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-04 10:36:40 +02:00
co-authored by Claude Sonnet 4.6
parent 8839d8f83e
commit fa89f8963f
2 changed files with 85 additions and 2 deletions
+68 -2
View File
@@ -7,11 +7,75 @@
"WebSearch", "WebSearch",
"Bash(npm install)", "Bash(npm install)",
"Bash(ls:*)", "Bash(ls:*)",
"Bash(python3:*)" "Bash(python3:*)",
"Read(/home/martin/.claude/**)",
"Bash(find *)",
"Bash(cat *)",
"Bash(git log*)",
"Bash(git diff*)",
"Bash(git status*)",
"Bash(git show*)",
"Bash(git branch*)",
"mcp__gitea__get_me",
"mcp__gitea__get_file_contents",
"mcp__gitea__get_dir_contents",
"mcp__gitea__get_commit",
"mcp__gitea__get_latest_release",
"mcp__gitea__get_release",
"mcp__gitea__get_tag",
"mcp__gitea__get_repository_tree",
"mcp__gitea__get_user_orgs",
"mcp__gitea__get_gitea_mcp_server_version",
"mcp__gitea__list_branches",
"mcp__gitea__list_commits",
"mcp__gitea__list_issues",
"mcp__gitea__list_my_repos",
"mcp__gitea__list_org_repos",
"mcp__gitea__list_pull_requests",
"mcp__gitea__list_releases",
"mcp__gitea__list_tags",
"mcp__gitea__issue_read",
"mcp__gitea__label_read",
"mcp__gitea__milestone_read",
"mcp__gitea__pull_request_read",
"mcp__gitea__search_issues",
"mcp__gitea__search_org_teams",
"mcp__gitea__search_repos",
"mcp__gitea__search_users",
"mcp__gitea__timetracking_read",
"mcp__gitea__wiki_read",
"mcp__gitea__actions_config_read",
"mcp__gitea__actions_run_read",
"Bash(jq *)",
"mcp__gitea__pull_request_write",
"mcp__gitea__pull_request_review_write",
"mcp__gitea__issue_write",
"mcp__plugin_context7_context7__query-docs",
"mcp__plugin_context7_context7__resolve-library-id",
"Bash(git checkout *)",
"Bash(git add *)",
"Bash(git commit *)",
"Bash(git push *)",
"Bash(git stash *)",
"Bash(docker compose *)",
"Bash(docker *)",
"Bash(which *)"
], ],
"defaultMode": "default" "defaultMode": "default"
}, },
"hooks": { "hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "bash /mnt/projekte/claude-workflow/hooks/pre-bash-checks.sh",
"statusMessage": "Prüfe Bash-Sicherheitsregeln..."
}
]
}
],
"PostToolUse": [ "PostToolUse": [
{ {
"matcher": "Edit|Write", "matcher": "Edit|Write",
@@ -46,5 +110,7 @@
"code-simplifier@claude-plugins-official": true, "code-simplifier@claude-plugins-official": true,
"skill-creator@claude-plugins-official": true "skill-creator@claude-plugins-official": true
}, },
"language": "German" "language": "German",
"editorMode": "vim",
"terminalProgressBarEnabled": false
} }
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
# Globale Sicherheitsprüfungen vor jedem Bash-Tool-Aufruf.
cmd=$(jq -r '.tool_input.command // ""')
# Git-Branch-Schutz: kein direkter Commit auf main
if echo "$cmd" | grep -q 'git commit'; then
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
if [ "$branch" = "main" ]; then
printf '{"continue":false,"stopReason":"BLOCKIERT: Direkter Commit auf main verboten (globale Regel). Bitte zuerst Feature-Branch erstellen: git checkout -b session/YYYY-MM-DD-titel"}\n'
exit 0
fi
fi
# apt -y verboten
if echo "$cmd" | grep -qE '\bapt\b' && echo "$cmd" | grep -q -- ' -y'; then
printf '{"continue":false,"stopReason":"BLOCKIERT: apt -y ist verboten. Bitte ohne -y ausfuehren, damit du die Zusammenfassung selbst bestaetigen kannst."}\n'
fi