Files
magpie/internal/redact
yetone ee715c2e0e redact: a key or token after 密钥, 令牌, 金鑰…, or apikey/token before 为/是/:, is masked (CyberCaius on Discord)
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.
2026-10-25 15:27:39 +08:00
..
gateway: a request archive, off unless turned on, keeps each call's headers and bodies in the user's own S3 bucket and a recent call reads its own back (Jorben on Discord: 请求存档) — the Gateway page's recent calls only ever held the last bodies in memory, the first 256 KB of each, with no headers, gone at a restart. A switch over Recent calls ("Request archive", POST /api/settings/archive, settings' requestArchive) turns it on, refused with a reason while sync isn't set up with an s3:// bucket; with it on, each call the gateway serves gets an id (UTC HHMMSS-<16 hex>, said back in X-Magpie-Archive-Id) and, once it is recorded, its method, path and query, request headers and body and response status, headers and body go as one JSON file to <prefix>/magpie/archive/<YYYY-MM-DD>/<id>.json in the bucket sync keeps its backup in, signed with the same client (davsync.Bucket, no new SDK). Before anything leaves, Authorization, x-api-key, Cookie, Set-Cookie, any header or JSON field or query parameter named for a key, token, secret or password, and anything that looks like a key or token anywhere in the text (the redaction rules' patterns, in a stream's data lines too) become [REDACTED] — gone, no placeholder kept; the archive is plain JSON, readable in the bucket, not sealed with the passphrase. Uploads go one at a time on their own goroutine from a queue of 16 calls, each body capped at the 256 KB the call already keeps and marked truncated; a full queue drops the call with a log line, a failed upload is logged and shown under the switch until the next one goes, and no request waits on any of it. A recent call the archive kept shows its date and id under its bodies, and "Fetch from archive" (GET /api/archive?date=&id=, only a date and an id of that shape) shows the request's and response's headers and bodies as the bucket has them, or says it isn't there yet. The hook is in record() and the Call literal, so PR #239's request log lines are not touched; the archived call carries its usage, and with #239 its vendor request id. Only calls through serve() are archived, not Codex's backend, image or video calls. TestArchiveOn, TestArchiveOff, TestArchiveName, TestRequestArchiveToS3 (a real gateway request through the signature-checking fake S3), TestScrub and request-archive.test.cjs fail without the change; TestSettingsSaveKeepsWhatItDoesNotSend now sets requestArchive. A sandbox magpie web with a fake vendor and a fake S3 server uploaded nothing while off; on, it uploaded a signed archive with none of eight planted secrets in it, read it back through /api/archive and in the page, and with the S3 server down served the call in 0.1 s and said why the upload failed. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (Claude account tests and TestClaudeRunEndsWhenTheClientLeaves pass alone); request-archive, click-scroll, old-webkit, sse-body, gateway-fold pass.
2026-10-01 17:13:34 +08:00