Secret-in-commit hooks never run: Claude Code doesn't set $TOOL_INPUT
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 92/100
Rechercherichtung
Lies .claude/settings.json und die drei Hook-Befehle (zwei PreToolUse, ein PostToolUse), die derzeit echo "$TOOL_INPUT" in grep pipen. Laut der Claude Code hooks reference trifft das Tool-Input über stdin ein, also entferne die Pipe und lass grep stdin direkt lesen, und sende die Blocknachricht an stderr, damit Claude Code sie als Ablehnungsgrund meldet. Fertig, wenn jeder Hook mit Code 2 endet und einen gestagten .env oder einen git commit-Aufruf blockiert, verifiziert, indem dem Hook das JSON zugeführt wird, das Claude Code sendet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
The two PreToolUse hooks in .claude/settings.json that stop a commit containing a sensitive file or a possible secret, and the PostToolUse security scan, all start with echo "$TOOL_INPUT" | grep -q 'git commit'. Claude Code passes the tool call to a hook as JSON on stdin and does not set $TOOL_INPUT (the hooks reference lists the variables it does set), so the grep never matches and none of the three checks runs.
I checked with Claude Code 2.1.292 that TOOL_INPUT is empty inside a hook. Then, in a repo with .env staged and fed the JSON Claude Code sends for git commit -m wip, both PreToolUse hooks exit 0 and the commit would go ahead.
The fix is to drop echo "$TOOL_INPUT" | so grep reads stdin. Sending the message to stderr also makes it the reason Claude Code gives for the block:
"command": "if grep -q 'git commit'; then git diff --cached --name-only | grep -E '\\.(env|pem|key|p12)$' && echo >&2 '⛔ BLOCKED: Sensitive file in commit' && exit 2 || exit 0; fi"
With that change and the same staged .env, the first hook exits 2 with "Sensitive file in commit" and the second exits 2 with "Possible secret in commit". The same one-line change applies to the PostToolUse scan.
Found this while testing Claude Code guards for Paveo. Happy to open a PR with the fix.
- Vorherrschende Sprache
- Go
- Sterne
- 76
- Forks
- 3
- Ø Merge
- 14 T. 15 Std.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nylas/cli
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
`XOAUTH2` / `OAUTHBEARER` supportEvtl. wieder frei @qasim-nylas hat das vor 167 Tagen übernommen, und es ist kein Pull Request offen. Offenbug enhancement
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
limitlessprojects/Go-Hybrid#3342 ·
Maintainer antworten meist innerhalb von 1 Tag
-
status/ready type/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
buildpacks/pack#2733 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
kind/bug needs-priority needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
konveyor/tackle2-hub#1166 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
router-for-me/CLIProxyAPI#7209 ·
Maintainer antworten meist innerhalb von 1 Tag