ClaudeMods
☰
KO
● — 명 접속 중 · 조회 — 회
후원프로젝트 제출
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 주소라는 세 종류의 값을 세션 대화 기록에서 제외합니다.

먼저 함수 훅을 켜세요. 이것은 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에는 실제 키가 전달됩니다. 디스크에는 아무것도 기록하지 않습니다. 보관소는 세션 종료와 함께 사라집니다.

세 가지 훅

| 이벤트 | 동작 | | --- | --- | | prompt.submit | 붙여 넣은 키가 원래 값 그대로 모델에 전달되지 않습니다 | | tool.call | 도구 입력에 실제 값을 복원한 뒤 도구 결과에서 다시 숨깁니다. 보통 비밀 정보는 여기서 들어옵니다. cat .env, 설정을 읽는 Read, API 응답 등이 해당합니다 | | prompt.context | 첫 메시지에 첨부되는 블록의 비밀 정보를 숨깁니다. 이메일은 그대로 둡니다. 엔진이 모델에게 대화 상대를 알려 주려고 그 블록에 사용자의 주소를 넣기 때문입니다 |

비밀 정보 판정 기준

다음 세 가지를 순서대로 검사합니다.

  1. 공급업체 형식. sk-ant-, ghp_, AKIA, sk_live_, whsec_, AIza, xoxb-, JWT, Slack 또는 Discord webhook, PRIVATE KEY 블록, postgres://user:pass@host 문자열 속 비밀번호. 발견하면 바로 숨깁니다.
  2. 엔트로피와 대소문자 혼합. 소문자, 대문자, 숫자를 포함한 24자 이상의 토큰으로, 문자당 엔트로피가 3.6비트를 초과하는 경우입니다.
  3. 엔트로피와 이름. 문자당 엔트로피가 3.0비트를 초과하는 더 짧은 토큰으로, API_KEY=, "token":, Bearer, password: 등의 뒤에 있는 경우입니다.

네 가지 규칙이 오탐을 줄입니다. 이 규칙들을 함께 적용하면 대규모 Next.js 모노레포의 추적 대상 소스 트리 전체에서 탐지가 두 건으로 줄며, 둘 다 실제 비밀 정보입니다.

  • 공개 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자 이상이고 각 문자가 한 번씩만 쓰인 토큰은 문자 집합 상수입니다. 그 길이의 실제 키에는 거의 확실히 반복 문자가 있습니다.
  • 순수 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 | 대소문자 혼합 검사의 문자당 비트 수 | | minLength | 24 | 대소문자 혼합 검사에 적용할 최소 토큰 길이 | | contextMinEntropy | 3.0 | 앞에 키 이름이 있을 때의 문자당 비트 수 | | redactPrivateIps | false | 예약 범위도 숨기기 | | allow | "" | 그대로 둘 정확한 문자열, 쉼표로 구분 | | allowEmails | "" | 주소 또는 @domain.com, 쉼표로 구분 | | allowPrefixes | "" | 공개 id로 취급할 추가 접두사 | | denyPrefixes | "" | 엔트로피 검사 대상으로 되돌릴 접두사 |

하지 않는 두 가지

  • 모델이 직접 쓰는 비밀 정보는 숨기지 않습니다. 모델이 읽는 내용만 검사합니다. 모델이 명령에 입력하는 키는 이미 알고 있던 키입니다.
  • 재시작 후에는 유지되지 않습니다. 보관소는 메모리에만 있습니다. 이전 세션의 자리표시자는 새 세션에서 의미가 없습니다.

테스트

모든 명령은 이 저장소의 루트에서 실행하세요.

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에는 반드시 숨겨야 하는 값과 반드시 유지해야 하는 값의 두 목록이 있습니다. 임계값이나 패턴 변경은 두 목록이 모두 계속 통과해야 완료됩니다.

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

비슷한 프로젝트