Files
magpie/internal/redact
yetone ab98228cc1 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).
2026-11-12 19:31:43 +08:00
..