feat: 4-layer secret leak prevention
Merged
SH
5mo ago+127+127+012345678901234567890123456789-0-0-0123456789
Summary
Implements the 4-layer secret leak prevention pattern from https://zenn.dev/takna/articles/secret-leak-prevention-4-layer.
- Layer 1 (design):
.gitignorepatterns for credential locations (_credentials/,*.local.md,*.secret.md,credentials*.md,**/draft/). - Layer 2 (pre-commit):
lefthook.ymlrunsgitleaks git --staged --redact --verbose. Gitleaks config moved toconfig/gitleaks/config.tomland installed globally at~/.config/gitleaks/config.tomlvia home-manager;GITLEAKS_CONFIGenv var is set so every repo picks up the same baseline without a per-repo.gitleaks.toml. - Layer 3 (push protection): server-side, enable manually per repo at Settings -> Advanced Security -> Secret Protection -> Push protection.
- Layer 4 (AI hook):
config/shared/hooks/secret-guard.shis a shared PreToolUse hook wired into both Claude Code (config/claude/settings.json) and Codex (config/codex/hooks.json) forWrite|Edit|MultiEdit. It extracts content from multiple payload shapes (Claudetool_input.*, Codextool.input.*, plus MultiEditedits[].new_string), runs gitleaks against the extracted content, and exits 2 to block on detection. Skips silently ifgitleaks/jqare missing so it does not break before the next rebuild.
gitleaks and lefthook added to home-manager/packages/default.nix.
Test plan
-
darwin-rebuild switch --flake .installsgitleaksandlefthook -
lefthook installwires.git/hooks/pre-commitin this repo -
echo 'AWS_SECRET_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE' | gitleaks stdinflags - Claude Code
Writewith a fake AWS key in content is blocked bysecret-guard.sh - Codex
Writewith the same payload is blocked - Clean writes pass through (exit 0)
Summary by cubic
Adds a 4-layer secret leak prevention system across ignore rules, pre-commit checks, server push protection, and editor hooks. Also adds shell coverage for secret-guard.sh and formats the script.
-
New Features
- Layer 1:
.gitignoreexcludes_credentials/,*.local.md,*.secret.md,credentials*.md,**/draft/. - Layer 2: Pre-commit via
lefthookrunsgitleaks git --staged --redact --verbose; global config at~/.config/gitleaks/config.tomlviahome-managerwith custom rules and allowlist. - Layer 3: Push protection (server-side). Enable per repo in Settings > Advanced Security > Secret Protection.
- Layer 4:
secret-guard.shhooks Claude Code and Codex Write/Edit/MultiEdit, scans payloads withgitleaks, exits 2 on findings; skips ifgitleaks/jqmissing.
- Layer 1:
-
Dependencies
- Added
gitleaksandlefthooktohome-managerpackages.
- Added