051 · Secrets hook
A pre-commit hook that stops commits adding API keys and other secrets, put in by the harness setup (spec_051_secret_hooks)
| Status | Built (v0.8.4, the owner’s request: “when the harness is created, and a git repository is created, we should also add githooks to ensure API keys are not committed”) |
| Source | pkg/secretscan (scan.go: the scan; hook.go: the hook, Install, Staged), apps/cli/security.go (blitz security scan-secrets, blitz security install-hook), pkg/engine/changes.go (GitInit, InstallSecretHook), pkg/engine/tools/secrethook.go (install_secret_hook), WorkspaceService.InstallSecretHook (pkg/service/server/workspace.go), the Changes menu (apps/desktop/web/src/MenuBar.tsx, Workspace.tsx), pkg/engine/agents/builtin/project-setup.md, harness-update.md |
| Tests | pkg/secretscan/scan_test.go (TestScan, TestInstall, TestHookStopsACommit, TestStaged), apps/cli/security_test.go (TestScanSecretsAndInstallHook), pkg/engine/changes_test.go (TestGitInit), pkg/engine/tools/jobs_test.go (TestInstallSecretHookTool), pkg/service/server/git_test.go (TestInitGitRepo) |
| Depends on | spec_048_harness_learning (the setup), spec_029_files (FIL-59, git in the window), spec_039_secrets (where keys belong: the keychain) |
Agents write configuration, scripts and .env files, and Blitz adds new files to git at the end of a turn (FIL-60). A key pasted into a file, or written by an agent that was given one, can be committed and pushed before anyone sees it. Blitz keeps its own keys in the keychain (spec_039_secrets); a repository it sets up should refuse to commit anyone’s.
- SH-01
secretscan.Scan(name, data)finds, a line at a time: known key formats anywhere (a private key’sBEGIN … PRIVATE KEYline, AWS access keys, Anthropic and OpenAI keys, Google API keys, GitHub and GitLab tokens, Slack tokens, Stripe live keys, Hugging Face tokens); and in env and config files (.env,.env.*but not.example,.sampleor.template;.toml,.yaml,.ini,.json,.propertiesand the like;.npmrc,.pypirc,credentials) a value of 16 characters or more, with letters and digits and high entropy, assigned to a key-like name (password, secret, token, API or access key, credential), unless it’s a placeholder (${…},<…>,your-…,changeme,keychain:…,env:…,op://…). A line withblitz:allow-secretis skipped; binary files and files over 1 MB too. A finding names the file, the line and the kind, with the value masked (its first four characters). - SH-01 2026-11-05 (scan N26-safety-enterprise#8: the scan, the hook, the secrets guardrail and its description each had their own copy of the key formats, and they had drifted: the guardrail missed GitLab, Stripe, Hugging Face and
ASIAAWS keys). The key formats are one table,redact.Formats: the redactor (so the secrets guardrail) masks them,secretscan.Scanfinds them (a private key by its first line),gates.Describenames them, and the hook’sgrep -Epattern is that table as ERE (a test holds it so). JWTs are among them, so the scan finds one too. blitz security scan-secrets --stagedscans what the commit being made adds (each added, copied, changed or renamed file as staged,git show :<path>), orblitz security scan-secrets <file>…the files named; it lists the findings on stderr, says how to deal with them (the keychain or an ignored.env, the marker for a false alarm,git commit --no-verify) and exits 1.
- SH-02
.githooks/pre-commit(versioned, so everyone who clones the repository has it;git config core.hooksPath .githooksturns it on in a clone) runsblitz security scan-secrets --stagedwhen theblitzon PATH has it (blitz security --helplists it: an older one would refuse--stagedand stop every commit), else searches the lines being added (git diff --cached -U0) for the same key formats withgrep -E, printing only their first four characters.secretscan.Installwrites it (0755) at the repository’s top and setscore.hooksPathin the repository’s own config, and reportsinstalled(a hook Blitz wrote before is brought up to date),present(it’s there as it is now) orother_hooks: a repository withcore.hooksPathset elsewhere, husky, the pre-commit framework, lefthook, a.git/hooks/pre-commit, or a.githooks/pre-commitof its own is left alone, and the detail says which (addblitz security scan-secrets --stagedto them). - It goes in when the harness is set up: project-setup calls
install_secret_hookonce the workspace is a repository (made then or already), asked about as a write showing the hook; when the window makes a repository (InitGitRepo→GitInit; a failure is logged, the init isn’t); and withblitz security install-hook [dir].
- SH-03 The Changes menu’s Protect against committing keys (
WorkspaceService.InstallSecretHook), whose snack says what happened (and, forother_hooks, which hooks); harness-update offers it to a harness without it (HE-52).
- Scanning history already committed (
gitleaks detect,trufflehog): a key that was committed is to be revoked, whatever the hook says. - A server-side check (push protection): the hosting service’s.