714ab8e8b masked a password after 密码/密碼/口令/パスワード/비밀번호. The reporter
came back with the rest of how a secret is sent in a Chinese chat: "密钥为 xxx",
"apikey 为 xxx", 密钥是, 秘钥, 私钥, 令牌, "token 是 xxx", "API Key 为 xxx". These
went to the vendor as written.
Now:
- A value after a CJK name for a key, secret or token is masked as SECRET:
密钥, 密鑰, 秘钥, 秘鑰, 私钥, 私鑰, 金钥, 金鑰, 令牌, 权杖, 權杖, 秘密鍵, トークン,
シークレット, APIキー, アクセスキー, 토큰, 비밀키, API 키. The value has letters and
digits both, or is 16+ characters with a letter, so "RSA 密钥为 2048 位" stays.
- An English name (password, passwd, pwd, secret, token, api key, access key,
private key, credential, key; DB_PASSWORD and access_token too) right before
为, 為, 是 or a full-width colon is masked the same way. "token: x" with an
ASCII colon stays the config rule's, as before.
- 为 and 為 join :, :, =, 是, は, 는 after any CJK name, so "密码为 hunter22" is
masked too; 암호 (Korean) joins the password names.
Left as they were (tested): 请输入密钥, 请输入密钥:, 密钥管理, 忘记密钥了怎么办,
令牌桶算法, 私钥文件放在哪, 密钥:${API_KEY}, 密钥:****, token 是 ****,
apikey 为 ${OPENAI_API_KEY}, RSA 密钥为 2048 位, token 是 expired, 这个 key 是 value,
token 是 abc, key 是什么, API Key 为空, and every case of TestCJKPasswordMasked.
Cost: the English rule is run only near 为/為/是/: (fold, 24 bytes back,
260 ahead), and the CJK rules only near their names. Doing that showed that
matches() looked back for the line's start from every fold marker through
the whole text, which is quadratic on a one-line request body: with the
English rule folded on key/token, Mask over 1.5MB of dense text took 10.4s
(0.12s before). The line's start is now looked for no further back than
`back`, which is what the window used anyway. Benchmarked Mask on 156KB of
dense Chinese, of dense code+JSON, and on redact.go itself, against
origin/main: within noise of it on a box at load ~200 (zh 31-36ms vs 13-37ms,
code 72-84ms vs 55-72ms, src 12-14ms vs 24-36ms); benchmark not committed.
Run at this head:
- go test ./internal/redact ./internal/masking ./internal/otlp ./internal/pii
./internal/settings ./internal/sessions -count=1: ok
- go test ./internal/gateway -run 'CJK|Mask|Redact|Privacy' -count=1: ok
- gofmt -l, go vet ./internal/redact, GOOS=windows go vet ./internal/redact: clean
- Broken by hand: with origin/main's redact.go, TestCJKSecretNamesMasked fails
16 of 19 masked cases and the JSON body case (账号密码 admin123 and 口令是 …
were already masked). With the CJK rules' window back set to 0,
"WiFi密码:20261025" and "admin密钥是k9j8h7g6f5" go unmasked (fixed with back 64).
Not tried: the GUI try box in a running magpie, and the full suite.