diff --git a/internal/redact/model.go b/internal/redact/model.go index e8b7d14f7..ae0624ce0 100644 --- a/internal/redact/model.go +++ b/internal/redact/model.go @@ -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++ { diff --git a/internal/redact/vendorchecks_test.go b/internal/redact/vendorchecks_test.go index e51c0b178..fcb5ea484 100644 --- a/internal/redact/vendorchecks_test.go +++ b/internal/redact/vendorchecks_test.go @@ -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) + } + } +}