1ccacad63281094de8a3372d5a507d38f9969e5c
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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> |
||
|
|
189db9ba5b |
redact: ids, digests and 毛利 go as written; the slider reaches known values; a user name goes as a made-up name
Reports on X under the masking demo (10-28):
_kaichen: "hash类型也会被过滤…长int,假如以1为开头的…会被当作电话被mask;
"毛利低"也会被当作人名被mask。即使把匹配拉到 0.95,也是一样行为".
- Hex digests: 16 to 31 hex digits in one case, with letters and digits
both (a cache key, a short commit), are ids now (digestShaped in
ids.go), like UUIDs and 32+ hex. The rules' SECRET keeps one only under
a credential's field or a CJK/prose key with no field word (密钥为…);
the model's SECRET is dropped under a field named for something else
(cache_key, commit, object, blob, file, content, revision, partition,
shard, bucket, dedup, lookup, row, sort) and on a JSON object's key
(nameOfField). A bare `key` after api/access/secret/private/signing/
license is still a credential (keyPhrase). The IBAN case kept its mask
through the letter/digit minimums.
- 11-digit 1x numbers (phone.go, phoneAt): a phone with +86/86, as the
value of a field whose name says phone (phone, mobile, tel, cell,
contact, 手机, 电话, `number`), or in prose with no id word right
before it (order, id, no., #, 订单号, 编号, 单号, 流水号…). Under
order_id/uid, after 订单号, or with a letter or digit against it, it
goes as written. PHONE and BANK_CARD are bounded by alnum, not digits,
in the rule and in known values.
- 毛利: zhWords gained 毛利, 毛重, 毛坯, 毛巾, 毛衣, so 毛利低 (a margin)
is no surname+name. The model still finds 毛利兰 (Guard). 毛利小五郎
(indekkusu141209) is masked by neither model nor the rules now.
- The slider: a value masked once was masked again as known whatever the
threshold. Each value now remembers the highest score it was found
with (rules count as sure, ruleFound), and knownSpans skips one under
Options.MinScore, which masking sets from pii.Threshold.
eerttreeeert: with mimo-v2.6-flash the home folder went as
C:\Users\{{USERNAME_…}}; the model took it for a temp folder and set out
to delete it. With the user name switch on, it now goes as a made-up name
of 8 lowercase letters (HMAC of the name, same every turn, standIn in
shape.go), restored in replies and tool calls like any placeholder;
Preview shows the same name.
Docs: docs/subsystems/gateway-routing.md masking bullets, and the site's
masking page (en, zh, ja) on mobile ids and the user name.
Run (mote, at this tree on base 6af83172d; rebased onto
|
||
|
|
1cbdda25be |
redact: cua-driver's element tokens go as written (#3782)
Hu9956 (#3782): with masking on, DeepSeek Harness's computer use (cua-driver: a window's state, then a click on one of its elements) went to the vendor with element_token values as {{SECRET_...}}, found by the rules. cua-driver hands the model a token for each element of a window: s, the snapshot's counter in 8 hex digits, a colon and the element's index (s0000002a:14). The model clicks by it. The SECRET rule takes a value of 8 or more letters and digits after a field whose name holds "token", and element_token is one, so each token in a window's state, in a click's arguments and in a shell command's JSON went as a placeholder and its index ({{SECRET_...}}:74). Two of the report's places show the token with no index ("element_token": "s00000001"), so that is taken as it is written too. noIDs, which lets a backend's id (a UUID, 32 hex digits or more) go as written unless its field is named for a credential, now takes an element token for one too (elementToken): s and 8 lowercase hex digits, then a colon and the index, with no letter, digit or _ on either side. Without the index, s and 8 hex digits is one only as the value of a field named for an element: alone in a text it may be a student's number (s12345678), which the local model may call an account. A field named for an element is no credential's, as one named for a page, a cursor or a request isn't (credentialField, whose field name reading is now fieldWords). So element_token's value goes as written, while the same value after password=, token:, "refresh_token": or "api_key": is masked, and so is a value of any other shape in element_token. A token the local model takes for a secret, or anything else, goes as written, as a UUID does. The user's own words still mask one. docs/subsystems/gateway-routing.md says so. A UUID in a field named for an element (element_token) goes as written now too, as one in next_page_token does. What was run (tree bb52fa4d, on origin/main |
||
|
|
0ddcf28a1d |
redact: a backend's id (a UUID, 32+ hex digits) goes as written, never a piece of it
The owner found UUIDs masked, and a backend looks an id up by every
character: a masked one, or half of one, finds nothing or the wrong row.
A probe with every kind on and the model labelling each value found five
ways a UUID went masked:
- a piece of one: PHONE took 13800138000 at the end of
…-a13800138000, BANK_CARD took 4111-1111-1111-9007 across a UUID's
groups, and the id went half a placeholder;
- the SECRET rule in a field named for an id, a cursor or a request:
secret_id, token_id, api_key_id, access_key_id, next_page_token,
nextPageToken, csrf_token, trace_token, secret_hash;
- the bare "key" rule ("key": "<uuid>", Idempotency-Key);
- the serial rule (sn:, Serial Number:);
- the model labelling a UUID a name, an account and so on (only
"secret" was held back before), and a phone number masked earlier
being found again inside a UUID.
noIDs (internal/redact/ids.go) drops, after every finder, a span that is
a piece of an id, and a whole id unless the user's own words or rules
found it, a PASSWORD/API_KEY/TOKEN/PRIVATE_KEY rule did, the SECRET rule
did in a field named for a credential (password=, api_key=, X-Api-Key,
refresh_token, session_token, token), or it was masked before in full.
32 hex digits without hyphens the model calls a secret in prose ("the api
key is 9f8e…") stay masked; a UUID it calls one does not, as before.
Run in ~/workspace/projects/magpie-wt/mask-act at this tree:
- TestIDsGoAsWritten: 7 id shapes × 22 contexts kept, 7 credential
contexts masked, the model's every label kept, a known phone not found
inside an id, a phone and a card number of their own masked, the user's
word masked. With noIDs taken out of mask(): 108 failures; restored: ok.
- The first full redact run caught two of my own mistakes, now fixed:
idAround didn't check the run's inside, so a 33-character IPv6 address
counted as an id (TestMoreKinds), and the model's 32-hex API key went
unmasked (TestModelSecretIsNoID).
- go test ./internal/redact ./internal/maskrec ./internal/gwmw
./internal/settings ./internal/gateway (-timeout 45m, -count=1): all ok (gateway 439s)
- gofmt -l: none; go vet ./internal/redact for darwin, linux, windows: ok.
Not tried: a real request through a running gateway with the local model
on; the model's labels are simulated with fakeModel.
|