Commit Graph
2 Commits
Author SHA1 Message Date
yetone fc91e58ba4 redact: a bare JSON number ("timestamp": 17929036837) is not masked as a phone (id.null on Discord)
The 脱敏 before/after view showed a tool result holding a session file's
JSONL line, and its "timestamp": 17929036837 went as {{PHONE_…}}. The
PHONE rule is 1[3-9]\d{9} bounded by digits, so any 11-digit number
starting 13-19 is a CN mobile wherever it sits. A phone, a card or an ID
number in JSON is a string; a bare number there is a count, an id or a
time.

Now a personal kind's value that is all of a bare JSON number is left,
judged by where it sits and its form, not by the key's name: digits only,
after "key": (an object's value) or inside an array of numbers, with only
, } ] or the text's end after it. It sits beside the decimal check
(noDecimals, now noNumbers), so it holds for what the rules, the model
and values known before find alike. A BANK_CARD (Luhn-valid snowflake)
and an ID_CARD's digits as JSON numbers are left the same way.

Still masked (tested): "phone": "13800138000", ["13800138000"],
phone:13800138000, "call 13800138000, thanks", 我的号码 13800138000,谢谢,
"numbers 13900139000, 13800138000]" (no [ before), a phone inside a JSON
string's text, "card": "4111111111111111", and every case of
TestStandaloneNumbersStillMasked. "phone": 13800138000 as a number is
left too; that is the cost of not going by the key's name.

Run at this head:
- go test ./internal/redact ./internal/pii ./internal/settings
  ./internal/masking ./internal/otlp ./internal/sessions ./internal/gui
  -count=1: ok
- go test ./internal/gateway -run 'CJK|Mask|Redact|Privacy|PII|Secret': ok
- gofmt -l, go vet, GOOS=windows go vet, GOOS=linux go vet -tags nogui
  ./internal/redact: clean
- Broken by hand: with origin/main's redact.go, TestBareJSONNumberNotMasked
  fails 7 cases (the reporter's line, {"n": 13800138000}, a spread-out
  object, two arrays, the card and the ID number). The 10- and 13-digit
  epochs were not masked before either; they are in the test to stay so.

Not tried: the GUI before/after view in a running magpie, and the full suite.
2026-10-25 16:47:29 +08:00
yetone ec7e50b828 redact: a decimal's digits are not masked as a number of their own (willz, Discord)
willz on Discord: a tool's JSON with "height": 5.13393848347348 went to
the vendor with part of the number as a placeholder. A run of digits
right after the point of a decimal, or right before it, was judged on
its own: 0.13800138000 went as 0.{{PHONE_…}}, 6.4111111111111111e-3 as
6.{{BANK_CARD_…}}e-3, 1.110105194912310038 as 1.{{ID_CARD_…}}, and
13800138000.5 as {{PHONE_…}}.5. The rules' bound only kept digits off
either side, not a point with a digit beyond it.

mask now drops, after noIDs, any span of a personal-data kind (kindCats:
PHONE, BANK_CARD, ID_CARD, SSN, IP, the model's ACCOUNT and PHONE, …)
that starts with a digit after "<digit>." or ends with a digit before
".<digit>" (noDecimals, inDecimal). It is one choke point for every
finder: the rules, the local model's spans and values known from
before. Not changed: secrets (a key or password masked once is masked
wherever it is, a decimal's digits too), the user's words and rules,
and the signed-thinking path, which re-masks only secrets. A phone
number or card standing alone, in text, after a colon, in a JSON
string, or at a sentence's end ("13800138000.") is masked as before.
A number list written "1.13800138000" with no space now goes as
written; a comma decimal (5,13800138000) is not treated as one.

Reporter's literal: at 86254d404 the rules alone leave
5.13393848347348 as written (the 14 fractional digits are too long for
a phone or a card); it is masked when the local model labels the
fraction (TestDecimalDigitsNotMaskedByModel, 5.{{ACCOUNT_…}} on the old
code) or once its digits are a known value, which is how it leaked
into another test's body on the old code. Which finder masked it for
willz is not known; the fix covers all three.

Tests (decimal_test.go): TestDecimalDigitsNotMasked (the reporter's
bytes and siblings: negative, exponent, ID card, whole part, text, many
digits; through Mask and MaskJSON in a tool_result),
TestDecimalDigitsNotMaskedByModel, TestKnownNumberNotInDecimal (plain
and in a signed thinking block), TestStandaloneNumbersStillMasked,
TestKnownSecretInDecimalStillMasked.

Run at 28d191fbe (on origin/main 86254d404):
- old redact.go with the new tests: all four decimal tests FAIL as above
  (TestStandaloneNumbersStillMasked too, through the known ACCOUNT).
- broken by hand: without the fraction-side check 12 failing lines;
  without the whole-part-side check, {"total": 13800138000.5} and
  "13800138000.25" fail; without the personal-kind scope,
  TestKnownSecretInDecimalStillMasked fails.
- gofmt -l internal/redact: empty. go vet ./..., GOOS=linux go vet
  -tags nogui ./..., GOOS=windows go vet ./...: ok.
- go test -timeout 45m ./... (one suite on the machine, checked with
  ps): 68 packages ok, no FAIL; internal/redact, internal/gateway and
  internal/agent ok. An earlier full run during the edit also passed.
- after rebasing on fresh origin/main: go test ./internal/redact/... ok.

Not tried: the real local model (internal/pii) on willz's text, a real
gateway request, Windows or Linux runs of the package. No docs page
describes the rules' boundaries, so none changed.
2026-10-22 17:49:49 +08:00