lc asked in #feedback (message 1558300896142696549) for magpie's masking
to cover more of what identifies a person or a machine. Under Settings >
Privacy > Mask personal data, each kind now has its own Off/On
(settings.redactKinds, redact.Options.Kinds). What each one masks:
- US SSNs: dashed numbers, except ones never issued (000, 666 and 9xx
areas) and well-known examples. Undashed ones only next to "SSN" or
"social security".
- Passport numbers, next to passport, Reisepass, 护照 or パスポート.
- IBANs: compact or in groups of four, with the country's length and the
mod-97 check.
- Birthdays: a date only next to birthday, DOB, born, 生日 and the like.
A date on its own stays.
- MAC addresses, but not documentation examples or all-decimal groups.
- Serial numbers, next to S/N, serial or 序列号.
- The user name in /Users/x, /home/x and C:\Users\x. The name is masked
and the path is kept.
- User and host in a shell prompt or an ssh/scp/rsync target (user@host
goes out as two placeholders, not as an email address), and on
hostname/user lines whose value ends the line. Code such as
`hostname = socket.gethostname()` is left alone.
- Public IPv4 and IPv6 addresses. Private, loopback, link-local, CGNAT,
documentation, multicast and well-known resolver addresses stay, and so
do version numbers.
- Cloud bucket names in s3://, gs://, oss://, cos://, abfss:// and
storage URLs. The object path is kept.
The last four are off by default. Agents send their working folder, the
prompt and log lines in nearly every request, and the model then has to
copy the placeholder exactly inside a path or URL. The first six are
rare and sensitive, so they are on. Each placeholder is restored in
replies, in streamed text and in tool-call JSON. Context rules run only
in a window around their words (rule.matches), so masking with the
defaults on 400KB of app.js takes 136ms (112ms before; 222ms with every
kind on).
Tests, run at this head:
- gofmt -l is clean. go vet passes on darwin, GOOS=linux and
GOOS=windows (-tags nogui) for internal/redact, gateway, gui and
settings.
- go test -tags nogui ./... under a temp HOME with pinned caches passed
everywhere except internal/proc's TestNoCommandBypassesProc. That
failure came from 2da8fbe4, and b934d64a fixed it on main. After the
rebase, the changed packages and internal/proc were run again and
passed. New tests:
- internal/redact TestMoreKinds, TestMoreKindsLeaveAlone (versions,
timestamps, hashes, UUIDs, model ids, code, ordinary dates, URLs in
code), TestCategoryDefaults, TestMoreKindsKnown, TestMoreKindsJSON.
- internal/gateway TestRedactedKinds.
- internal/gui TestRedactKindsAreRedacts.
- I broke the IBAN checksum by hand and TestMoreKindsLeaveAlone went
red.
- GUI tests pass in Chromium and WebKit:
- the new redact-kinds.test.cjs (en, zh, zh-TW, ja and de, at 1100
and 640 px);
- i18n-keys, gui-de, gui-ja, gui-zh-tw, redact-rule-row,
privacy-hides-accounts, privacy-usage-stats, settings-groups,
settings-sections and mobile-web;
- 29 more files that open the Privacy page (252 tests).
privacy-usage-stats now scrolls with the wheel to reach Count me as a
user, which the new rows push below its 760px window. WebKit doesn't
let a script scroll Settings.
- Real gateway check: a `magpie serve` built from this tree, under a
sandbox HOME, on 127.0.0.1:3492, with a fake OpenAI upstream on 3491.
An Anthropic /v1/messages request went to the upstream with each kind
as a placeholder. Turning SSNs off and home folders on changed what
was sent the same way. The streamed reply came back with every value
restored.
The masking rules find a value by what is around it: DB_PASSWORD= before
a password, a bound an email may not touch (so an email that ends a
sentence isn't one). The vendor writes about a placeholder in words of
its own ("your password is {{SECRET_…}}", "I will write to {{EMAIL_…}}."),
the agent reads the value there (Restore), and on the next turn that text
is in the history, where no rule matches it, so it went out as written.
Now every value a placeholder was made for (redact's in-memory values,
bounded by maxValues, never written anywhere) is also matched as an exact
string in each string Mask and MaskJSON look at, and goes as the same
placeholder it had (same kind, same keyed hash), so history and vendor
caches stay stable:
- only from 8 characters (the assignment rule's minimum): the 3-character
passwords the user:password@ rule takes, and the user's own words
(which Options.Words matches everywhere already), are not;
- personal values only while personal masking is on, secrets only while
secret masking is on;
- not as a piece of a longer value: a phone or card number with a digit
beside it, an email inside a longer address (a full stop after it may
end the sentence), a secret with a letter or digit against it;
- where a rule finds the same span, the rule's kind still wins, so
nothing masked before changes placeholder;
- in what a vendor signed (7137feb4), the values masked elsewhere in the
request go back as their placeholders as before, and so do known
secrets, for a turn whose other copies were compacted away; known
personal values don't, since a number the vendor wrote of its own
(13800138000) may be one masked in another conversation, and masking
it would break the signature.
A prefix index and a 4-byte bitset keep the lookup cheap: a ~1 MB body
masked in ~79 ms with 0, 1k or 200k known values alike (rules dominate).
Every route goes through redact.MaskJSON / Mask (chat, Responses,
Anthropic, Gemini, count_tokens, embeddings/rerank, the Codex backend,
image and video prompts), so each gets it; Scrub, the archive's, gets the
known secrets too.
Tests: TestEchoedValueMaskedNextTurn (gateway: two chat turns where the
fake vendor echoes the placeholders in other words; the second request
must not hold the password or the email, and keeps the first turn's
placeholders; then the echoed text alone through /v1/responses,
/v1/messages, count_tokens, Gemini generateContent, embeddings and the
Codex backend) fails on origin/main with the second turn sending
"…password is Mv4kestrelPass28, and I will write to
tomas.ng@quietfield.dev.". TestKnownValueMaskedInOtherWords and
TestKnownInSigned fail there too; TestShortValueNotMaskedEverywhere and
TestKnownReindexed pin the bounds and the eviction rebuild.
Run: gofmt -l (nothing); go vet -tags nogui ./... on darwin,
GOOS=linux and GOOS=windows; go build -tags nogui for darwin, linux,
windows; go test -tags nogui ./... under a temp HOME with pinned caches
(all ok); internal/redact -count=3 and -race. Not tried against a real
vendor.