From 53c81a2700a96944faf00a71a3829406aa922278 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 6 Nov 2026 10:02:57 +0800 Subject: [PATCH] =?UTF-8?q?redact:=20=E7=99=BD=E5=90=8D=E5=8D=95=20is=20re?= =?UTF-8?q?ad=20as=20a=20word,=20not=20a=20name=20(tianyk,=20#4087)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the local model on, 白名单 went out as a name placeholder 821 times in three days: the model took it for a name, and the reader's list of ordinary words (zhWords, zhNounEnds), which every Chinese-name find is checked against (zhWordNotName), had no word for it. 白名 is now in zhWords and 单 in zhNounEnds, so the model's find goes as written and never becomes a known value. Of the report's other rows: node_modules and 连续 are already left as written at this tree (probed with a fake model finding each as a name and a path). 时按 and 时隐藏, the model's finds cut across two words (超时+按住, 超时+隐藏), are still masked; this change does not cover them. Changed from the contributor's patch: its second half, a gate in knownSpans that let a known PERSON value go wherever it reads as a word, is not taken. Every PERSON finder already asks zhWordNotName, so the only values that gate let go are names masked where a role said a person was meant: with it, "联系人:白名单" masked and the next request's "白名单说明天到" went out as written. The test now checks that case and resets the known values around itself. Run (mote): go test -tags nogui ./internal/redact/... ./internal/pii/... ./internal/masking/... (ok), -shuffle=on ./internal/redact/ (ok); go vet -tags nogui ./internal/redact/...; gofmt -l (empty). Broken by hand: with the old zhname.go, TestModelMisreadsNotMasked and TestKnownWordTakenForANameGoesAsWritten fail (开启{{PERSON_…}}之后); with the patch's knownSpans gate put back, TestKnownWordTakenForANameGoes AsWritten fails ("a name masked once left as written: 白名单说明天到"). Not tried: the reporter's real AstrLink Guard model on their requests. Co-authored-by: ggbdpq --- internal/redact/modelfits_test.go | 6 ++++ internal/redact/zhname.go | 11 +++--- internal/redact/zhword_known_test.go | 54 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 internal/redact/zhword_known_test.go diff --git a/internal/redact/modelfits_test.go b/internal/redact/modelfits_test.go index 5ee960e0b..d52c06982 100644 --- a/internal/redact/modelfits_test.go +++ b/internal/redact/modelfits_test.go @@ -72,6 +72,10 @@ func TestModelMisreadsNotMasked(t *testing.T) { // the method a call is made on: gctx.GetInt64 went as a made-up key // in the reporter's redaction shot (#4444) {`rows, err := gctx.GetInt64("user_id")`, "gctx.GetInt64", "secret"}, + // a setting's word the local model took for a name, wherever it + // stood: 白名单, 821 replacements in the reporter's three days + // (tianyk, #4087) + {"开启白名单之后,把要放行的域名填进去。", "白名单", "private_person"}, } { f := &fakeModel{values: map[string]string{c.value: c.label}} if out, n := Mask(c.text, Options{Secrets: true, Personal: true, Model: f.find}); n != 0 { @@ -108,6 +112,8 @@ func TestModelFindsStillMasked(t *testing.T) { {"the token is 9f2c4e1a7b3d5c8e9f2c", "9f2c4e1a7b3d5c8e9f2c", "secret"}, {"ask McDonald, he knows", "McDonald", "private_person"}, {"write to Rina at rina.lee@kowalczyk.pl", "Rina", "private_person"}, + // a Chinese name where the words around it say one is meant + {"找王芳确认一下档期", "王芳", "private_person"}, {"ring +1 415.555.0132 after six", "+1 415.555.0132", "private_phone"}, {"we live at 3/12 Smith Street, Sydney", "3/12 Smith Street, Sydney", "private_address"}, } { diff --git a/internal/redact/zhname.go b/internal/redact/zhname.go index 067d685a1..79d0825ee 100644 --- a/internal/redact/zhname.go +++ b/internal/redact/zhname.go @@ -34,7 +34,9 @@ const zhNotGiven = "的了在是和与跟同说他她它我你您们这那个不 // candidate's first two are looked up (zhWord). 毛利 is a gross margin // (毛利低 went as a name, _kaichen on X, 10-28) and a Japanese surname // too (毛利兰): the rules leave both, and the model, which reads the -// sentence, finds the name. +// sentence, finds the name. 白名 is the first two characters of 白名单, +// a setting's word the model took for a name wherever it stood (tianyk, +// #4087). var zhWords = runes2( "张量", "张开", "张贴", "高度", "高效", "高级", "高速", "高亮", "高手", "高兴", "王国", "王者", "黄河", "黄色", "方法", "方向", "方式", "方案", "方便", "方面", "程序", "程度", "温度", "白色", @@ -54,7 +56,7 @@ var zhWords = runes2( "范例", "游戏", "游客", "商品", "商店", "商业", "左边", "左侧", "焦点", "毕竟", "尚未", "陆续", "连续", "连线", "林间", "林区", "谢谢", "顾客", "顾问", "房间", "房子", "高端", "高层", "古代", "古典", "农业", "司法", "施工", "卫生", "荣誉", "宗旨", "齐全", "凌晨", "冷却", "蒙版", - "曲线", "黄金", "白天", "白板", "金钱", "石油", "夏天", "夏季", "唐朝", "宋朝", "秦朝", "申请", + "曲线", "黄金", "白天", "白板", "白名", "金钱", "石油", "夏天", "夏季", "唐朝", "宋朝", "秦朝", "申请", "符号", "景色", "费用", "舒服", "辛苦", "纪律", "席位", "车间", "管道", "何时", "何况", "于是", "余下", "杜绝", "罗列", "程式", "叶片", "涂层", "沙发", "池子", "巩固", "迟到", "仲裁", "钟点", "钟表", "向导", "史诗", "易懂", "马路", "马虎", "汤汁", "朱红", "阳光", "任职", "董事", @@ -86,8 +88,9 @@ var zhDict = func() map[string]bool { const zhColours = "红橙黄绿蓝紫黑白灰褐棕粉赤" // zhNounEnds are what makes a word a longer one (关键 → 关键词, 边界 → -// 边界线, 毛利 → 毛利率), and no given name ends with (毛利兰 does not). -const zhNounEnds = "词字性率值码型键框栏库器类表量度点线层期区图版式页数论员价计费件名夹帧戳" +// 边界线, 白名 → 白名单, 毛利 → 毛利率), and no given name ends with +// (毛利兰 does not). +const zhNounEnds = "词单字性率值码型键框栏库器类表量度点线层期区图版式页数论员价计费件名夹帧戳" // zhWordShaped says v, a Chinese name the model or the cues took, is an // ordinary word: a colour (黄绿色, hh05928822 on X), a word that starts diff --git a/internal/redact/zhword_known_test.go b/internal/redact/zhword_known_test.go new file mode 100644 index 000000000..867f700dd --- /dev/null +++ b/internal/redact/zhword_known_test.go @@ -0,0 +1,54 @@ +package redact + +import ( + "strings" + "testing" +) + +// tianyk, #4087: 白名单, a common word, was taken for a name by the local +// model once, and from then on went as its placeholder everywhere, request +// after request (821 replacements in three days, "之前见过"): a value +// masked once is masked again wherever it stands (known.go). The reader +// now knows 白名单 for a word (zhWordNotName, asked of every find), so the +// model's find goes as written and never becomes known. A name masked +// once, where a role said a person was meant, is masked again wherever it +// stands, word-shaped or not: that is what known values are for. +func TestKnownWordTakenForANameGoesAsWritten(t *testing.T) { + // what this test makes known is let go after it, so no other test + // meets 白名单 as a known name + Forget() + t.Cleanup(Forget) + f := &fakeModel{values: map[string]string{"白名单": "private_person"}} + o := Options{Personal: true, Model: f.find} + if out, n := Mask("开启白名单之后,把要放行的域名填进去。", o); n != 0 { + t.Fatalf("not left as written to begin with: %q", out) + } + // the next request, with the model finding nothing in it + if out, n := Mask("白名单在设置里,加一行就行。", Options{Personal: true}); n != 0 { + t.Errorf("as known: %q", out) + } + if out, n := Mask("设置里的白名单要加一行。", o); n != 0 { + t.Errorf("as found again: %q", out) + } + + // masked where a role says a person is meant, it is masked again + // in the next request, with no role beside it + if out, _ := Mask("联系人:白名单,电话见附件", o); strings.Contains(out, "白名单") { + t.Fatalf("not masked after a role: %q", out) + } + if out, n := Mask("白名单说明天到", Options{Personal: true}); n == 0 { + t.Errorf("a name masked once left as written: %q", out) + } + + // a name of its own, once masked, is masked again where no word stands + // in its place: 欧阳娜娜 the reader takes for one (欧阳 a surname's + // two characters, no word begins with them) + fr := &fakeModel{values: map[string]string{"欧阳娜娜": "private_person"}} + or := Options{Personal: true, Model: fr.find} + if out, _ := Mask("客户欧阳娜娜来电话", or); strings.Contains(out, "欧阳娜娜") { + t.Fatalf("not masked to begin with: %q", out) + } + if out, n := Mask("欧阳娜娜今天到了", Options{Personal: true}); n == 0 { + t.Errorf("a known name left as written: %q", out) + } +}