redact: a Bilibili BV id, an av number or a YouTube link's id goes as written, whatever the local model takes it for (jimlee0824v2 on X)
jimlee0824v2 on X: in a script's list of nine Bilibili videos
(bvs = ['BV1f94c6uEr3', …]), five BV ids went to the vendor as
{{SECRET_…}}, and the script the vendor's model wrote back could no
longer fetch them. A BV id (BV1 and nine base58 characters) is a public
video's id, not a secret.
Which finder took them: no rule. With Secrets and Personal on and every
kind on, the rules alone mask none of them (the "by the rules" checks in
TestPublicVideoIDGoesAsWritten). The local model did. Asked for real
(Privacy Filter and AstrLink Guard from mote's ~/evalcache) on the
reporter's script: Privacy Filter took all nine BV ids for secrets,
AstrLink Guard eight, and AstrLink Guard took av170001 for an account
number. That the screenshot shows five of nine is the model's score
around its threshold.
The class: a public video's id that the vendor's model needs as written
to look the video up. Now modelFits takes no span of any kind that is
- a BV id (^BV1[base58]{9}$) or an av number (av and up to 12 digits),
by its own shape;
- a YouTube video's, playlist's or channel's id (10 to 64 of base64url's
characters) only where its link is right before it: watch?v=, list=,
youtu.be/, /shorts/, /embed/, /live/, /channel/ on youtube.com,
youtube-nocookie.com or youtu.be. Eleven base64url characters alone may
be a key's piece, so no shape alone exempts one.
Nothing is keyed on a field's name. The rules are unchanged: a key in a
BV id's shape after its name (api_key=BV1…) is masked still. Numeric
public ids (a Douyin video's, an X status's) were already held back by
the model checks for bare digits (numberNamedSecret, accountCues).
Tests:
- TestPublicVideoIDGoesAsWritten (new): the reporter's nine BV ids in
the tool call's arguments as the screenshot shows them, a bilibili.com
video link, av170001, YouTube watch/youtu.be/shorts/embed/playlist/
channel links; none masked by the rules, nor as secret or
account_number from the model. Still masked: a 12-character secret
(Xq7vR2mK9pLs), BV1 with 0/O/I/l (not base58), a BV id with a 13th
character, a bare 11-character run, the same run after example.com's
watch?v=, a key after a YouTube link's &key=, and api_key=BV1VMnk68E9Q
by the rules.
- TestBVScriptToolCallKeepsIDs (new): the same through MaskJSON as an
OpenAI tool call's arguments.
- TestMaskEval: cases bilibili-bvids (the reporter's script) and
video-links, with both real models' recordings added (only these two
entries; the rest of the recordings were left as committed).
- Broken by hand: the publicID check taken out of modelFits.
TestPublicVideoIDGoesAsWritten FAILs with each of the nine BV ids
masked ('"BV1VMnk68E9Q" as secret: masked in "…'{{SECRET_ekl3f6pv}}'…"'),
av170001 as {{SECRET_…}} and {{ACCOUNT_…}}, the watch?v= id and the
playlist id; TestBVScriptToolCallKeepsIDs FAILs with all nine as
{{SECRET_…}}. Restored: both pass.
Run at 3f862a27c's tree (base 1248dc16c, origin/main when pushed):
- mica-run: gofmt -l internal/redact docs (empty); go test -count=1
./internal/redact/... ./internal/masking/... ok; GOOS=linux go vet
-tags nogui ./... ok; GOOS=windows go vet ./... ok; go vet
./internal/redact/ ok.
- mote-run (the models' cache is on mote only):
MAGPIE_EVAL_CACHE=~/evalcache go test -run TestMaskEval -v
./internal/redact/ PASS, both models asked.
Not run before the push: the full suite (mica's suite lock had three
suites queued at load 53); it runs after the tag. Not tried: a running
magpie with the model on, and the reporter's whole request (only the
screenshot was posted).
docs/subsystems/gateway-routing.md says it beside the hex number rule.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -61,6 +61,19 @@ var evalCases = []evalCase{
|
||||
Text: "The license check is at `0x004EA5E0`; the key table at `0x0058C210`.",
|
||||
Keep: []evalValue{{V: "0x004EA5E0", Kind: "ACCOUNT"}, {V: "0x0058C210", Kind: "ACCOUNT"}},
|
||||
},
|
||||
{
|
||||
ID: "bilibili-bvids", From: "jimlee0824v2 on X",
|
||||
Text: "import urllib.request, json\n\nbvs = [\n 'BV1f94c6uEr3', 'BV1bqx76wEUM', 'BV1hWar6SEVP',\n 'BV1bAxg6GEX8', 'BV1VMnk68E9Q',\n 'BV1JvaW6JEMb',\n 'BV19gp16kEAc',\n 'BV1kLn36WEN6', 'BV1wvJB6aEp5'\n]\n\nfor bv in bvs:\n url = f'https://api.bilibili.com/x/web-interface/view?bvid={bv}'",
|
||||
Keep: []evalValue{{V: "BV1f94c6uEr3", Kind: "SECRET"}, {V: "BV1bqx76wEUM", Kind: "SECRET"}, {V: "BV1hWar6SEVP", Kind: "SECRET"},
|
||||
{V: "BV1bAxg6GEX8", Kind: "SECRET"}, {V: "BV1VMnk68E9Q", Kind: "SECRET"}, {V: "BV1JvaW6JEMb", Kind: "SECRET"},
|
||||
{V: "BV19gp16kEAc", Kind: "SECRET"}, {V: "BV1kLn36WEN6", Kind: "SECRET"}, {V: "BV1wvJB6aEp5", Kind: "SECRET"}},
|
||||
},
|
||||
{
|
||||
ID: "video-links", From: "jimlee0824v2 on X",
|
||||
Text: "参考这几个视频:https://www.bilibili.com/video/BV1VMnk68E9Q/ 、老的 av170001,还有 https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI 和 https://youtu.be/aqz-KE-bpKQ",
|
||||
Keep: []evalValue{{V: "BV1VMnk68E9Q", Kind: "SECRET"}, {V: "av170001", Kind: "ACCOUNT"}, {V: "dQw4w9WgXcQ", Kind: "SECRET"},
|
||||
{V: "PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI", Kind: "SECRET"}, {V: "aqz-KE-bpKQ", Kind: "SECRET"}},
|
||||
},
|
||||
{
|
||||
ID: "url-userinfo", From: "#3538",
|
||||
Text: "DATABASE_URL=postgres://app:hunter2pass@db.acme-corp.cn:5432/orders",
|
||||
|
||||
@@ -316,6 +316,9 @@ func modelFits(s string, a, b int, kind string, args bool) bool {
|
||||
return false
|
||||
}
|
||||
v := s[a:b]
|
||||
if publicID(s, a, b) {
|
||||
return false
|
||||
}
|
||||
if evmRe.MatchString(v) {
|
||||
// a wallet's or a contract's address (0x and 40 hex digits) is
|
||||
// public, on its chain for anyone to read, and the vendor's model
|
||||
@@ -387,6 +390,27 @@ func modelFits(s string, a, b int, kind string, args bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// publicID says s[a:b] is a video's id on a public site, an id anyone
|
||||
// with the link reads, which the vendor's model needs as written to look
|
||||
// the video up: a Bilibili BV id (BV1VMnk68E9Q) or av number, and a
|
||||
// YouTube video's, playlist's or channel's id in its link. The local
|
||||
// model took BV ids in a list a script was to fetch for secrets, and
|
||||
// five of nine went as {{SECRET_…}} (jimlee0824v2 on X). A BV id is known
|
||||
// by its own shape; a YouTube id has none (11 of base64url's letters, as
|
||||
// a key's piece may be), so only what is before it in its link says it
|
||||
// is one. A key that has either shape is still the rules' when its name
|
||||
// is before it (api_key=…).
|
||||
func publicID(s string, a, b int) bool {
|
||||
v := s[a:b]
|
||||
if bvidRe.MatchString(v) {
|
||||
return true
|
||||
}
|
||||
if !youtubeID.MatchString(v) {
|
||||
return false
|
||||
}
|
||||
return youtubeAt.MatchString(s[max(0, a-160):a])
|
||||
}
|
||||
|
||||
// programWords says v, which the model took for a person's or a place's,
|
||||
// is a program's words: it has an underscore (node_modules, __pycache__,
|
||||
// node_modules 太, the model running on into the sentence after it), or
|
||||
@@ -915,6 +939,14 @@ var (
|
||||
// 0x004EA5E0). A key written so is longer (0x and 64 hex digits) and
|
||||
// is masked still.
|
||||
hexLiteral = lazyre.New(`^0[xX][0-9a-fA-F]{1,16}$`)
|
||||
// a Bilibili video's id: BV1 and nine base58 characters
|
||||
// (BV1VMnk68E9Q), or its older av and a number (av170001)
|
||||
bvidRe = lazyre.New(`^BV1[1-9A-HJ-NP-Za-km-z]{9}$|^(?i:av)[1-9]\d{0,11}$`)
|
||||
// what is before a YouTube video's, playlist's or channel's id in its
|
||||
// link: watch?v=, list=, youtu.be/, /shorts/, /embed/, /live/,
|
||||
// /channel/
|
||||
youtubeAt = lazyre.New(`(?i)(?:^|[^a-z0-9.-])(?:(?:www|m|music)\.)?(?:(?:youtube|youtube-nocookie)\.com/(?:(?:watch|playlist)\?(?:[^\s"'<>&]*&)*(?:v|list)=|(?:shorts|embed|live|v|channel)/)|youtu\.be/)$`)
|
||||
youtubeID = lazyre.New(`^[A-Za-z0-9_-]{10,64}$`)
|
||||
// a time of day in words the model took for a passphrase (release
|
||||
// about 17:05Z)
|
||||
clockIn = lazyre.New(`(?:^|\s)\d{1,2}:\d{2}(?::\d{2})?Z?(?:\s|$)`)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package redact
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// bvScript is the tool call jimlee0824v2 posted on X: a script fetching
|
||||
// nine Bilibili videos by their BV ids, five of which went to the vendor
|
||||
// as {{SECRET_…}} (BV1VMnk68E9Q, BV1JvaW6JEMb, BV19gp16kEAc, BV1kLn36WEN6,
|
||||
// BV1wvJB6aEp5).
|
||||
const bvScript = `{"command":"python3 -c \"\nimport urllib.request, json\n\nbvs = [\n 'BV1f94c6uEr3', 'BV1bqx76wEUM', 'BV1hWar6SEVP',\n 'BV1bAxg6GEX8', 'BV1VMnk68E9Q',\n 'BV1JvaW6JEMb',\n 'BV19gp16kEAc',\n 'BV1kLn36WEN6', 'BV1wvJB6aEp5'\n]\n\nfor bv in bvs:\n url = f'https://api.bilibili.com/x/web-interface/view?bvid={bv}'\n req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})\n\""}`
|
||||
|
||||
var bvIDs = []string{
|
||||
"BV1f94c6uEr3", "BV1bqx76wEUM", "BV1hWar6SEVP", "BV1bAxg6GEX8", "BV1VMnk68E9Q",
|
||||
"BV1JvaW6JEMb", "BV19gp16kEAc", "BV1kLn36WEN6", "BV1wvJB6aEp5",
|
||||
}
|
||||
|
||||
// A public video's id goes as written whatever the local model takes it
|
||||
// for: a Bilibili BV id or av number by its own shape, a YouTube video's,
|
||||
// playlist's or channel's id by its link. No rule takes one either. A
|
||||
// secret of the same length, a near-BV with a letter base58 has none of,
|
||||
// and a key after a YouTube link's key= are masked still. Each case
|
||||
// starts with nothing known, so one label's mask isn't the next one's
|
||||
// known value.
|
||||
func TestPublicVideoIDGoesAsWritten(t *testing.T) {
|
||||
all := map[string]bool{}
|
||||
for _, c := range Categories {
|
||||
all[c.ID] = true
|
||||
}
|
||||
type tc struct{ text, value string }
|
||||
var keep []tc
|
||||
for _, id := range bvIDs {
|
||||
keep = append(keep, tc{bvScript, id})
|
||||
}
|
||||
keep = append(keep,
|
||||
tc{"看一下 https://www.bilibili.com/video/BV1VMnk68E9Q/?spm_id_from=333.1007 这个视频", "BV1VMnk68E9Q"},
|
||||
tc{"老视频 av170001 还在", "av170001"},
|
||||
tc{"https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=42s", "dQw4w9WgXcQ"},
|
||||
tc{"see https://youtu.be/dQw4w9WgXcQ?si=x", "dQw4w9WgXcQ"},
|
||||
tc{"https://m.youtube.com/shorts/aqz-KE-bpKQ", "aqz-KE-bpKQ"},
|
||||
tc{`<iframe src="https://www.youtube-nocookie.com/embed/M7lc1UVf-VE">`, "M7lc1UVf-VE"},
|
||||
tc{"https://www.youtube.com/playlist?list=PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI", "PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI"},
|
||||
tc{"https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI", "PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI"},
|
||||
tc{"https://www.youtube.com/channel/UC_x5XG1OV2P6uZZ5FSM9Ttw", "UC_x5XG1OV2P6uZZ5FSM9Ttw"},
|
||||
)
|
||||
for _, c := range keep {
|
||||
Forget()
|
||||
if out, n := Mask(c.text, Options{Secrets: true, Personal: true, Kinds: all}); n != 0 {
|
||||
t.Errorf("%q by the rules: masked %q", c.value, out)
|
||||
}
|
||||
for _, label := range []string{"secret", "account_number"} {
|
||||
Forget()
|
||||
f := &fakeModel{values: map[string]string{c.value: label}}
|
||||
if out, _ := Mask(c.text, Options{Secrets: true, Personal: true, Kinds: all, Model: f.find}); !strings.Contains(out, c.value) {
|
||||
t.Errorf("%q as %s: masked in %q", c.value, label, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, c := range []tc{
|
||||
// a secret as long as a BV id
|
||||
{"the vault code is Xq7vR2mK9pLs", "Xq7vR2mK9pLs"},
|
||||
// BV1 and a 0, an O, an I and an l: no base58, no BV id
|
||||
{"ref BV10OIl6aEp5 again", "BV10OIl6aEp5"},
|
||||
// as long as a BV id, BV1 and one more letter than a BV id has
|
||||
{"ref BV1wvJB6aEp5x again", "BV1wvJB6aEp5x"},
|
||||
// an 11-letter run that is no YouTube link's id
|
||||
{"the token is dQw4w9WgXcQ", "dQw4w9WgXcQ"},
|
||||
{"https://example.com/watch?v=dQw4w9WgXcQ", "dQw4w9WgXcQ"},
|
||||
{"https://www.youtube.com/watch?v=dQw4w9WgXcQ&key=Rk7vT2xLk9RbW4nZpE6s", "Rk7vT2xLk9RbW4nZpE6s"},
|
||||
} {
|
||||
Forget()
|
||||
f := &fakeModel{values: map[string]string{c.value: "secret"}}
|
||||
if out, _ := Mask(c.text, Options{Secrets: true, Personal: true, Model: f.find}); strings.Contains(out, c.value) {
|
||||
t.Errorf("%q: left in %q", c.value, out)
|
||||
}
|
||||
}
|
||||
// a key whose name is before it is the rules', in a BV id's shape too
|
||||
Forget()
|
||||
if out, _ := Mask("api_key=BV1VMnk68E9Q", Options{Secrets: true}); strings.Contains(out, "BV1VMnk68E9Q") {
|
||||
t.Errorf("named key left in %q", out)
|
||||
}
|
||||
}
|
||||
|
||||
// The reporter's tool call, as MaskJSON sends it: every BV id goes as
|
||||
// written with the model taking each for a secret.
|
||||
func TestBVScriptToolCallKeepsIDs(t *testing.T) {
|
||||
Forget()
|
||||
values := map[string]string{}
|
||||
for _, id := range bvIDs {
|
||||
values[id] = "secret"
|
||||
}
|
||||
f := &fakeModel{values: values}
|
||||
args, _ := json.Marshal(bvScript)
|
||||
body := `{"messages":[{"role":"assistant","content":null,"tool_calls":[{"id":"call_1","type":"function","function":{"name":"bash","arguments":` + string(args) + `}}]}]}`
|
||||
out, _ := MaskJSON([]byte(body), Options{Secrets: true, Personal: true, Model: f.find})
|
||||
for _, id := range bvIDs {
|
||||
if !strings.Contains(string(out), id) {
|
||||
t.Errorf("%s masked: %s", id, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
+94
@@ -133,6 +133,71 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"bilibili-bvids": {
|
||||
"text": "9676d7499353f242",
|
||||
"found": [
|
||||
{
|
||||
"Start": 42,
|
||||
"End": 54,
|
||||
"Label": "account_number",
|
||||
"score": 0.5316396951675415
|
||||
},
|
||||
{
|
||||
"Start": 58,
|
||||
"End": 70,
|
||||
"Label": "secret",
|
||||
"score": 0.9852209687232971
|
||||
},
|
||||
{
|
||||
"Start": 74,
|
||||
"End": 86,
|
||||
"Label": "secret",
|
||||
"score": 0.991255521774292
|
||||
},
|
||||
{
|
||||
"Start": 94,
|
||||
"End": 106,
|
||||
"Label": "secret",
|
||||
"score": 0.9925815463066101
|
||||
},
|
||||
{
|
||||
"Start": 110,
|
||||
"End": 122,
|
||||
"Label": "secret",
|
||||
"score": 0.9928242564201355
|
||||
},
|
||||
{
|
||||
"Start": 130,
|
||||
"End": 142,
|
||||
"Label": "secret",
|
||||
"score": 0.9921749234199524
|
||||
},
|
||||
{
|
||||
"Start": 150,
|
||||
"End": 162,
|
||||
"Label": "secret",
|
||||
"score": 0.9932796359062195
|
||||
},
|
||||
{
|
||||
"Start": 170,
|
||||
"End": 182,
|
||||
"Label": "secret",
|
||||
"score": 0.9932944178581238
|
||||
},
|
||||
{
|
||||
"Start": 186,
|
||||
"End": 198,
|
||||
"Label": "secret",
|
||||
"score": 0.9930053353309631
|
||||
},
|
||||
{
|
||||
"Start": 230,
|
||||
"End": 282,
|
||||
"Label": "private_url",
|
||||
"score": 0.5869995951652527
|
||||
}
|
||||
]
|
||||
},
|
||||
"card": {
|
||||
"text": "7387f43ca5ce5824",
|
||||
"found": [
|
||||
@@ -760,6 +825,35 @@
|
||||
"text": "007eeda2f5ba95d3",
|
||||
"found": []
|
||||
},
|
||||
"video-links": {
|
||||
"text": "45a5bdcb03ac26ca",
|
||||
"found": [
|
||||
{
|
||||
"Start": 24,
|
||||
"End": 68,
|
||||
"Label": "private_url",
|
||||
"score": 0.9962197542190552
|
||||
},
|
||||
{
|
||||
"Start": 79,
|
||||
"End": 87,
|
||||
"Label": "account_number",
|
||||
"score": 0.9276061654090881
|
||||
},
|
||||
{
|
||||
"Start": 97,
|
||||
"End": 180,
|
||||
"Label": "private_url",
|
||||
"score": 0.9961463212966919
|
||||
},
|
||||
{
|
||||
"Start": 185,
|
||||
"End": 213,
|
||||
"Label": "private_url",
|
||||
"score": 0.9962778687477112
|
||||
}
|
||||
]
|
||||
},
|
||||
"zh-contact": {
|
||||
"text": "5d654b2bbdd23aa1",
|
||||
"found": [
|
||||
|
||||
+70
@@ -195,6 +195,65 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"bilibili-bvids": {
|
||||
"text": "9676d7499353f242",
|
||||
"found": [
|
||||
{
|
||||
"Start": 42,
|
||||
"End": 54,
|
||||
"Label": "account_number",
|
||||
"score": 0.9999904036521912
|
||||
},
|
||||
{
|
||||
"Start": 58,
|
||||
"End": 70,
|
||||
"Label": "account_number",
|
||||
"score": 0.9999867081642151
|
||||
},
|
||||
{
|
||||
"Start": 74,
|
||||
"End": 86,
|
||||
"Label": "account_number",
|
||||
"score": 0.916449785232544
|
||||
},
|
||||
{
|
||||
"Start": 94,
|
||||
"End": 106,
|
||||
"Label": "account_number",
|
||||
"score": 0.9981630444526672
|
||||
},
|
||||
{
|
||||
"Start": 110,
|
||||
"End": 122,
|
||||
"Label": "account_number",
|
||||
"score": 0.9999914169311523
|
||||
},
|
||||
{
|
||||
"Start": 130,
|
||||
"End": 142,
|
||||
"Label": "account_number",
|
||||
"score": 0.9999295473098755
|
||||
},
|
||||
{
|
||||
"Start": 150,
|
||||
"End": 162,
|
||||
"Label": "account_number",
|
||||
"score": 0.9885242581367493
|
||||
},
|
||||
{
|
||||
"Start": 170,
|
||||
"End": 182,
|
||||
"Label": "account_number",
|
||||
"score": 0.999966561794281
|
||||
},
|
||||
{
|
||||
"Start": 186,
|
||||
"End": 198,
|
||||
"Label": "account_number",
|
||||
"score": 0.9600074291229248
|
||||
}
|
||||
]
|
||||
},
|
||||
"card": {
|
||||
"text": "7387f43ca5ce5824",
|
||||
"found": []
|
||||
@@ -1077,6 +1136,17 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"video-links": {
|
||||
"text": "45a5bdcb03ac26ca",
|
||||
"found": [
|
||||
{
|
||||
"Start": 21,
|
||||
"End": 72,
|
||||
"Label": "private_url",
|
||||
"score": 0.9987955689430237
|
||||
}
|
||||
]
|
||||
},
|
||||
"zh-contact": {
|
||||
"text": "5d654b2bbdd23aa1",
|
||||
"found": [
|
||||
|
||||
Reference in New Issue
Block a user