ClaudeMods
☰
JA
● — 人がオンライン ・閲覧 — 回
スポンサー作品を投稿
GitHub リポジトリ · 投稿者 ray-amjad

secret-redactor

機密情報、メールアドレス、IP アドレスをセッションの会話記録に残さないようにします。入力時に一定のプレースホルダーに置き換え、ツール呼び出しに渡す際に実際の値を復元します。

ray-amjad@ray-amjad

ray-amjad/awesome-claude-code-function-hooks/tree/main/plugins/secret-redactor

翻訳済み

この mod について

secret-redactor

機密情報、メールアドレス、IP アドレスの 3 種類の値をセッションの会話記録に残さないようにします。

まず関数フックを有効にしてください。 これは Claude Code の関数フックです。 anthropics/claude-code#91870 で提案された早期アクセス機能です。 デフォルトでは無効で、有効にするまでこのプラグインは何もしません。 ~/.claude/settings.json に "env": { "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS": "1" } を追加するか、 CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude でセッションを開始してください。

値は破棄されません。フックモジュール内の、セッション中だけメモリに存在する保管庫に入り、会話記録には代わりにプレースホルダーが入ります。

ANTHROPIC_API_KEY=[REDACTED-SECRET-164d0c98]
SUPPORT_EMAIL=[REDACTED-EMAIL-6f096ff7]
EDGE_ORIGIN=[REDACTED-IP-6fc52d2b]

同じ値には常に同じプレースホルダーが生成されるため、モデルは顧客を区別できます。ツール呼び出しに渡す際には実際の値に戻るので、Bash コマンドや Write は実際のキーを扱います。ディスクには何も書き込みません。保管庫はセッション終了とともに消えます。

3 つのフック

| イベント | 動作 | | --- | --- | | prompt.submit | 貼り付けたキーがそのままモデルに届くことはありません | | tool.call | ツールの入力で実際の値を復元し、結果では再び隠します。通常、機密情報はここから入ります。cat .env、設定を読む Read、API の応答などです | | prompt.context | 最初のメッセージに添付されるブロック内の機密情報を隠します。メールアドレスはそのままです。エンジンがあなたのアドレスをそのブロックに入れ、モデルに相手を知らせるためです |

機密情報の判定

次の 3 つを順に検査します。

  1. ベンダー固有の形式。 sk-ant-、ghp_、AKIA、sk_live_、whsec_、AIza、 xoxb-、JWT、Slack や Discord の webhook、PRIVATE KEY ブロック、 postgres://user:pass@host 内のパスワード。見つけ次第隠します。
  2. エントロピーと大小文字の混在。 小文字、大文字、数字を含む 24 文字以上のトークンで、 1 文字あたりのエントロピーが 3.6 ビットを超えるもの。
  3. エントロピーと名前。 1 文字あたりのエントロピーが 3.0 ビットを超える短いトークンで、 API_KEY=、"token":、Bearer、password: などの後にあるもの。

4 つのルールで誤検出を抑えます。これらを組み合わせると、大規模な Next.js モノレポの追跡対象ソースツリー全体で検出は 2 件となり、どちらも実際の機密情報です。

  • 公開 id は機密情報ではありません。 price_、prod_、cus_、promo_、 pk_live_ などの Stripe オブジェクト id や YouTube チャンネル id は、 ダッシュボードやソースに表示されます。隠しても保護にはなりません。
  • 名前はキーではありません。 archived-modules-marker、 lesson_article_outline_open_v1、playerEventBatchV1Schema、 randomTimestampWithinLast14Days、 META_Conv_Lookalike-Customers_FreeTrial_2024Q1 は高エントロピーに見えます。 しかし単語の組み合わせです。キーは単語で構成されません。
  • 文字集合はキーではありません。 20 文字以上で各文字を 1 回ずつ使うトークンは文字集合の定数です。 その長さの実際のキーでは、ほぼ確実に文字が繰り返されます。
  • 単なる 16 進数には名前が必要です。 40 文字の 16 進数はキーより git SHA やチェックサムであることが多いため、 前に API_KEY= や "token": がある場合だけ機密情報と判定します。

個人識別情報(PII)の判定

  • メールアドレス。 noreply@、@users.noreply.github.com、 文書用ドメイン(@example.com、@company.com、@test)、 仮のローカル部(you@、name@、admin@)、allowEmails の内容は除外します。 公開済みの自分のアドレスを @yourdomain.com などの形でこのオプションに追加すれば、 自分の連絡先は読める状態で残ります。
  • IP アドレス、v4 と v6。開発では 127.0.0.1:3000 が頻出するため、 プライベート範囲と予約範囲はデフォルトで表示したままです。ループバック、10.x、 192.168.x、172.16-31.x、リンクローカル、キャリアグレード NAT、マルチキャスト、 ベンチマーク用範囲、RFC 5737 の文書用範囲が含まれます。redactPrivateIps を設定すると、これらも隠せます。

オプション

ユーザー設定の pluginConfigs 内でプラグインごとに設定します。

| オプション | デフォルト | 動作 | | --- | --- | --- | | secrets | true | 機密情報を隠す | | pii | true | メールアドレスと IP アドレスを隠す | | restoreInToolInputs | true | ツール実行前に実際の値を復元する | | notify | true | ツール行に件数、プロンプトにはトーストを表示する | | minEntropy | 3.6 | 大小文字混在検査の 1 文字あたりのビット数 | | minLength | 24 | 大小文字混在検査の最小トークン長 | | contextMinEntropy | 3.0 | キー名が前にある場合の 1 文字あたりのビット数 | | redactPrivateIps | false | 予約範囲も隠す | | allow | "" | そのまま残す完全一致文字列。カンマ区切り | | allowEmails | "" | アドレスまたは @domain.com。カンマ区切り | | allowPrefixes | "" | 公開 id とみなす追加の接頭辞 | | denyPrefixes | "" | エントロピー検査の対象に戻す接頭辞 |

対応しない 2 つのこと

  • モデル自身が書く機密情報は隠しません。 スキャンするのはモデルが読む内容だけです。 モデルがコマンドに入力するキーは、すでに知っていたキーです。
  • 再起動後には残りません。 保管庫はメモリ内だけです。 以前のセッションのプレースホルダーは、新しいセッションでは意味を持ちません。

テスト

すべてのコマンドをこのリポジトリのルートから実行してください。

手順 1:型宣言を生成します。新しい Claude Code リリースが上書きするため、git には含まれていません。 このコマンドは tsconfig.json が参照する types/claude-code.d.ts を書き込みます。

/plugin-types

手順 2:検出器のテストとプラグイン検証を実行します。

node --experimental-strip-types plugins/secret-redactor/test/detect.test.mts
claude plugin validate plugins/secret-redactor

test/detect.test.mts には、隠すべき値と残すべき値の 2 つの一覧があります。 しきい値やパターンの変更は、両方が引き続き合格して初めて完了です。

手順 3:エンドツーエンドで試します。

claude --plugin-dir plugins/secret-redactor \
  -p "cat plugins/secret-redactor/test/fixtures/sample.env, then repeat the values back"

インストール

まず作者の README で marketplace とプラグイン名を確認してください。コマンドはリポジトリの構成によって変わる場合があります。

claude plugin marketplace add ray-amjad/awesome-claude-code-function-hooks
claude plugin install secret-redactor
原文 / README

secret-redactor

Keeps three classes of value out of the session transcript: secrets, email addresses and IP addresses.

Turn function hooks on first. This is a Claude Code function hook, the early-access feature proposed in anthropics/claude-code#91870. It is off by default, and this plugin does nothing until you turn it on. Add "env": { "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS": "1" } to ~/.claude/settings.json, or start one session with CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude.

The value is not destroyed. It goes into a vault that lives in the hooks module, in memory, for the session, and the transcript gets a placeholder in its place:

ANTHROPIC_API_KEY=[REDACTED-SECRET-164d0c98]
SUPPORT_EMAIL=[REDACTED-EMAIL-6f096ff7]
EDGE_ORIGIN=[REDACTED-IP-6fc52d2b]

The same value always mints the same placeholder, so the model can still tell one customer from another. The placeholder is swapped back for the real value on the way into a tool call, so a Bash command or a Write still carries the real key. Nothing is written to disk. The vault dies with the session.

The three hooks

| Event | What it does | | --- | --- | | prompt.submit | A key you paste never reaches the model as itself | | tool.call | Puts real values back into the tool's input, then hides them again in the tool's result. This is where a secret usually arrives: a cat .env, a Read of a config, an API answer | | prompt.context | Hides secrets in the blocks attached to the first message. Emails are left alone there: the engine puts your own address in that block so the model knows who it is talking to |

What counts as a secret

Three tests, in order.

  1. A vendor shape. sk-ant-, ghp_, AKIA, sk_live_, whsec_, AIza, xoxb-, a JWT, a Slack or Discord webhook, a PRIVATE KEY block, the password inside a postgres://user:pass@host string. Hidden on sight.
  2. Entropy plus mixed case. A token of 24 characters or more that carries lower case, upper case and digits, above 3.6 bits per character.
  3. Entropy plus a name. A shorter token, above 3.0 bits per character, that sits after API_KEY=, "token":, Bearer, password: and the like.

Four rules stop the noise. Together they take a large Next.js monorepo down to two hits across its whole tracked source tree, and both are real secrets.

  • A public id is not a secret. price_, prod_, cus_, promo_, pk_live_ and the rest of Stripe's object ids, and a YouTube channel id, are printed in dashboards and in source. Hiding them protects nothing.
  • A name is not a key. archived-modules-marker, lesson_article_outline_open_v1, playerEventBatchV1Schema, randomTimestampWithinLast14Days and META_Conv_Lookalike-Customers_FreeTrial_2024Q1 all read as high entropy. They are word lists. A key is not built out of words.
  • An alphabet is not a key. A token of 20 characters or more that uses every character once is a charset constant. A real key of that length repeats a character with near certainty.
  • Bare hex needs a name beside it. A 40-character hex run is a git SHA or a checksum far more often than it is a key, so hex only counts as a secret when API_KEY= or "token": sits in front of it.

What counts as PII

  • Email addresses. Skipped: noreply@, @users.noreply.github.com, documentation domains (@example.com, @company.com, @test), placeholder local parts (you@, name@, admin@), and anything in allowEmails. Put your own published addresses in that option, as @yourdomain.com, so your own contact address stays readable.
  • IP addresses, v4 and v6. Private and reserved ranges stay visible by default, because 127.0.0.1:3000 is everywhere in dev: loopback, 10.x, 192.168.x, 172.16-31.x, link-local, carrier-grade NAT, multicast, the benchmarking range, and the RFC 5737 documentation ranges. Set redactPrivateIps to hide those too.

Options

Set them per plugin under pluginConfigs in your user settings.

| Option | Default | What it does | | --- | --- | --- | | secrets | true | Hide secrets | | pii | true | Hide emails and IP addresses | | restoreInToolInputs | true | Put the real value back before a tool runs | | notify | true | Count on the tool row, toast on a prompt | | minEntropy | 3.6 | Bits per character for the mixed-case test | | minLength | 24 | Shortest token the mixed-case test looks at | | contextMinEntropy | 3.0 | Bits per character when a key name sits in front | | redactPrivateIps | false | Hide reserved ranges too | | allow | "" | Exact strings to leave alone, separated by commas | | allowEmails | "" | Addresses, or @domain.com, separated by commas | | allowPrefixes | "" | Extra id prefixes to treat as public | | denyPrefixes | "" | Prefixes to put back under the entropy test |

Two things it does not do

  • It does not hide a secret the model itself writes. Only what the model reads is scanned. A key the model types into a command is a key it already had.
  • It does not survive a restart. The vault is memory only. Placeholders from an earlier session are meaningless in a new one.

Testing

Run every command from the root of this repo.

Step 1. Make the type declarations. They are not in git, because a new Claude Code release rewrites them. This command writes types/claude-code.d.ts, which tsconfig.json points at:

/plugin-types

Step 2. Run the detector test and the plugin validator:

node --experimental-strip-types plugins/secret-redactor/test/detect.test.mts
claude plugin validate plugins/secret-redactor

test/detect.test.mts holds two lists: values that must be hidden and values that must be kept. A change to a threshold or a pattern is only finished when both still pass.

Step 3. Try it end to end:

claude --plugin-dir plugins/secret-redactor \
  -p "cat plugins/secret-redactor/test/fixtures/sample.env, then repeat the values back"

バッジを取得

あなたのプロジェクトですか?このバッジを README やサイトに貼ると、このページにリンクします。

Featured on ClaudeMods
サイズ
テーマ
Markdown
HTML

関連作品