redact: a one-word name the model flags goes out only beside a thing's word, never alone or in tool arguments

With a model that labels Rina a PERSON, at origin/main 49c9491b7, these
went out unmasked through 4e7661adc's app-name exemption (thingNamed):
a tool_use {"recipient":"Rina"} and user content "Rina" (namesOnly took
one capitalized word for a list of app names), "Rina's Mac won't boot"
and "Rina uses Windows at home" (an app's or a system's word anywhere in
the clause, thingWords, counted as a cue).

thingNamed now:
- treats a possessive right after the word ('s, ’s) as a person's;
- no longer takes a thing word (or a Chinese one, zhThingWords, now
  gone) anywhere in the clause as a cue: only the word right before or
  after counts (using X, the X app, X vs, X 这个软件), or the item's
  place in a list of apps;
- takes a text of names only when it has two of them at least.
personFits never applies the exemption in a tool call's arguments
(Options.args, set by MaskJSON under args or an "arguments" string).

Cases 4e7661adc was written for that are exactly the leak, and are
masked now (filed as #5506):
- "Muesli" alone (thingname_test, and eval case app-alone, now Keep
  with Known #5506 for Privacy Filter);
- "Which is better for notes on my Mac, Cicada or Mimi?" and the
  "Cicada 和 Mimi 呢" half of "Parakeet 这个软件很好用,Cicada 和 Mimi
  呢?", whose only cue is elsewhere in the sentence. They are taken out
  of TestAppNamesNotPersons; "Parakeet 这个软件很好用。" stays.
- TestPersonBesideAppStillMasked's lone "Mimi" was let go "by design";
  it is masked now.
The rest of TestAppNamesNotPersons (the bare list, "Cicada and Mimi",
the Markdown list, switched to, crashes, using, vs, apps like) and every
other eval case pass unchanged.

TestFirstNameNearAThingMasked holds the four reported texts, ’s,
"Send the license to Rina." and three bodies (user text, tool_use input,
a function_call's arguments string), and that "using Rina" and "the Rina
app" still go as written. Broken by hand: with thingname.go, model.go,
redact.go and json.go as on main it fails on all 9 masked cases (and the
lone Mimi); with only the args flag forced off, the two tool-argument
cases with an app's word beside the name ("install Rina", "using Rina")
go out.

Run at 4c0e22aa7, this stack's head on origin/main c6b7bbedf, on mote:
- gofmt -l clean on the changed files.
- go vet -tags nogui, GOOS=linux go vet -tags nogui (./internal/redact
  ./internal/gateway) and GOOS=windows go vet ./internal/redact: clean.
- go test -tags nogui ./internal/redact ./internal/gateway -count=1
  -timeout 45m: ok (redact 2.6s, gateway 1837s at load ~100).
Not run: go test ./... (the change is internal/redact only) and the
GUI suite (no GUI file touched).
This commit is contained in:
yetone
2026-11-06 18:36:19 +08:00
parent d7714b3f3b
commit 2b2abec457
6 changed files with 77 additions and 28 deletions
+3 -1
View File
@@ -314,9 +314,11 @@ var evalCases = []evalCase{
Keep: []evalValue{{V: "Cicada", Kind: "PERSON"}, {V: "Mimi", Kind: "PERSON"}, {V: "Phosphor", Kind: "PERSON"}, {V: "Parakeet", Kind: "PERSON"}, {V: "Muesli", Kind: "PERSON"}},
},
{
// a word alone says nothing whose, and may be a person's
// ("Rina"): what the model takes for a name is masked (#5506)
ID: "app-alone", From: "ylorn.",
Text: "Muesli",
Keep: []evalValue{{V: "Muesli", Kind: "PERSON"}},
Keep: []evalValue{{V: "Muesli", Kind: "PERSON", Known: "#5506"}},
},
{
ID: "app-markdown", From: "ylorn.",
+3 -1
View File
@@ -470,7 +470,9 @@ func MaskJSON(body []byte, o Options) ([]byte, int) {
if !masked(path, key, s) || under(path, defs) {
return s
}
t, n := mask(s, o, put, asJSON(key, ""))
so := o
so.args = under(path, args) || key == "arguments"
t, n := mask(s, so, put, asJSON(key, ""))
total += n
return t
})
+8 -6
View File
@@ -84,7 +84,7 @@ func modelSpans(s string, o Options) []span {
if kind == "PERSON" {
a, b = zhTrim(s, a, b)
}
if a < b && utf8.ValidString(s[a:b]) && modelTakes(kind, s[a:b]) && modelFits(s, a, b, kind) && !(kind == "PERSON" && zhWordNotName(s, a, b)) {
if a < b && utf8.ValidString(s[a:b]) && modelTakes(kind, s[a:b]) && modelFits(s, a, b, kind, o.args) && !(kind == "PERSON" && zhWordNotName(s, a, b)) {
out = append(out, span{a, b, kind, ByModel, f.Score, false})
}
}
@@ -307,7 +307,7 @@ func withModel(o Options, texts []string) Options {
// A name's words each start with a capital, but for the particles names
// have (van, de, bin): "local LLM", "User yetone" and claudeKeychain are
// a program's or a log's words.
func modelFits(s string, a, b int, kind string) bool {
func modelFits(s string, a, b int, kind string, args bool) bool {
if a > 0 && wordByte(s[a-1]) && wordByte(s[a]) || b < len(s) && wordByte(s[b-1]) && wordByte(s[b]) {
return false
}
@@ -325,7 +325,7 @@ func modelFits(s string, a, b int, kind string) bool {
}
switch kind {
case "PERSON":
return personFits(s, a, b, v)
return personFits(s, a, b, v, args)
case "ACCOUNT":
if hexRe.MatchString(v) && strings.ContainsAny(v, "abcdef") || versionRe.MatchString(v) || !numberLike(v) {
return false
@@ -739,7 +739,7 @@ func wordByte(c byte) bool {
return c == '_' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'
}
func personFits(s string, a, b int, v string) bool {
func personFits(s string, a, b int, v string, args bool) bool {
if strings.ContainsAny(v, "0123456789/\\@<>|=_") || strings.IndexFunc(v, unicode.IsUpper) < 0 && isASCII(v) {
return false
}
@@ -762,8 +762,10 @@ func personFits(s string, a, b int, v string) bool {
return false
}
// an app's or a product's name the model took for a first name, where
// its sentence speaks of a thing (thingname.go)
if w := strings.Fields(v); len(w) == 1 && isASCII(v) && thingNamed(s, a, b) {
// its sentence speaks of a thing (thingname.go); never in a tool
// call's arguments, which name whom a tool acts for
// ({"recipient":"Rina"})
if w := strings.Fields(v); len(w) == 1 && isASCII(v) && !args && thingNamed(s, a, b) {
return false
}
for i, w := range strings.Fields(v) {
+3
View File
@@ -87,6 +87,9 @@ type Options struct {
// found are the spans Model found, by text, for one request's texts
found map[string][]Found
// args is masking a tool call's arguments (MaskJSON): the model's
// one-word name there is never taken for an app's (thingNamed)
args bool
// sent is masking for a vendor (Mask, MaskJSON): a text masked
// before on Route has the model's finds and the known values it had
// then (sentSpans)
+21 -16
View File
@@ -18,23 +18,32 @@ import (
// One word the model took for a name goes as written where what is
// around it says a thing is meant, and nothing says a person is:
// - the word before or after it says so: a person's (my colleague Mimi,
// Hi Mimi, Mimi said, 张伟先生) or a thing's (using Phosphor, switched
// to Muesli, the Phosphor app, Parakeet 这个软件);
// Hi Mimi, Mimi said, Mimi's Mac, 张伟先生) or a thing's (using
// Phosphor, switched to Muesli, the Phosphor app, Parakeet 这个软件);
// - else its sentence: a pronoun, a relation or a title, a word of
// speech or a greeting say a person, and the name is masked; an app's,
// a tool's or a system's word, a price or a comparison say a thing;
// - else a text of nothing but such words (Cicada, Mimi, Phosphor) is a
// speech or a greeting say a person, and the name is masked;
// - else an item of a list whose other items speak of apps, or a text
// of nothing but two such words or more (Cicada, Mimi, Phosphor) is a
// list of names with nothing to say whose, and goes as written.
//
// What this lets go: a first name alone, in a sentence that names an app
// and has nothing of a person in it ("Mimi uses the app daily"), and a
// text that is only first names. A name of two words or more (John
// Smith), one in a sentence with he, she, said, a greeting or a relation
// in it, and every Chinese name are masked as before.
// An app's word elsewhere in the sentence says nothing of the name: with
// "Rina uses Windows at home" and "Rina's Mac won't boot" let go, a
// person's first name went out beside a system's. Nor does a text that
// is the word alone ("Rina", a tool's {"recipient":"Rina"}), and nothing
// in a tool call's arguments goes by this (personFits).
//
// What this lets go: a first name in a list of them, or with an app's
// word right beside it. A name of two words or more (John Smith), one in
// a sentence with he, she, said, a greeting or a relation in it, and
// every Chinese name are masked as before.
// thingNamed says the one word at s[a:b] that the model took for a
// person's name names a thing there.
func thingNamed(s string, a, b int) bool {
if t := strings.TrimLeft(s[b:], "*_`\"'”)"); strings.HasPrefix(t, "'s") || strings.HasPrefix(t, "’s") {
// a possessive is a person's (Rina's Mac won't boot)
return false
}
cs, ce := clauseAround(s, a, b)
prev, prev2 := wordsBefore(s[cs:a])
next := latinAfter(s[b:ce])
@@ -50,9 +59,6 @@ func thingNamed(s string, a, b int) bool {
if hasWord(clause, personWords) || containsAny(clause, zhPersonWords) {
return false
}
if hasWord(clause, thingWords) || containsAny(clause, zhThingWords) {
return true
}
return listOfThings(s, a) || namesOnly(s)
}
@@ -228,7 +234,7 @@ func namesOnly(s string) bool {
}
n++
}
return n > 0 && n <= 20
return n >= 2 && n <= 20
}
func wordSet(ws ...string) map[string]bool {
@@ -274,7 +280,7 @@ var (
"dad", "mother", "father", "son", "daughter", "brother", "sister", "boyfriend", "girlfriend", "teacher",
"client", "customer", "mr", "mrs", "ms", "dr", "dear", "hi", "hello", "hey", "thanks", "regards", "cc",
"said", "says", "told", "tells", "asked", "emailed", "texted", "birthday", "married")
// thingWords in a name's sentence say a thing is meant
// thingWords in a list's other items say its items are things
thingWords = wordSet("app", "apps", "application", "applications", "software", "tool", "tools", "utility", "utilities",
"plugin", "plugins", "extension", "extensions", "launcher", "widget", "widgets",
"macos", "ios", "ipados", "android", "mac", "iphone", "ipad", "windows", "linux", "download",
@@ -283,6 +289,5 @@ var (
"browser", "note-taking", "markdown", "rss")
// and Chinese ones, found inside the text (it has no spaces)
zhPersonWords = []string{"他", "她", "同事", "朋友", "老板", "先生", "女士", "老师", "说", "告诉"}
zhThingWords = []string{"应用", "软件", "工具", "插件", "客户端", "这款", "一款", "下载", "安装", "订阅", "功能", "版本", "替代", "对比", "比较", "好用"}
zhThingAfter = []string{"这个软件", "这个应用", "这个工具", "这款", "应用", "软件", "客户端", "插件"}
)
+39 -4
View File
@@ -17,14 +17,12 @@ func TestAppNamesNotPersons(t *testing.T) {
}
for _, s := range []string{
"Cicada, Mimi, Phosphor, Parakeet, Muesli",
"Muesli",
"Cicada and Mimi",
"1. **Cicada** – a minimal note-taking app with Markdown.\n2. **Mimi** – a voice memo app with AI summaries.\n3. **Phosphor** – an RSS reader.\n4. **Parakeet** – a podcast player for macOS.\n5. **Muesli** – a meal planner.",
"Which is better for notes on my Mac, Cicada or Mimi?",
"I switched to Muesli last week; Parakeet crashes too often.",
"I'm using Phosphor now, and Cicada vs Mimi is still open.",
"Apps like Muesli are hard to find.",
"Parakeet 这个软件很好用,Cicada 和 Mimi 呢?",
"Parakeet 这个软件很好用。",
} {
out, _ := Mask(s, Options{Personal: true, Model: f.find})
if out != s {
@@ -51,7 +49,7 @@ func TestPersonBesideAppStillMasked(t *testing.T) {
{"张伟说 Parakeet 这个软件很好用,让我也装一个。", []string{"张伟"}, []string{"Parakeet"}},
{"Hi Mimi, thanks for the notes from Tuesday's call. Can you send them to Laura as well?", []string{"Mimi", "Laura"}, nil},
{"Mimi will review the draft tomorrow and send it to Daniel.", []string{"Mimi", "Daniel"}, nil},
{"Mimi", nil, nil}, // alone it says nothing whose: let go, by design
{"Mimi", []string{"Mimi"}, nil}, // alone it says nothing whose, and may be anyone's
} {
out, _ := Mask(c.s, Options{Personal: true, Model: f.find})
for _, v := range c.mask {
@@ -113,3 +111,40 @@ func TestManyNamesRestoreEachToItself(t *testing.T) {
t.Fatalf("restored\n got %q\nwant %q", got, want.String())
}
}
// A first name the model took for a person's goes out only where a
// thing's word is right beside it, or in a list of apps: not alone, not
// with an app's or a system's word elsewhere in its sentence, not as a
// possessive, and never in a tool call's arguments, which name whom a
// tool acts for.
func TestFirstNameNearAThingMasked(t *testing.T) {
f := &fakeModel{values: map[string]string{"Rina": "private_person"}}
o := Options{Personal: true, Model: f.find}
for _, s := range []string{
"Rina",
"Rina's Mac won't boot",
"Rina’s iPhone is on iOS 26",
"Rina uses Windows at home",
"Send the license to Rina.",
} {
if out, _ := Mask(s, o); strings.Contains(out, "Rina") {
t.Errorf("went as written: %q", out)
}
}
for name, body := range map[string]string{
"user text": `{"messages":[{"role":"user","content":"Rina"}]}`,
"tool_use": `{"messages":[{"role":"assistant","content":[{"type":"tool_use","id":"toolu_1","name":"send","input":{"recipient":"Rina"}}]}]}`,
"tool_use, an app's word beside": `{"messages":[{"role":"assistant","content":[{"type":"tool_use","id":"toolu_1","name":"send","input":{"note":"install Rina"}}]}]}`,
"function_call": `{"input":[{"type":"function_call","call_id":"c1","name":"send","arguments":"{\"recipient\":\"Rina\",\"note\":\"using Rina\"}"}]}`,
} {
if out, _ := MaskJSON([]byte(body), o); strings.Contains(string(out), "Rina") {
t.Errorf("%s: went as written: %s", name, out)
}
}
// an app's word right beside it still says a thing
for _, s := range []string{"I'm using Rina now.", "the Rina app crashed"} {
if out, _ := Mask(s, o); out != s {
t.Errorf("an app's name masked: %q", out)
}
}
}