Secret-in-commit hooks never run: Claude Code doesn't set $TOOL_INPUT
まだ誰も着手していません。
評価
調査の方向性
.claude/settings.json と、現在 echo "$TOOL_INPUT" を grep にパイプしている 3 つのフックコマンド(PreToolUse が 2 つ、PostToolUse が 1 つ)を読む。Claude Code hooks reference によれば、ツール入力は stdin 上で届くため、パイプを外して grep に stdin を直接読ませ、ブロックメッセージは stderr へ送って Claude Code が却下理由として報告するようにする。各フックが終了コード 2 で終了し、ステージ済みの .env または git commit 呼び出しをブロックしたときに完了とみなす。検証は、Claude Code が送信する JSON をフックに与えて行う。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Go
- スター
- 75
- フォーク
- 2
- 平均マージ
- 16日 4時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nylas/cli のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
`XOAUTH2` / `OAUTHBEARER` support再び着手できるかも @qasim-nylas が 152 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug enhancement
似ている issue
-
good first issue help wanted v3
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
oras-project/oras-go#1621 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
メンテナーはふだん 4 日以内に返信
-
Chained slog With calls discard previously bound attributes対応中かも @yuefdev が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
[scanner] TestAgentNowLineStates hard-fails instead of degrading when node is off PATH対応中かも @arteeh が今日担当しました。 オープンagent/scanner ci help wanted kind/test
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
hivecommons/hive#12924 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Gentleman-Programming/engram#1940 ·
メンテナーはふだん 1 日以内に返信