redact: Cloudflare's tokens and keys are masked by default (eiyuuzaki2333 on X)

Formats from Cloudflare's docs (fundamentals/api/get-started/token-formats
and /ca-keys): the scannable prefixes cfut_ (user token), cfat_ (account
token), cfk_ (Global API Key) and cfoat_ (Wrangler OAuth), each 40
characters and a checksum; an Origin CA key, which always starts v1.0-
(two alphanumeric runs split by a hyphen); a tunnel token, base64 of
{"a":..,"t":..,"s":..} so it starts eyJhIjoi (the docs show only that
head). The X-Auth-Key and X-Auth-User-Service-Key headers are masked
whatever the value looks like. The unprefixed older token (40 letters) and
Global Key (37-45 hex), and an R2 Secret Access Key (64 hex), have no
shape and were already masked under their names (CLOUDFLARE_API_TOKEN,
AWS_SECRET_ACCESS_KEY); the test pins that. An R2 Access Key ID is an id
and goes as written by design (TestIDsGoAsWritten), so it is not masked.
The checksum's length and alphabet aren't documented, so the prefixed rule
takes 40 or more of [A-Za-z0-9_-]. The origin CA hex split is not in the
docs; the rule takes alphanumerics.

Docs: the masking page (en, zh, ja) and llms-full.txt list them.

Run (mica, mote was loaded): go test -count=1 ./internal/redact ok;
gofmt; go vet darwin, linux nogui, windows. The new tests were red on the
old code for every prefixed, Origin CA, tunnel and X-Auth-Key case, and
keep SHA-1/SHA-256/MD5 hex, a base62 string, v1.0-beta, a bare prefix, an
R2 id and a JWT header unmasked.
Not tried: a real Cloudflare token (fake values in the documented shapes);
the full suite and GUI suite (no GUI file touched).
This commit is contained in:
yetone
2026-11-12 19:31:43 +08:00
parent 4519eea711
commit ab98228cc1
6 changed files with 102 additions and 4 deletions
+79
View File
@@ -0,0 +1,79 @@
package redact
import (
"strings"
"testing"
)
// Fake credentials in Cloudflare's documented shapes
// (developers.cloudflare.com/fundamentals/api/get-started/token-formats,
// .../ca-keys, and cloudflared's tunnel token, which is base64 of
// {"a":account,"t":tunnel,"s":secret}).
const (
cfUserTok = "cfut_Kq3vXm9ZpL2wRt7YbN4cHd8sJf6GaE1uVoTi5MxA" + "9f3c1b7e"
cfAcctTok = "cfat_Zr8dQw2LmN5vXc7BtY1pHk4sJg6FaE3uVoTi9MxP" + "02a8d4c6"
cfGlobalNew = "cfk_Hb4nXw7ZpL2qRt9YcN3vMd8sJf6GaE1uKoTi5MyQ" + "5e1b7a90"
cfOriginCA = "v1.0-3f9a1c7e5b2d4a6c8e0f1a2b-" + "4d6f8a0c2e4b6d8f0a1c3e5a7b9d1f3a5c7e9b1d3f5a7c9e1b3d5f7a9c1e3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a5c7e9b1d3f5a7c9e1b3d5f7a9c1e3b5d7f"
cfTunnelTok = "eyJhIjoiMGE0YzNmOWU3YjFkMmM2ZThmNWE5MDQ3YjNjMWUyZDQiLCJ0IjoiN2M5ZTFiM2EtNGQ2Zi00YThjLTllMGYtMWEyYjNjNGQ1ZTZmIiwicyI6IlpYaGhiWEJzWlhObFkzSmxkSFpoYkhWbE1USXpORFUyTnpnNU1BPT0ifQ=="
cfGlobalOld = "c2547eb745079dac9320b638f5e225cf483cc" // 37 hex
cfLegacyTok = "8M7wS6hCpXQ5QeL2Ek4xj3Bt9nVa1uRyZfDgHi0O" // 40 alnum
cfR2KeyID = "9d1f3b5a7c2e4a6c8e0b1d3f5a7c9e2b" // 32 hex
cfR2Secret = "a3f5c7e9b1d3f5a7c9e1b3d5f7a9c1e3b5d7f9a1c3e5b7d9f1a3c5e7b9d1f3a5" // 64 hex
)
func TestCloudflareCredentials(t *testing.T) {
cases := []struct{ name, in, gone string }{
{"user token", "token is " + cfUserTok + " ok", cfUserTok},
{"account token", "use " + cfAcctTok + ".", cfAcctTok},
{"global key", "key=" + cfGlobalNew, cfGlobalNew},
{"origin ca", "X-Auth-User-Service-Key: " + cfOriginCA, cfOriginCA},
{"origin ca bare", "see " + cfOriginCA + " here", cfOriginCA},
{"wrangler oauth", "cfoat_" + strings.Repeat("aB3dE5gH7j", 5) + "12345678", "cfoat_"},
{"tunnel token flag", "cloudflared tunnel run --token " + cfTunnelTok, cfTunnelTok},
{"tunnel token env", "TUNNEL_TOKEN=" + cfTunnelTok, cfTunnelTok},
{"tunnel token bare", "run " + cfTunnelTok + " now", cfTunnelTok},
{"legacy token env", "CLOUDFLARE_API_TOKEN=" + cfLegacyTok, cfLegacyTok},
{"legacy token cf", "CF_API_TOKEN: " + cfLegacyTok, cfLegacyTok},
{"bearer", "curl -H 'Authorization: Bearer " + cfLegacyTok + "' https://api.cloudflare.com/client/v4/user/tokens/verify", cfLegacyTok},
{"global key header", "curl -H 'X-Auth-Key: " + cfGlobalOld + "' -H 'X-Auth-Email: a@b.co'", cfGlobalOld},
{"global key env", "CLOUDFLARE_API_KEY=" + cfGlobalOld, cfGlobalOld},
{"r2 secret env", "R2_SECRET_ACCESS_KEY=" + cfR2Secret, cfR2Secret},
{"r2 aws env", "AWS_ACCESS_KEY_ID=" + cfR2KeyID + "\nAWS_SECRET_ACCESS_KEY=" + cfR2Secret + "\nendpoint https://acc.r2.cloudflarestorage.com", cfR2Secret},
{"origin ca env", "CLOUDFLARE_ORIGIN_CA_KEY=" + cfOriginCA, cfOriginCA},
}
for _, c := range cases {
out, n := Mask(c.in, Options{Secrets: true})
if strings.Contains(unmarked(out), c.gone) || n == 0 {
t.Errorf("%s: not masked (%d): %q", c.name, n, out)
}
}
}
func TestCloudflareLookalikesKept(t *testing.T) {
sha1 := "da39a3ee5e6b4b0d3255bfef95601890afd80709"
sha256 := "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
md5 := "d41d8cd98f00b204e9800998ecf8427e"
b62 := "Zm9vYmFyYmF6cXV4Z3JhdWx0aGVsbG93b3JsZDEyMzQ1Ng"
for _, in := range []string{
"commit " + sha1,
"sha256: " + sha256,
"etag " + md5,
"digest " + sha256 + " and " + sha1,
"id " + b62,
"version v1.0-beta.2 released, v1.0-rc1",
"cloudflare zone id " + md5 + " in the dashboard",
"cf account " + cfR2KeyID,
"R2_ACCESS_KEY_ID=" + cfR2KeyID,
"AWS_ACCESS_KEY_ID=" + cfR2KeyID,
"cfut_ is the prefix of user tokens",
"cfk_short",
"Image digest sha256:" + sha256,
"CLOUDFLARE_ACCOUNT_ID=" + cfR2KeyID,
"eyJhbGciOiJub25lIn0 is a jwt header",
} {
out, n := Mask(in, Options{Secrets: true})
if n != 0 || out != in {
t.Errorf("masked a lookalike: %q -> %q", in, out)
}
}
}
+19
View File
@@ -182,6 +182,25 @@ var rules = append([]rule{
{kind: "API_KEY", re: lazyre.New(`(?:AKIA|ASIA)[0-9A-Z]{16}`), markers: []string{"AKIA", "ASIA"}, bound: alnum},
{kind: "API_KEY", re: lazyre.New(`(?:hf_[A-Za-z0-9]{30,}|gsk_[A-Za-z0-9]{40,}|xai-[A-Za-z0-9]{40,}|npm_[A-Za-z0-9]{36}|pypi-[A-Za-z0-9_-]{50,}|dop_v1_[a-f0-9]{64}|SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43})`),
markers: []string{"hf_", "gsk_", "xai-", "npm_", "pypi-", "dop_v1_", "SG."}, bound: tokenCh},
// Cloudflare's: the scannable prefixes of a user token, an account
// token, a Global API Key and a Wrangler OAuth token (cfut_, cfat_,
// cfk_, cfoat_; 40 characters and a checksum,
// developers.cloudflare.com/fundamentals/api/get-started/token-formats),
// an Origin CA key (always v1.0-, two hex runs), and a tunnel token
// (base64 of {"a":account,"t":tunnel,"s":secret}, so it starts eyJhIjoi).
// The unprefixed older tokens and keys are 40 letters or 37 to 45 hex
// and have no shape of their own; they are masked by the name they sit
// under (secretNames).
{kind: "API_KEY", re: lazyre.New(`cf(?:ut|at|k|oat)_[A-Za-z0-9_-]{40,}`), markers: []string{"cfut_", "cfat_", "cfk_", "cfoat_"}, bound: tokenCh},
{kind: "API_KEY", re: lazyre.New(`v1\.0-[A-Za-z0-9]{16,}-[A-Za-z0-9]{40,}`), markers: []string{"v1.0-"}, bound: tokenCh},
{kind: "TOKEN", re: lazyre.New(`eyJhIjoi[A-Za-z0-9+/_-]{40,}={0,2}`), markers: []string{"eyJhIjoi"}, bound: tokenCh},
// X-Auth-Key (the Global API Key) and X-Auth-User-Service-Key (the
// Origin CA key) headers, whatever the key looks like
{kind: "SECRET", re: lazyre.New(`(?i)x-auth-(?:user-service-)?key["']?[ \t]*[:=][ \t]*["']?([A-Za-z0-9._-]{16,})`),
fold: []string{"x-auth-"}, ahead: 120, ok: notAVariable},
// An R2 Access Key ID (32 hex, the id of its API token) is an id and
// goes as written (TestIDsGoAsWritten); its Secret Access Key (64 hex)
// is masked under a secret's name.
{kind: "TOKEN", re: lazyre.New(`eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}`), markers: []string{"eyJ"}, bound: tokenCh},
// the password of user:password@host, or of :password@host as a Redis
// URL has it with no user
+1 -1
View File
@@ -170,7 +170,7 @@
<h2 id="what"><a class="anchor" href="#what">マスクされるもの</a></h2>
<div class="table-wrap"><table>
<tr><th>スイッチ</th><th>見つけるもの</th></tr>
<tr><td><span class="ui">シークレットをマスク</span></td><td>秘密鍵のブロック(<code>-----BEGIN … PRIVATE KEY-----</code>)。形で見分ける API キー:<code>sk-…</code>(OpenAI、Anthropic、OpenRouter)、<code>ghp_</code>/<code>github_pat_</code>、<code>glpat-</code>、<code>AIza…</code>、<code>xox…-</code>、<code>sk_live_</code>、<code>AKIA</code>/<code>ASIA</code>、<code>hf_</code>、<code>gsk_</code>、<code>xai-</code>、<code>npm_</code>、<code>pypi-</code>、<code>dop_v1_</code>、<code>SG.</code>、それに <code>oc_sk_…</code> のような中継サービスのキー。JWT。<code>user:password@host</code> のパスワード。<code>.env</code> や設定ファイルでシークレットの名前が付いたフィールドの値:<code>DB_PASSWORD=…</code>、<code>api_key: …</code>、<code>client_secret</code>、<code>token</code>、<code>credential</code>。それと自分の <span class="ui">マスクルール</span>。 ウォレットの秘密鍵も、ウォレットが書き出す形で探します:Bitcoin の WIF、BIP32 の <code>xprv</code>、Ethereum と TRON の <code>0x</code> 鍵、Solana の鍵と <code>id.json</code> のキーペア、Sui の <code>suiprivkey1…</code>、Aptos の <code>ed25519-priv-0x…</code>、Stellar のシード、NEAR の <code>ed25519:…</code>、Nostr の <code>nsec1…</code>、age の ID、Zcash の拡張支払鍵、<em>seed</em> や <em>ニーモニック</em> の後の、どの語も BIP39 の単語リストにある 12〜25 語のシードフレーズ。決まった接頭辞のない鍵は検証を通ったときだけ置き換えます:WIF と <code>xprv</code> はチェックサム、Solana の鍵は後半の公開鍵、Stellar のシードは CRC で確かめるので、Solana のトランザクション署名はそのまま送られます。<code>0x</code> 鍵はトランザクションハッシュと同じ形なので、鍵の名前の後(<code>PRIVATE_KEY=</code>、<code>--private-key</code>、<code>new Wallet(…)</code>、私钥)でだけ置き換えます。ハッシュ、ストレージスロット、sha256 の値はそのまま送られます。取引所の API キー、シークレット、<code>passphrase</code> はフィールド名で置き換えます。</td></tr>
<tr><td><span class="ui">シークレットをマスク</span></td><td>秘密鍵のブロック(<code>-----BEGIN … PRIVATE KEY-----</code>)。形で見分ける API キー:<code>sk-…</code>(OpenAI、Anthropic、OpenRouter)、<code>ghp_</code>/<code>github_pat_</code>、<code>glpat-</code>、<code>AIza…</code>、<code>xox…-</code>、<code>sk_live_</code>、<code>AKIA</code>/<code>ASIA</code>、<code>hf_</code>、<code>gsk_</code>、<code>xai-</code>、<code>npm_</code>、<code>pypi-</code>、<code>dop_v1_</code>、<code>SG.</code>、Cloudflare のもの(<code>cfut_</code>、<code>cfat_</code>、<code>cfk_</code>、<code>cfoat_</code>、Origin CA <code>v1.0-</code>、Tunnel トークン)、それに <code>oc_sk_…</code> のような中継サービスのキー。JWT。<code>user:password@host</code> のパスワード。<code>.env</code> や設定ファイルでシークレットの名前が付いたフィールドの値:<code>DB_PASSWORD=…</code>、<code>api_key: …</code>、<code>client_secret</code>、<code>token</code>、<code>credential</code>。それと自分の <span class="ui">マスクルール</span>。 ウォレットの秘密鍵も、ウォレットが書き出す形で探します:Bitcoin の WIF、BIP32 の <code>xprv</code>、Ethereum と TRON の <code>0x</code> 鍵、Solana の鍵と <code>id.json</code> のキーペア、Sui の <code>suiprivkey1…</code>、Aptos の <code>ed25519-priv-0x…</code>、Stellar のシード、NEAR の <code>ed25519:…</code>、Nostr の <code>nsec1…</code>、age の ID、Zcash の拡張支払鍵、<em>seed</em> や <em>ニーモニック</em> の後の、どの語も BIP39 の単語リストにある 12〜25 語のシードフレーズ。決まった接頭辞のない鍵は検証を通ったときだけ置き換えます:WIF と <code>xprv</code> はチェックサム、Solana の鍵は後半の公開鍵、Stellar のシードは CRC で確かめるので、Solana のトランザクション署名はそのまま送られます。<code>0x</code> 鍵はトランザクションハッシュと同じ形なので、鍵の名前の後(<code>PRIVATE_KEY=</code>、<code>--private-key</code>、<code>new Wallet(…)</code>、私钥)でだけ置き換えます。ハッシュ、ストレージスロット、sha256 の値はそのまま送られます。取引所の API キー、シークレット、<code>passphrase</code> はフィールド名で置き換えます。</td></tr>
<tr><td><span class="ui">個人情報をマスク</span></td><td>メールアドレス、中国本土の携帯番号(11 桁の ID は別:<code>order_id</code> の値や 订单号 の後ろのものはそのまま)、チェックサムの合う中国の身分証番号と銀行カード番号。既定でオンのもの:米国の社会保障番号、パスポート番号(<em>passport</em>、护照、パスポートの後)、IBAN、誕生日(<em>birthday</em>、<em>DOB</em>、生日の近くにある、一年以上前の日付。今日の日付はそのまま)、MAC アドレス、シリアル番号(<em>S/N</em> の後)。エージェントがほぼ毎回送るので、自分でオンにするまでオフのもの:ホームフォルダのユーザー名(毎回同じ仮の名前で送るので、モデルにはプレースホルダーではなく普通のフォルダに見えます)、ユーザー名とコンピュータ名(<code>user@host</code>)、パブリック IP アドレス(<code>public-ip-kvxqmrtz</code> のような名前として送るので、モデルはパブリックなアドレスだとわかったまま接続に使い、コマンドの中で本物のアドレスに戻ります)、クラウドストレージのバケット。ウォレットやコントラクトのアドレス(<code>0x</code> と 16 進 40 桁)は公開情報なのでそのまま送ります。秘密鍵は引き続きマスクします。</td></tr>
<tr><td><span class="ui">マスクする語</span></td><td>入れた語そのままを <code>{{TERM_…}}</code> に。日付(<em>1990-05-12</em> など)を入れると、同じ日のどの書き方もマスクされます:<em>1990/5/12</em>、<em>1990.05.12</em>、<em>1990年5月12日</em>、<em>19900512</em>、<em>May 12, 1990</em>。<em>13/05/1990</em> のような日が先の書き方は、日と月を取り違えようがないときだけです。別の日付や <em>1990.5.12.1</em> のようなバージョン番号はマスクされません。</td></tr>
<tr><td><span class="ui">ローカルモデルで検出</span></td><td><span class="ui">検出方法</span> の中にあります。このコンピュータで動くモデルが、ルールでは見つからない自由文中の名前や住所を見つけます。オフにしない限りオンで、最初にマスクするリクエストで AstrLink Guard をダウンロードします。ダウンロードが終わるまではルールだけでマスクします。<span class="ui">シークレットをマスク</span> か <span class="ui">個人情報をマスク</span> がオンのときに使え、見つけたものは同じスイッチに従います。横のメニューでモデルを選べます:AstrLink Guard(中国語と英語、39 MB のダウンロード、コードでの誤検出が少ない、Mac では Neural Engine で動く。既定)か OpenAI の Privacy Filter(1.6 GB、GPU を使える、コード中の普通の値も多く隠す)。その下の <span class="ui">信頼度のしきい値</span> は、値をマスクするのにモデルがどれだけ確かである必要があるかです。既定は Privacy Filter が 0.5、AstrLink Guard が公開元の 0.8。上げると普通の値のマスクは減りますが、本物の名前や住所もそのまま送られやすくなります。誤検出の多くはモデルのあとのルールが既に外すので、既定値は測った中で本物の値を最も逃さない値です。</td></tr>
+1 -1
View File
@@ -170,7 +170,7 @@
<h2 id="what"><a class="anchor" href="#what">What is masked</a></h2>
<div class="table-wrap"><table>
<tr><th>Switch</th><th>What it finds</th></tr>
<tr><td><span class="ui">Mask secrets</span></td><td>Private key blocks (<code>-----BEGIN … PRIVATE KEY-----</code>). API keys by their shape: <code>sk-…</code> (OpenAI, Anthropic, OpenRouter), <code>ghp_</code>/<code>github_pat_</code>, <code>glpat-</code>, <code>AIza…</code>, <code>xox…-</code>, <code>sk_live_</code>, <code>AKIA</code>/<code>ASIA</code>, <code>hf_</code>, <code>gsk_</code>, <code>xai-</code>, <code>npm_</code>, <code>pypi-</code>, <code>dop_v1_</code>, <code>SG.</code>, and relay keys like <code>oc_sk_…</code>. JWTs. The password in <code>user:password@host</code>. The value of a field named for a secret, as <code>.env</code> files and configs have them: <code>DB_PASSWORD=…</code>, <code>api_key: …</code>, <code>client_secret</code>, <code>token</code>, <code>credential</code>. Your own <span class="ui">Masking rules</span>. Wallet private keys by the shape their wallets export: a Bitcoin WIF, a BIP32 <code>xprv</code>, an Ethereum or TRON <code>0x</code> key, a Solana key or <code>id.json</code> keypair, a Sui <code>suiprivkey1…</code>, an Aptos <code>ed25519-priv-0x…</code>, a Stellar seed, a NEAR <code>ed25519:…</code> key, a Nostr <code>nsec1…</code>, an age identity, a Zcash extended spending key, and a 12 to 25 word seed phrase after <em>seed</em> or <em>mnemonic</em> whose every word is in the BIP39 list. A key with no prefix of its own is masked only when it checks out: a WIF or <code>xprv</code> by its checksum, a Solana key by its public half, a Stellar seed by its CRC, so a Solana transaction signature goes as written. A <code>0x</code> key has the shape of a transaction hash, so it is masked only after a key&rsquo;s name (<code>PRIVATE_KEY=</code>, <code>--private-key</code>, <code>new Wallet(…)</code>, 私钥); a hash, a storage slot or a sha256 sum goes as written. An exchange&rsquo;s API key, secret and <code>passphrase</code> go by their fields&rsquo; names.</td></tr>
<tr><td><span class="ui">Mask secrets</span></td><td>Private key blocks (<code>-----BEGIN … PRIVATE KEY-----</code>). API keys by their shape: <code>sk-…</code> (OpenAI, Anthropic, OpenRouter), <code>ghp_</code>/<code>github_pat_</code>, <code>glpat-</code>, <code>AIza…</code>, <code>xox…-</code>, <code>sk_live_</code>, <code>AKIA</code>/<code>ASIA</code>, <code>hf_</code>, <code>gsk_</code>, <code>xai-</code>, <code>npm_</code>, <code>pypi-</code>, <code>dop_v1_</code>, <code>SG.</code>, Cloudflare's (<code>cfut_</code>, <code>cfat_</code>, <code>cfk_</code>, <code>cfoat_</code>, Origin CA <code>v1.0-</code>, tunnel tokens), and relay keys like <code>oc_sk_…</code>. JWTs. The password in <code>user:password@host</code>. The value of a field named for a secret, as <code>.env</code> files and configs have them: <code>DB_PASSWORD=…</code>, <code>api_key: …</code>, <code>client_secret</code>, <code>token</code>, <code>credential</code>. Your own <span class="ui">Masking rules</span>. Wallet private keys by the shape their wallets export: a Bitcoin WIF, a BIP32 <code>xprv</code>, an Ethereum or TRON <code>0x</code> key, a Solana key or <code>id.json</code> keypair, a Sui <code>suiprivkey1…</code>, an Aptos <code>ed25519-priv-0x…</code>, a Stellar seed, a NEAR <code>ed25519:…</code> key, a Nostr <code>nsec1…</code>, an age identity, a Zcash extended spending key, and a 12 to 25 word seed phrase after <em>seed</em> or <em>mnemonic</em> whose every word is in the BIP39 list. A key with no prefix of its own is masked only when it checks out: a WIF or <code>xprv</code> by its checksum, a Solana key by its public half, a Stellar seed by its CRC, so a Solana transaction signature goes as written. A <code>0x</code> key has the shape of a transaction hash, so it is masked only after a key&rsquo;s name (<code>PRIVATE_KEY=</code>, <code>--private-key</code>, <code>new Wallet(…)</code>, 私钥); a hash, a storage slot or a sha256 sum goes as written. An exchange&rsquo;s API key, secret and <code>passphrase</code> go by their fields&rsquo; names.</td></tr>
<tr><td><span class="ui">Mask personal data</span></td><td>Emails, mainland China mobile numbers (not an 11-digit id: one under <code>order_id</code> or after 订单号 goes as written), Chinese ID numbers and bank card numbers whose checksum adds up. Also on by default: US Social Security numbers, passport numbers (after <em>passport</em>, 护照 or パスポート), IBANs, birthdays (next to <em>birthday</em>, <em>DOB</em> or 生日, and over a year ago, so today&rsquo;s date stays), MAC addresses and serial numbers (after <em>S/N</em>). Off until you turn them on, since agents send them in nearly every request: the user name in home folders (sent as a made-up name, the same every turn, so the model reads a real folder rather than a placeholder), user and computer names (<code>user@host</code>), public IP addresses (sent as a name such as <code>public-ip-kvxqmrtz</code>, so the model still knows the address is public and connects with it, and the real address goes back into its commands) and cloud storage buckets. A wallet or contract address (<code>0x</code> and 40 hex digits) is public and goes as written; a private key is still masked.</td></tr>
<tr><td><span class="ui">Masked words</span></td><td>Each word you listed, exactly, as <code>{{TERM_…}}</code>. A date, such as <em>1990-05-12</em>, matches that day however it is written: <em>1990/5/12</em>, <em>1990.05.12</em>, <em>1990年5月12日</em>, <em>19900512</em>, <em>May 12, 1990</em>, and <em>13/05/1990</em> style only where the day can’t be read as a month. Never another date or a version like <em>1990.5.12.1</em>.</td></tr>
<tr><td><span class="ui">Find with a local model</span></td><td>Under <span class="ui">How it’s found</span>. A model on this computer finds what no rule can: a name or an address in free text. It is on unless you turned it off, and AstrLink Guard downloads with the first masked request; until it is on disk, the rules mask alone. It needs <span class="ui">Mask secrets</span> or <span class="ui">Mask personal data</span> on, and finds under the same switches. The menu beside it picks the model: AstrLink Guard (Chinese and English, a 39 MB download, few false alarms in code, on a Mac it runs on the Neural Engine; the default) or OpenAI’s Privacy Filter (1.6 GB, uses the GPU, masks more ordinary values in code). <span class="ui">Confidence threshold</span> under it is how sure the model must be before a value is masked: Privacy Filter’s default is 0.5, AstrLink Guard’s 0.8, its publisher’s. Higher masks fewer ordinary values, and lets more real names and addresses through: the rules after the model drop most false alarms already, so the default is where we measured the fewest real values lost.</td></tr>
+1 -1
View File
@@ -170,7 +170,7 @@
<h2 id="what"><a class="anchor" href="#what">会遮掉什么</a></h2>
<div class="table-wrap"><table>
<tr><th>开关</th><th>能找到什么</th></tr>
<tr><td><span class="ui">脱敏密钥</span></td><td>私钥块(<code>-----BEGIN … PRIVATE KEY-----</code>)。按格式识别的 API Key:<code>sk-…</code>(OpenAI、Anthropic、OpenRouter)、<code>ghp_</code>/<code>github_pat_</code>、<code>glpat-</code>、<code>AIza…</code>、<code>xox…-</code>、<code>sk_live_</code>、<code>AKIA</code>/<code>ASIA</code>、<code>hf_</code>、<code>gsk_</code>、<code>xai-</code>、<code>npm_</code>、<code>pypi-</code>、<code>dop_v1_</code>、<code>SG.</code>,以及 <code>oc_sk_…</code> 这类中转站的 key。JWT。<code>user:password@host</code> 里的密码。<code>.env</code> 和配置文件里以密钥命名的字段的值:<code>DB_PASSWORD=…</code>、<code>api_key: …</code>、<code>client_secret</code>、<code>token</code>、<code>credential</code>。以及你的 <span class="ui">自定义脱敏规则</span>。 钱包私钥按钱包导出的格式匹配:比特币 WIF、BIP32 <code>xprv</code>、以太坊和 TRON 的 <code>0x</code> 私钥、Solana 私钥与 <code>id.json</code> 密钥对、Sui <code>suiprivkey1…</code>、Aptos <code>ed25519-priv-0x…</code>、Stellar 种子、NEAR <code>ed25519:…</code>、Nostr <code>nsec1…</code>、age 身份、Zcash 扩展支出密钥,以及 <em>seed</em>、<em>助记词</em> 后面、每个词都在 BIP39 词表里的 12 到 25 个单词。没有固定前缀的私钥要先通过校验才会被替换:WIF 和 <code>xprv</code> 看校验和,Solana 私钥看后半段公钥,Stellar 种子看 CRC,所以 Solana 交易签名照原样发送。<code>0x</code> 私钥和交易哈希形状相同,只在私钥的名字后面才替换(<code>PRIVATE_KEY=</code>、<code>--private-key</code>、<code>new Wallet(…)</code>、私钥);哈希、存储槽和 sha256 校验值照原样发送。交易所的 API key、secret 和 <code>passphrase</code> 按字段名替换。</td></tr>
<tr><td><span class="ui">脱敏密钥</span></td><td>私钥块(<code>-----BEGIN … PRIVATE KEY-----</code>)。按格式识别的 API Key:<code>sk-…</code>(OpenAI、Anthropic、OpenRouter)、<code>ghp_</code>/<code>github_pat_</code>、<code>glpat-</code>、<code>AIza…</code>、<code>xox…-</code>、<code>sk_live_</code>、<code>AKIA</code>/<code>ASIA</code>、<code>hf_</code>、<code>gsk_</code>、<code>xai-</code>、<code>npm_</code>、<code>pypi-</code>、<code>dop_v1_</code>、<code>SG.</code>、Cloudflare 的(<code>cfut_</code>、<code>cfat_</code>、<code>cfk_</code>、<code>cfoat_</code>、Origin CA <code>v1.0-</code>、Tunnel token),以及 <code>oc_sk_…</code> 这类中转站的 key。JWT。<code>user:password@host</code> 里的密码。<code>.env</code> 和配置文件里以密钥命名的字段的值:<code>DB_PASSWORD=…</code>、<code>api_key: …</code>、<code>client_secret</code>、<code>token</code>、<code>credential</code>。以及你的 <span class="ui">自定义脱敏规则</span>。 钱包私钥按钱包导出的格式匹配:比特币 WIF、BIP32 <code>xprv</code>、以太坊和 TRON 的 <code>0x</code> 私钥、Solana 私钥与 <code>id.json</code> 密钥对、Sui <code>suiprivkey1…</code>、Aptos <code>ed25519-priv-0x…</code>、Stellar 种子、NEAR <code>ed25519:…</code>、Nostr <code>nsec1…</code>、age 身份、Zcash 扩展支出密钥,以及 <em>seed</em>、<em>助记词</em> 后面、每个词都在 BIP39 词表里的 12 到 25 个单词。没有固定前缀的私钥要先通过校验才会被替换:WIF 和 <code>xprv</code> 看校验和,Solana 私钥看后半段公钥,Stellar 种子看 CRC,所以 Solana 交易签名照原样发送。<code>0x</code> 私钥和交易哈希形状相同,只在私钥的名字后面才替换(<code>PRIVATE_KEY=</code>、<code>--private-key</code>、<code>new Wallet(…)</code>、私钥);哈希、存储槽和 sha256 校验值照原样发送。交易所的 API key、secret 和 <code>passphrase</code> 按字段名替换。</td></tr>
<tr><td><span class="ui">脱敏个人信息</span></td><td>邮箱、中国大陆手机号(11 位的编号不算:在 <code>order_id</code> 下或跟在「订单号」后面的照原样发出)、校验位对得上的身份证号和银行卡号。默认也开着的:美国社会安全号、护照号(跟在 <em>passport</em>、护照或パスポート后面)、IBAN、生日(旁边有 <em>birthday</em>、<em>DOB</em> 或「生日」,且是一年以前的日期,所以今天的日期不动)、MAC 地址、序列号(跟在 <em>S/N</em> 后面)。默认关闭、需要自己打开的(Agent 几乎每个请求都会带):主目录里的用户名(以一个每轮都相同的假名发出,模型看到的是正常的文件夹,而不是占位符)、用户名和主机名(<code>user@host</code>)、公网 IP 地址(以 <code>public-ip-kvxqmrtz</code> 这样的名字发出,模型仍知道这是公网地址,照常用它连接,命令里再换回真实地址)、云存储桶。钱包或合约地址(<code>0x</code> 加 40 位十六进制)是公开的,照原样发出;私钥照样脱敏。</td></tr>
<tr><td><span class="ui">脱敏词</span></td><td>你填的每个词,精确匹配,换成 <code>{{TERM_…}}</code>。填的是日期(比如 <em>1990-05-12</em>)时,同一天的各种写法都会遮掉:<em>1990/5/12</em>、<em>1990.05.12</em>、<em>1990年5月12日</em>、<em>19900512</em>、<em>May 12, 1990</em>;<em>13/05/1990</em> 这种日在前的写法只在日和月不会混淆时才算。别的日期和 <em>1990.5.12.1</em> 这样的版本号不会被遮。</td></tr>
<tr><td><span class="ui">用本地模型查找</span></td><td>在 <span class="ui">怎么找</span> 下面。一个在这台电脑上运行的模型能找出规则找不到的东西:自由文本里的人名、地址。除非你关掉,它默认打开:第一个要脱敏的请求开始下载 AstrLink Guard,下载完成前只用规则脱敏。需要先打开 <span class="ui">脱敏密钥</span> 或 <span class="ui">脱敏个人信息</span>,找到的内容按同样的开关处理。旁边的菜单选择模型:AstrLink Guard(中英文,下载 39 MB,代码里很少误判,在 Mac 上用神经网络引擎运行;默认)或 OpenAI 的 Privacy Filter(1.6 GB,可用 GPU,代码里会遮盖更多普通值)。下面的 <span class="ui">置信度阈值</span> 是模型要多确定才遮盖一个值:Privacy Filter 默认 0.5,AstrLink Guard 默认 0.8(发布者的值)。调高会少遮一些普通值,也会让更多真实的人名、地址原样发出去;模型之后的规则已经去掉了大部分误判,所以默认值是我们测下来漏掉真实信息最少的那一档。</td></tr>
+1 -1
View File
@@ -3714,7 +3714,7 @@ There is no CLI command for it. Without the window (`magpie serve`, [Docker](htt
| Switch | What it finds |
| --- | --- |
| Mask secrets | Private key blocks (`-----BEGIN … PRIVATE KEY-----`). API keys by their shape: `sk-…` (OpenAI, Anthropic, OpenRouter), `ghp_`/`github_pat_`, `glpat-`, `AIza…`, `xox…-`, `sk_live_`, `AKIA`/`ASIA`, `hf_`, `gsk_`, `xai-`, `npm_`, `pypi-`, `dop_v1_`, `SG.`, and relay keys like `oc_sk_…`. JWTs. The password in `user:password@host`. The value of a field named for a secret, as `.env` files and configs have them: `DB_PASSWORD=…`, `api_key: …`, `client_secret`, `token`, `credential`. Your own Masking rules. Wallet private keys by the shape their wallets export: a Bitcoin WIF, a BIP32 `xprv`, an Ethereum or TRON `0x` key, a Solana key or `id.json` keypair, a Sui `suiprivkey1…`, an Aptos `ed25519-priv-0x…`, a Stellar seed, a NEAR `ed25519:…` key, a Nostr `nsec1…`, an age identity, a Zcash extended spending key, and a 12 to 25 word seed phrase after *seed* or *mnemonic* whose every word is in the BIP39 list. A key with no prefix of its own is masked only when it checks out: a WIF or `xprv` by its checksum, a Solana key by its public half, a Stellar seed by its CRC, so a Solana transaction signature goes as written. A `0x` key has the shape of a transaction hash, so it is masked only after a key&rsquo;s name (`PRIVATE_KEY=`, `--private-key`, `new Wallet(…)`, 私钥); a hash, a storage slot or a sha256 sum goes as written. An exchange&rsquo;s API key, secret and `passphrase` go by their fields&rsquo; names. |
| Mask secrets | Private key blocks (`-----BEGIN … PRIVATE KEY-----`). API keys by their shape: `sk-…` (OpenAI, Anthropic, OpenRouter), `ghp_`/`github_pat_`, `glpat-`, `AIza…`, `xox…-`, `sk_live_`, `AKIA`/`ASIA`, `hf_`, `gsk_`, `xai-`, `npm_`, `pypi-`, `dop_v1_`, `SG.`, Cloudflare's (`cfut_`, `cfat_`, `cfk_`, `cfoat_`, Origin CA `v1.0-`, tunnel tokens), and relay keys like `oc_sk_…`. JWTs. The password in `user:password@host`. The value of a field named for a secret, as `.env` files and configs have them: `DB_PASSWORD=…`, `api_key: …`, `client_secret`, `token`, `credential`. Your own Masking rules. Wallet private keys by the shape their wallets export: a Bitcoin WIF, a BIP32 `xprv`, an Ethereum or TRON `0x` key, a Solana key or `id.json` keypair, a Sui `suiprivkey1…`, an Aptos `ed25519-priv-0x…`, a Stellar seed, a NEAR `ed25519:…` key, a Nostr `nsec1…`, an age identity, a Zcash extended spending key, and a 12 to 25 word seed phrase after *seed* or *mnemonic* whose every word is in the BIP39 list. A key with no prefix of its own is masked only when it checks out: a WIF or `xprv` by its checksum, a Solana key by its public half, a Stellar seed by its CRC, so a Solana transaction signature goes as written. A `0x` key has the shape of a transaction hash, so it is masked only after a key&rsquo;s name (`PRIVATE_KEY=`, `--private-key`, `new Wallet(…)`, 私钥); a hash, a storage slot or a sha256 sum goes as written. An exchange&rsquo;s API key, secret and `passphrase` go by their fields&rsquo; names. |
| Mask personal data | Emails, mainland China mobile numbers (not an 11-digit id: one under `order_id` or after 订单号 goes as written), Chinese ID numbers and bank card numbers whose checksum adds up. Also on by default: US Social Security numbers, passport numbers (after *passport*, 护照 or パスポート), IBANs, birthdays (next to *birthday*, *DOB* or 生日, and over a year ago, so today&rsquo;s date stays), MAC addresses and serial numbers (after *S/N*). Off until you turn them on, since agents send them in nearly every request: the user name in home folders (sent as a made-up name, the same every turn, so the model reads a real folder rather than a placeholder), user and computer names (`user@host`), public IP addresses (sent as a name such as `public-ip-kvxqmrtz`, so the model still knows the address is public and connects with it, and the real address goes back into its commands) and cloud storage buckets. A wallet or contract address (`0x` and 40 hex digits) is public and goes as written; a private key is still masked. |
| Masked words | Each word you listed, exactly, as `{{TERM_…}}`. A date, such as *1990-05-12*, matches that day however it is written: *1990/5/12*, *1990.05.12*, *1990年5月12日*, *19900512*, *May 12, 1990*, and *13/05/1990* style only where the day can’t be read as a month. Never another date or a version like *1990.5.12.1*. |
| Find with a local model | Under How it’s found. A model on this computer finds what no rule can: a name or an address in free text. It is on unless you turned it off, and AstrLink Guard downloads with the first masked request; until it is on disk, the rules mask alone. It needs Mask secrets or Mask personal data on, and finds under the same switches. The menu beside it picks the model: AstrLink Guard (Chinese and English, a 39 MB download, few false alarms in code, on a Mac it runs on the Neural Engine; the default) or OpenAI’s Privacy Filter (1.6 GB, uses the GPU, masks more ordinary values in code). Confidence threshold under it is how sure the model must be before a value is masked: Privacy Filter’s default is 0.5, AstrLink Guard’s 0.8, its publisher’s. Higher masks fewer ordinary values, and lets more real names and addresses through: the rules after the model drop most false alarms already, so the default is where we measured the fewest real values lost. |