redact: a Unix time the local model takes for a phone is not masked (#3577)
id.null (v0.1.1483) saw a tool result's "timestamp": 1792903687 go as
"timestamp": {{PHONE_c2ukh7gk}}. The PHONE rule needs eleven digits, so
the local model found it; v0.1.1457's check leaves a bare number alone
unless a cue is before it, but cues match inside words, and a log's
"tool_call" (or "telemetry") is "call" (or "tel").
A ten-digit time, or a thirteen-digit one in milliseconds, starting with
1 and nothing else, is now never a phone, cued or not: a North American
area code starts with 2 to 9, and a Chinese mobile is eleven digits.
The loose cues themselves are #3585.
Run: go test ./internal/redact ok; go vet darwin, linux, windows; gofmt
clean. Broken by hand: without the epochNumber check
TestModelPhoneKeepsUnixTime is red with the reporter's line masked.
Not tried: the real model on the reporter's whole tool result (their
screenshot only has the one line); the full Go suite.
This commit is contained in:
@@ -208,7 +208,8 @@ func withModel(o Options, texts []string) Options {
|
||||
// assistant's or a model's own (Claude, Codex, Haiku 4.5);
|
||||
// - an account that is a commit's hash, a version, or a number with
|
||||
// nothing before it to say it is an account's; a phone number that is
|
||||
// digits only with nothing to say it is one, and no 0 or + to start;
|
||||
// digits only with nothing to say it is one, and no 0 or + to start,
|
||||
// or a Unix time whatever is before it;
|
||||
// - a secret that is a pattern's words, a|b|c, holds a UUID (a session's
|
||||
// file) or is a piece of JSON;
|
||||
// - an account or a phone number that is a size (1624x1487), drawing
|
||||
@@ -232,7 +233,7 @@ func modelFits(s string, a, b int, kind string) bool {
|
||||
}
|
||||
return strings.Trim(v, digits) != "" || cued(s, a, accountCues)
|
||||
case "PHONE":
|
||||
if !numberLike(v) || countDigits(v) < 7 {
|
||||
if !numberLike(v) || countDigits(v) < 7 || epochNumber(v) {
|
||||
return false
|
||||
}
|
||||
return strings.Trim(v, digits) != "" || v[0] == '0' || cued(s, a, phoneCues)
|
||||
@@ -320,6 +321,19 @@ func numberLike(v string) bool {
|
||||
return letters <= 4 && countDigits(v)*2 > len(v)
|
||||
}
|
||||
|
||||
// epochNumber says v is a Unix time, as a log or a tool's JSON has one:
|
||||
// ten digits, or thirteen in milliseconds, and nothing else, starting with
|
||||
// 1. The model took "timestamp": 1792903687 for a phone, with "tool_call"
|
||||
// before it as the cue (#3577). No phone is written so: a North American
|
||||
// number's area code starts with 2 to 9, and a Chinese mobile has eleven
|
||||
// digits (the PHONE rule's).
|
||||
func epochNumber(v string) bool {
|
||||
if len(v) != 10 && len(v) != 13 || v[0] != '1' {
|
||||
return false
|
||||
}
|
||||
return strings.Trim(v, digits) == ""
|
||||
}
|
||||
|
||||
func countDigits(v string) int {
|
||||
n := 0
|
||||
for i := 0; i < len(v); i++ {
|
||||
|
||||
@@ -75,3 +75,27 @@ func TestModelTakesNoSnakeWord(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The model took a tool result's Unix time for a phone, "tool_call" before
|
||||
// it was the cue, and the log went as "timestamp": {{PHONE_c2ukh7gk}}
|
||||
// (#3577, the reporter's line). A time in seconds or milliseconds is
|
||||
// kept, cued or not; a phone beside it is still masked.
|
||||
func TestModelPhoneKeepsUnixTime(t *testing.T) {
|
||||
f := &fakeModel{values: map[string]string{"1792903687": "private_phone", "1792903687123": "private_phone", "+1 415 555 0132": "private_phone"}}
|
||||
body := `{"messages":[{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_1","content":` +
|
||||
`"{\"event\": \"tool_call\", \"timestamp\": 1792903687, \"ms\": 1792903687123, \"at\": \"2026-10-25T04:48:03.755Z\", \"desk\": \"+1 415 555 0132\"}"}]}]}`
|
||||
out, n := MaskJSON([]byte(body), Options{Personal: true, Model: f.find})
|
||||
for _, keep := range []string{`\"timestamp\": 1792903687,`, `\"ms\": 1792903687123,`} {
|
||||
if !strings.Contains(string(out), keep) {
|
||||
t.Errorf("time masked: %s", out)
|
||||
}
|
||||
}
|
||||
if n != 1 || strings.Contains(string(out), "415 555 0132") {
|
||||
t.Fatalf("%d masked: %s", n, out)
|
||||
}
|
||||
for _, v := range []string{"13800138000", "2125551234", "1792903687x", "179290368", "+11792903687"} {
|
||||
if epochNumber(v) {
|
||||
t.Errorf("%q taken for a time", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user