Skip to content

Commit ef03c28

Browse files
committed
chore(security): add gitleaks pre-commit hook + .gitleaks.toml
- .gitleaks.toml extends gitleaks default rules with project-specific allowlists for the 2026-04-25 redacted-token markers + intentional template placeholders. - scripts/install-pre-commit-hook.sh — idempotent local-hook installer. - README documents the hook + bypass. Source: 2026-04-25 secret-scrub follow-on
1 parent 907cc9d commit ef03c28

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

.gitleaks.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# .gitleaks.toml — extends gitleaks default rules
2+
# Generated 2026-04-25 by fminimax pre-commit hook deployment.
3+
4+
[extend]
5+
useDefault = true
6+
7+
[[allowlists]]
8+
description = "Redacted-token markers from the 2026-04-25 history scrub"
9+
regexes = [
10+
'''gho_REDACTED-AUDIT-2026-04-25''',
11+
'''ntn_REDACTED-AUDIT-2026-04-25''',
12+
'''MORGEN-REDACTED-AUDIT-2026-04-25''',
13+
'''gho_REDACTED-W2-FIX-OUTPUT''',
14+
'''ntn_REDACTED-W2-FIX-OUTPUT''',
15+
'''MORGEN-REDACTED-W2-FIX-OUTPUT''',
16+
]
17+
18+
[[allowlists]]
19+
description = "Placeholder strings used in templates"
20+
regexes = [
21+
'''REPLACE_WITH_GITHUB_TOKEN''',
22+
'''REPLACE_WITH_NOTION_TOKEN''',
23+
'''REPLACE_WITH_MORGEN_API_KEY''',
24+
'''\{\{(NOTION_TOKEN|GITHUB_TOKEN|MORGEN_API_KEY|NOTION_DATABASE_ID|W[123]_WORKFLOW_ID)\}\}''',
25+
'''\$\{?[A-Z_]+_(TOKEN|KEY|SECRET|PASSWORD)\}?''',
26+
]

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,21 @@ The dual copyright reflects reality: ruv wrote the engine, I wrote the wrapper.
346346
> Credit to ruv is not a footer. It's load-bearing. Every release and every public surface should preserve the attribution block in the intro, the Built on Ruflo section, the License dual-copyright, and the Links list. If any of those go missing in a future edit, this fork stops being honest.
347347
348348
[⤴ back to top](#top)
349+
350+
## Security: gitleaks pre-commit hook
351+
352+
This repo ships with a `.gitleaks.toml` config and a one-liner installer for a local
353+
pre-commit hook that scans staged content for secrets (GitHub tokens, API keys, JWTs,
354+
etc.) before every commit.
355+
356+
```bash
357+
bash scripts/install-pre-commit-hook.sh
358+
```
359+
360+
The hook runs `gitleaks protect --staged` and blocks commits that contain secrets.
361+
For emergencies you can bypass with `git commit --no-verify` — but DO NOT bypass for
362+
real secrets. Use env vars or a secret manager instead.
363+
364+
If gitleaks isn't installed yet:
365+
- macOS: `brew install gitleaks`
366+
- Linux: https://github.com/gitleaks/gitleaks/releases

scripts/install-pre-commit-hook.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# install-pre-commit-hook.sh — wires up the local gitleaks pre-commit hook.
3+
# Idempotent: safe to re-run.
4+
set -euo pipefail
5+
6+
REPO_ROOT="$(git rev-parse --show-toplevel)"
7+
HOOK="$REPO_ROOT/.git/hooks/pre-commit"
8+
9+
if ! command -v gitleaks &>/dev/null; then
10+
echo "❌ gitleaks not found on PATH."
11+
echo " macOS: brew install gitleaks"
12+
echo " Linux: https://github.com/gitleaks/gitleaks/releases"
13+
exit 1
14+
fi
15+
16+
mkdir -p "$REPO_ROOT/.git/hooks"
17+
cat > "$HOOK" <<'HOOK_EOF'
18+
#!/usr/bin/env bash
19+
# pre-commit — gitleaks scan on staged content. Block if any secret detected.
20+
# Bypass for emergencies: git commit --no-verify
21+
set -euo pipefail
22+
23+
if ! command -v gitleaks &>/dev/null; then
24+
echo "⚠️ gitleaks missing — skipping pre-commit secret scan." >&2
25+
exit 0
26+
fi
27+
28+
if ! gitleaks protect --staged --no-banner --redact -v 2>&1; then
29+
echo ""
30+
echo "🚨 SECRETS DETECTED in staged content. Commit BLOCKED." >&2
31+
echo " 1. Review the leak above (output is redacted — full content in your staged files)." >&2
32+
echo " 2. Remove the secret from your changes (use env vars / .env / secret manager)." >&2
33+
echo " 3. Re-stage cleaned files and commit again." >&2
34+
echo " 4. Emergency bypass (DO NOT USE FOR REAL SECRETS): git commit --no-verify" >&2
35+
exit 1
36+
fi
37+
HOOK_EOF
38+
chmod +x "$HOOK"
39+
40+
echo "✅ Installed pre-commit hook → $HOOK"
41+
echo " Test it: stage a file containing a fake gho_/ntn_ token, then try git commit."

0 commit comments

Comments
 (0)