Files
magpie/internal/redact
yetoneandRex Zhou 5673eab0ba redact: mask crypto wallet keys, seed phrases and exchange passphrases (#4025, rexzh0u on X)
Rex Zhou's #4025 proposed default rules for crypto secrets. This ports
them with every shape that can also be ordinary text checked first:

- WALLET_KEY: 64 hex digits (0x or bare) only after a key's name on the
  same line (private key, secret, signer, deployer, wallet, pk, 私钥 …),
  and not when a hash, sha, digest, sum, pub, addr, tx or an id name sits
  between: tx hashes, block hashes, storage slots and sha256 sums go as
  written. noIDs keeps it, since the name already says it is a key.
- WIF and BIP32 xprv/tprv: base58check (double sha256) and payload length,
  so a random base58 run, an xpub or an address is not one.
- Solana: a base58 secret or a 64-number keyfile counts only when its
  second half is the ed25519 public key of its first; a tx signature,
  same length, goes as written. Each number in a keyfile is <= 255.
- Stellar S... seeds: StrKey version byte and CRC16-XModem.
- Prefixed kinds: NEAR ed25519:, Sui suiprivkey1, Aptos AIP-80
  ed25519-priv-0x, Nostr nsec1, age, Zcash secret-extended-key.
- SEED_PHRASE: after seed/mnemonic/phrase/recovery (and zh, ja, ko), the
  longest run of words from the BIP39 English list, cut to 12/15/18/21/
  24/25 words. The list is embedded, its sha256 checked by a test against
  the published one. A sentence after "recovery" has words off the list.
- Exchange keys: secretNames gains passphrase/pass (OKX, Coinbase, KuCoin)
  and priv_key; API key and secret fields were already masked by name.

What the patch had that does not ship: every 0x+64 hex masked (tx and
block hashes), unchecked base58 lengths for WIF and Solana (any long
base58 run), and a phrase pattern that took prose after "recovery".

The three rules with no marker (WIF, Solana, Stellar) run their pattern
only after a byte scan finds a long enough run (rule.may). Without it the
prose benchmark went from 2.9ms to 15.8ms per MB; with it 3.0ms, the
same as without the rules (profile: sha256 of the memo and memmove).

Run (wsl-run magpie-desktop, mote refused SSH all session):
- go test -count=1 ./internal/redact: ok
- go test -run TestCountTokensRedacted ./internal/gateway: ok (crypto on
  with Redact, off with RedactPersonal only)
- gofmt -l; go vet linux, -tags nogui, GOOS=darwin, GOOS=windows for
  internal/redact and internal/gateway: clean
- node --test site/worker.test.mjs (llms-full, docs): 7 of 7
- false positives: 1000 npm sha512 integrity lines, go.sum h1 lines,
  git shas, uuids, sha256 sums, std and URL-safe base64 blobs, xpub,
  addresses, IPFS CIDs, bech32, npub, public keys: none masked.
- 1MB inputs of each shape stay linear (RE2, no backtracking).

Broken by hand, each red: Solana unchecked (Lookalikes, Lengths), WIF
unchecked (Lookalikes), WALLET_KEY without its name check
(WalletKeyNeedsItsName, LockfilesAndBlobs), phrase without the wordlist
(SeedPhrase), Stellar unchecked and keyfile unchecked (Lookalikes), rules
unwired (7 tests).

Not tried: real wallets (test vectors are the BIPs', NIP-19's and
derived keys); Monero's own word list; other BIP39 languages; a Windows
or macOS run of the tests; the full suite (after the tag).

Co-authored-by: Rex Zhou <zhouzhuojie@gmail.com>
2026-11-10 19:00:46 +08:00
..