redact: a masked word that is a date matches that date however it is written
JackyCcao on X turned birthday masking off (old dates in logs and tasks after a birthday's word were still taken) and put their own birthday in Masked words instead. A word matched only as typed, so 1990-05-12 let 1990/5/12, 1990.05.12, 1990年5月12日 and 19900512 go as written. A masked word that is all of a date (dateword.go: year-month-day with - / . 、 or a space, 年月日 or 년월일, a month's English name, or day/month/year where only one reading is a date) now matches that calendar date in each of those forms, with or without leading zeros, as eight digits, and day-first or month-first only where the day is over 12 or equals the month: for 1990-05-12 neither 05/12/1990 nor 12/05/1990, which reads as December 5th too. A word like 05/12/1990 is no date and matches only as written. Eight digits alone are not taken for a date word (as likely an id) and match as before. A date match never has a digit, or a dot and a digit, beside it, whatever Whole words only says, so 1990.5.12.1, 3.1990.5.12 and 11990-05-12 are no match; this is a change for a date word without Whole words, which matched inside such numbers before. The birthday rule is not changed. It takes a date only right after a birthday's word (生日, DOB, born...), so a log line's, a file name's or a task's own date is never one, however old. What is left (生日: 2019-03-02 in a task log about a party) has the same shape as a real date of birth, and a time beside the date doesn't tell them apart: a date of birth stored as a time (1990-05-11T16:00:00.000Z, midnight in UTC+8, as JavaScript writes it) is the commonest way one reaches an agent in JSON. TestBirthdayLogDates pins both sides; #3878 tracks fixed-shape false alarms. Tests: TestDateWordEveryForm (22 forms x 5 words x 6 contexts, each restored as written), TestDateWordDayMonthOrder, TestDateWordNotAnotherDate (another date, 1990.5.12.1, longer numbers), TestDateWordOnlyADate. Broken by hand: with the dateSpans hook in mask turned off, EveryForm, DayMonthOrder and NotAnotherDate fail; OnlyADate and BirthdayLogDates pin behaviour that was already right and pass on both. Docs: gateway-routing.md, masking.html en/zh/ja. Run on origin/main94c2aaecb, sandbox HOME and GOCACHE, then rebased onto841bcf8da(its changes are in usage and gateway/history.go, none in redact) and the vet and the four packages run again there; one056779a6(a GUI change, nothing in redact) redact, masking and settings again: - gofmt -l clean; go vet clean on macOS, GOOS=linux -tags nogui and GOOS=windows (internal/redact). - go test -count=1 ./internal/redact/... ./internal/masking/... ./internal/pii/... ./internal/settings/...: ok. The date tests also with TZ=UTC and TZ=Pacific/Kiritimati: ok. - go test -count=1 -timeout 100m ./internal/gateway (at94c2aaecb): every test ok but TestPluginToldWhereTheAgentWorks, which failed only because the run's TMPDIR was inside this git worktree (its "not in a repo" folder was in one, git "yes"). Run alone with TMPDIR outside the repo it is ok; with TMPDIR inside it fails at this head too. Not run: the full ./... suite (another session's full suite holds the machine, load ~100-140). No GUI asset changed, so no GUI run.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,183 @@
|
||||
package redact
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// A masked word that is a date matches that calendar date however it is
|
||||
// written (JackyCcao on X: with birthdays off, the user's own birthday as a
|
||||
// masked word, 1990-05-12, let 1990/5/12, 1990年5月12日 and 19900512 go as
|
||||
// written). The word is a date when it is all of one: year, month and day
|
||||
// with - / . 、 or a space between (1990-05-12, 1990.5.12); 1990年5月12日 or
|
||||
// 1990년 5월 12일; day and month before the year where only one reading is
|
||||
// a date (13/05/1990, 05/13/1990, 05/05/1990, never 05/12/1990); or a month's
|
||||
// English name (May 12, 1990; 12 May 1990). Eight digits alone are not
|
||||
// taken for a date word: they are as likely an id.
|
||||
//
|
||||
// It then matches the same date, and only it, in each of those forms, with
|
||||
// or without leading zeros, and as eight digits (19900512); day-first and
|
||||
// month-first only where the day is over 12 or equals the month, so no
|
||||
// form can read as another date. A match never has a digit beside it, nor
|
||||
// a dot and a digit (1990.5.12.1 is a version, 11990-05-12 another number),
|
||||
// whatever Whole words only says: a date is matched as a whole date.
|
||||
|
||||
// dateSep is what stands between a date's numbers.
|
||||
const dateSep = `(?:[ \t]*[-/.、/-][ \t]*|[ \t])`
|
||||
|
||||
var (
|
||||
dateYMD = regexp.MustCompile(`^(\d{4})` + dateSep + `(\d{1,2})` + dateSep + `(\d{1,2})\.?$`)
|
||||
dateCJK = regexp.MustCompile(`^(\d{4})[ \t]*[年년][ \t]*(\d{1,2})[ \t]*[月월][ \t]*(\d{1,2})[ \t]*[日号號일]?$`)
|
||||
dateDMY = regexp.MustCompile(`^(\d{1,2})` + dateSep + `(\d{1,2})` + dateSep + `(\d{4})$`)
|
||||
dateNameF = regexp.MustCompile(`^([A-Za-z]+)\.?[ \t]+(\d{1,2})(?:st|nd|rd|th)?,?[ \t]+(\d{4})$`)
|
||||
dateNameB = regexp.MustCompile(`^(\d{1,2})(?:st|nd|rd|th)?(?:[ \t]+|-)([A-Za-z]+)\.?,?(?:[ \t]+|-)(\d{4})$`)
|
||||
)
|
||||
|
||||
var monthNames = []string{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
|
||||
|
||||
// monthOf is the month a name or its first three letters say, 0 for none.
|
||||
func monthOf(name string) int {
|
||||
l := strings.ToLower(name)
|
||||
if l == "sept" {
|
||||
return 9
|
||||
}
|
||||
for i, m := range monthNames {
|
||||
ml := strings.ToLower(m)
|
||||
if l == ml || len(l) == 3 && strings.HasPrefix(ml, l) {
|
||||
return i + 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// realDate says y-m-d is a day of the calendar.
|
||||
func realDate(y, m, d int) bool {
|
||||
if y < 1000 || y > 2999 || m < 1 || m > 12 || d < 1 {
|
||||
return false
|
||||
}
|
||||
t := time.Date(y, time.Month(m), d, 0, 0, 0, 0, time.UTC)
|
||||
return t.Day() == d && int(t.Month()) == m
|
||||
}
|
||||
|
||||
// parseDateWord is the date the word w is, where it is one.
|
||||
func parseDateWord(w string) (y, m, d int, ok bool) {
|
||||
n := func(s string) int { v, _ := strconv.Atoi(s); return v }
|
||||
if g := dateYMD.FindStringSubmatch(w); g != nil {
|
||||
y, m, d = n(g[1]), n(g[2]), n(g[3])
|
||||
} else if g := dateCJK.FindStringSubmatch(w); g != nil {
|
||||
y, m, d = n(g[1]), n(g[2]), n(g[3])
|
||||
} else if g := dateDMY.FindStringSubmatch(w); g != nil {
|
||||
p, q := n(g[1]), n(g[2])
|
||||
y = n(g[3])
|
||||
switch {
|
||||
case p == q:
|
||||
m, d = p, q
|
||||
case p > 12 && q <= 12:
|
||||
d, m = p, q
|
||||
case q > 12 && p <= 12:
|
||||
m, d = p, q
|
||||
default: // 05/12/1990: May 12th or December 5th
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
} else if g := dateNameF.FindStringSubmatch(w); g != nil {
|
||||
m, d, y = monthOf(g[1]), n(g[2]), n(g[3])
|
||||
} else if g := dateNameB.FindStringSubmatch(w); g != nil {
|
||||
d, m, y = n(g[1]), monthOf(g[2]), n(g[3])
|
||||
} else {
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
return y, m, d, realDate(y, m, d)
|
||||
}
|
||||
|
||||
// dateForms is a pattern for the date y-m-d in each form a date word
|
||||
// matches, and the word itself as written.
|
||||
func dateForms(y, m, d int, w string) string {
|
||||
num := func(v int) string { // 5 or 05; 12
|
||||
if v < 10 {
|
||||
return "0?" + strconv.Itoa(v)
|
||||
}
|
||||
return strconv.Itoa(v)
|
||||
}
|
||||
Y, M, D := strconv.Itoa(y), num(m), num(d)
|
||||
full, abbr := monthNames[m-1], monthNames[m-1][:3]
|
||||
if m == 9 {
|
||||
abbr = "Sept|Sep"
|
||||
}
|
||||
name := `(?i:` + full + `|(?:` + abbr + `)\.?)`
|
||||
ord := `(?:st|nd|rd|th)?`
|
||||
forms := []string{
|
||||
Y + dateSep + M + dateSep + D,
|
||||
Y + `[ \t]*年[ \t]*` + M + `[ \t]*月[ \t]*` + D + `(?:[ \t]*[日号號])?`,
|
||||
Y + `[ \t]*년[ \t]*` + M + `[ \t]*월[ \t]*` + D + `(?:[ \t]*일)?`,
|
||||
Y + strconv.Itoa(100 + m)[1:] + strconv.Itoa(100 + d)[1:],
|
||||
name + `[ \t]+` + D + ord + `,?[ \t]+` + Y,
|
||||
D + ord + `(?:[ \t]+|-)` + name + `,?(?:[ \t]+|-)` + Y,
|
||||
}
|
||||
// day-first and month-first only where no other date reads the same
|
||||
if d > 12 || d == m {
|
||||
forms = append(forms, D+dateSep+M+dateSep+Y)
|
||||
if d != m {
|
||||
forms = append(forms, M+dateSep+D+dateSep+Y)
|
||||
}
|
||||
}
|
||||
return `(?:` + strings.Join(forms, "|") + `|` + regexp.QuoteMeta(w) + `)`
|
||||
}
|
||||
|
||||
var dateWords sync.Map // word → *regexp.Regexp, or nil for one that is no date
|
||||
|
||||
// dateWord is the pattern for the date the masked word w is, nil where it
|
||||
// is no date.
|
||||
func dateWord(w string) *regexp.Regexp {
|
||||
if re, ok := dateWords.Load(w); ok {
|
||||
return re.(*regexp.Regexp)
|
||||
}
|
||||
var re *regexp.Regexp
|
||||
if y, m, d, ok := parseDateWord(w); ok {
|
||||
re = regexp.MustCompile(dateForms(y, m, d, w))
|
||||
}
|
||||
dateWords.Store(w, re)
|
||||
return re
|
||||
}
|
||||
|
||||
// dateWhole says the date at s[a:b] is no part of a longer number: no
|
||||
// digit beside it, no dot and a digit (a version's 1990.5.12.1, 3.1990.5.12),
|
||||
// and no letter before a month's name (xMay), save in a script that puts
|
||||
// no spaces between words (生日是May 12, 1990).
|
||||
func dateWhole(s string, a, b int) bool {
|
||||
isDigit := func(c byte) bool { return c >= '0' && c <= '9' }
|
||||
if a > 0 {
|
||||
if isDigit(s[a-1]) || s[a-1] == '.' && a > 1 && isDigit(s[a-2]) {
|
||||
return false
|
||||
}
|
||||
if r, _ := utf8.DecodeLastRuneInString(s[:a]); unicode.IsLetter(rune(s[a])) && unicode.IsLetter(r) && !unicode.In(r, unicode.Han, unicode.Hiragana, unicode.Katakana, unicode.Hangul) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if b < len(s) {
|
||||
if isDigit(s[b]) || s[b] == '.' && b+1 < len(s) && isDigit(s[b+1]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// dateSpans are where s has the date the masked word w is, nil and false
|
||||
// where w is no date.
|
||||
func dateSpans(s, w string) ([]span, bool) {
|
||||
re := dateWord(w)
|
||||
if re == nil {
|
||||
return nil, false
|
||||
}
|
||||
var out []span
|
||||
for _, m := range re.FindAllStringIndex(s, -1) {
|
||||
if dateWhole(s, m[0], m[1]) {
|
||||
out = append(out, span{m[0], m[1], "TERM", ByWord})
|
||||
}
|
||||
}
|
||||
return out, true
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package redact
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// JackyCcao on X turned birthdays off and put their own birthday in
|
||||
// Masked words, and asked that a date word catch the same date written
|
||||
// with another separator or as 年月日. A date word matches that calendar
|
||||
// date in every common form, and never another date or a longer number.
|
||||
func TestDateWordEveryForm(t *testing.T) {
|
||||
forms := []string{
|
||||
"1990-05-12", "1990-5-12", "1990/05/12", "1990/5/12", "1990.05.12", "1990.5.12",
|
||||
"1990、5、12", "1990 5 12", "1990 / 05 / 12", "1990. 5. 12",
|
||||
"1990年5月12日", "1990年05月12日", "1990 年 5 月 12 日", "1990年5月12号", "1990年5月12",
|
||||
"1990년 5월 12일", "19900512",
|
||||
"May 12, 1990", "May 12th 1990", "may 12 1990", "12 May 1990", "12-May-1990",
|
||||
}
|
||||
for _, word := range []string{"1990-05-12", "1990/5/12", "1990年5月12日", "May 12, 1990", "12 May 1990"} {
|
||||
o := Options{Words: []string{word}}
|
||||
for _, f := range forms {
|
||||
for _, in := range []string{f, "生日是" + f + ",记得", "born " + f + ".", `{"dob":"` + f + `"}`, "IMG_" + f + "_1.jpg", f + "T08:00:00Z"} {
|
||||
out, n := Mask(in, o)
|
||||
if n != 1 || strings.Contains(out, f) {
|
||||
t.Errorf("word %q: %q masked %d as %q", word, in, n, out)
|
||||
continue
|
||||
}
|
||||
if back := Restore(out, false); back != in {
|
||||
t.Errorf("word %q: %q came back as %q", word, in, back)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Day-first and month-first forms only where one reading is a date: for
|
||||
// May 13th both 13/05/1990 and 05/13/1990 are; for May 12th neither
|
||||
// 05/12/1990 nor 12/05/1990 (December 5th) is, and a word written so is
|
||||
// matched only as written.
|
||||
func TestDateWordDayMonthOrder(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
word, in string
|
||||
n int
|
||||
}{
|
||||
{"1990-05-13", "13/05/1990", 1},
|
||||
{"1990-05-13", "05/13/1990", 1},
|
||||
{"1990-05-13", "13.5.1990", 1},
|
||||
{"13.05.1990", "1990年5月13日", 1},
|
||||
{"05/13/1990", "1990-05-13", 1},
|
||||
{"1990-05-05", "05/05/1990", 1},
|
||||
{"1990-05-12", "05/12/1990", 0},
|
||||
{"1990-05-12", "12/05/1990", 0},
|
||||
{"1990-05-12", "12.05.1990", 0},
|
||||
{"05/12/1990", "1990-05-12", 0}, // May 12th or December 5th: no date
|
||||
{"05/12/1990", "1990-12-05", 0},
|
||||
{"05/12/1990", "on 05/12/1990.", 1}, // still the word as written
|
||||
} {
|
||||
if _, n := Mask(c.in, Options{Words: []string{c.word}}); n != c.n {
|
||||
t.Errorf("word %q: %q masked %d, want %d", c.word, c.in, n, c.n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A date word never matches another date, a longer number, or a version
|
||||
// that starts as the date does.
|
||||
func TestDateWordNotAnotherDate(t *testing.T) {
|
||||
for _, word := range []string{"1990-05-12", "1990.5.12", "1990年5月12日"} {
|
||||
for _, in := range []string{
|
||||
"1990-05-13", "1990-12-05", "1991-05-12", "1990年5月1日", "1990年5月120日", "1990/05/1",
|
||||
"1990.5.12.1", "v1990.5.12.1", "3.1990.5.12", "11990-05-12", "1990-05-123", "199005123", "2199005120",
|
||||
"19900513", "1990512", "May 13, 1990", "Mayday 12 1990", "12/05/1990", "05/12/1990",
|
||||
} {
|
||||
if out, n := Mask(in, Options{Words: []string{word}}); n != 0 || out != in {
|
||||
t.Errorf("word %q: %q masked as %q", word, in, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
// a full stop after the date ends a sentence; it is no version
|
||||
if _, n := Mask("生日 1990.5.12.", Options{Words: []string{"1990-05-12"}}); n != 1 {
|
||||
t.Errorf("date before a full stop not masked")
|
||||
}
|
||||
}
|
||||
|
||||
// What is no date stays a word as before: eight digits (as likely an id),
|
||||
// a date that isn't one, a word with a date in it.
|
||||
func TestDateWordOnlyADate(t *testing.T) {
|
||||
for _, c := range []struct{ word, in string }{
|
||||
{"19900512", "1990-05-12"},
|
||||
{"1990-02-30", "1990/2/30"},
|
||||
{"1990-13-01", "1990/13/1"},
|
||||
{"release-1990-05-12", "1990-05-12"},
|
||||
} {
|
||||
if out, n := Mask(c.in, Options{Words: []string{c.word}}); n != 0 {
|
||||
t.Errorf("word %q: %q masked as %q", c.word, c.in, out)
|
||||
}
|
||||
}
|
||||
// and is found inside a longer one as before
|
||||
if _, n := Mask("x19900512y", Options{Words: []string{"19900512"}}); n != 1 {
|
||||
t.Errorf("eight-digit word no longer found inside a longer one")
|
||||
}
|
||||
}
|
||||
|
||||
// The birthday rule needs a birthday's word right before the date, so a
|
||||
// log's or a task's own date is not one, however old. A date of birth
|
||||
// stored as a time, as a database or JavaScript writes it, is still a
|
||||
// birthday: the time beside a date doesn't say it is a log's (#3878).
|
||||
func TestBirthdayLogDates(t *testing.T) {
|
||||
defer func(c func() time.Time) { dateClock = c }(dateClock)
|
||||
dateClock = func() time.Time { return time.Date(2026, 10, 27, 9, 0, 0, 0, time.Local) }
|
||||
for _, s := range []string{
|
||||
"2019-03-02 10:00:01 INFO birthday reminder sent to user 42",
|
||||
"[2019-03-02T10:00:01Z] 生日提醒已发送",
|
||||
"logs/2019-03-02.log: born-again job finished",
|
||||
"任务创建于 2019-03-02,生日活动筹备",
|
||||
"2019-03-02 生日",
|
||||
} {
|
||||
if out, n := Mask(s, allKinds()); n != 0 || out != s {
|
||||
t.Errorf("%q masked as %q", s, out)
|
||||
}
|
||||
}
|
||||
for _, s := range []string{
|
||||
`{"birthday":"1990-05-11T16:00:00.000Z"}`,
|
||||
"出生日期:1990-05-12 00:00:00",
|
||||
"生日:2019-03-02",
|
||||
} {
|
||||
if out, _ := Mask(s, allKinds()); !strings.Contains(out, "BIRTHDAY") {
|
||||
t.Errorf("%q not masked: %q", s, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -800,6 +800,11 @@ func mask(raw string, o Options, put func(kind, v string) string, escaped bool)
|
||||
if w = strings.TrimSpace(w); len(w) < 2 {
|
||||
continue
|
||||
}
|
||||
// a date is matched as that date, however it is written (dateword.go)
|
||||
if spans, ok := dateSpans(s, w); ok {
|
||||
found = append(found, spans...)
|
||||
continue
|
||||
}
|
||||
// next finds w at or after i; one inside a longer word, where the
|
||||
// user asked for whole words, is passed over a letter at a time, so
|
||||
// "XABC ABC" still finds the second
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<tr><th>スイッチ</th><th>見つけるもの</th></tr>
|
||||
<tr><td><span class="ui">シークレットをマスク</span></td><td>秘密鍵のブロック(<code>-----BEGIN … PRIVATE KEY-----</code>)。形で見分ける API キー:<code>sk-…</code>(OpenAI、Anthropic、OpenRouter)、<code>ghp_</code>/<code>github_pat_</code>、<code>glpat-</code>、<code>AIza…</code>、<code>xox…-</code>、<code>sk_live_</code>、<code>AKIA</code>/<code>ASIA</code>、<code>hf_</code>、<code>gsk_</code>、<code>xai-</code>、<code>npm_</code>、<code>pypi-</code>、<code>dop_v1_</code>、<code>SG.</code>、それに <code>oc_sk_…</code> のような中継サービスのキー。JWT。<code>user:password@host</code> のパスワード。<code>.env</code> や設定ファイルでシークレットの名前が付いたフィールドの値:<code>DB_PASSWORD=…</code>、<code>api_key: …</code>、<code>client_secret</code>、<code>token</code>、<code>credential</code>。それと自分の <span class="ui">マスクルール</span>。</td></tr>
|
||||
<tr><td><span class="ui">個人情報をマスク</span></td><td>メールアドレス、中国本土の携帯番号、チェックサムの合う中国の身分証番号と銀行カード番号。既定でオンのもの:米国の社会保障番号、パスポート番号(<em>passport</em>、护照、パスポートの後)、IBAN、誕生日(<em>birthday</em>、<em>DOB</em>、生日の近くにある、一年以上前の日付。今日の日付はそのまま)、MAC アドレス、シリアル番号(<em>S/N</em> の後)。エージェントがほぼ毎回送るので、自分でオンにするまでオフのもの:ホームフォルダのユーザー名、ユーザー名とコンピュータ名(<code>user@host</code>)、パブリック IP アドレス、クラウドストレージのバケット。</td></tr>
|
||||
<tr><td><span class="ui">マスクする語</span></td><td>入れた語そのままを <code>{{TERM_…}}</code> に。</td></tr>
|
||||
<tr><td><span class="ui">マスクする語</span></td><td>入れた語そのままを <code>{{TERM_…}}</code> に。日付(<em>1990-05-12</em> など)を入れると、同じ日のどの書き方もマスクされます:<em>1990/5/12</em>、<em>1990.05.12</em>、<em>1990年5月12日</em>、<em>19900512</em>、<em>May 12, 1990</em>。<em>13/05/1990</em> のような日が先の書き方は、日と月を取り違えようがないときだけです。別の日付や <em>1990.5.12.1</em> のようなバージョン番号はマスクされません。</td></tr>
|
||||
<tr><td><span class="ui">ローカルモデルで検出</span></td><td><span class="ui">検出方法</span> の中にあります。このコンピュータで動くモデルが、ルールでは見つからない自由文中の名前や住所を見つけます。<span class="ui">シークレットをマスク</span> か <span class="ui">個人情報をマスク</span> がオンのときに使え、見つけたものは同じスイッチに従います。横のメニューでモデルを選べます:AstrLink Guard(中国語と英語、39 MB のダウンロード、コードでの誤検出が少ない、Mac では Neural Engine で動く。既定)か OpenAI の Privacy Filter(1.6 GB、GPU を使える、コード中の普通の値も多く隠す)。その下の <span class="ui">信頼度のしきい値</span> は、値をマスクするのにモデルがどれだけ確かである必要があるかです。既定は Privacy Filter が 0.5、AstrLink Guard が公開元の 0.8。上げると普通の値のマスクは減りますが、本物の名前や住所もそのまま送られやすくなります。誤検出の多くはモデルのあとのルールが既に外すので、既定値は測った中で本物の値を最も逃さない値です。</td></tr>
|
||||
</table></div>
|
||||
<p>プレースホルダーは「種類 + 鍵付きハッシュの 8 文字」です。同じ値はいつも同じプレースホルダーになるので、会話は毎ターン同じに読め、ベンダーのプロンプトキャッシュも有効なままです。値はメモリにだけ置かれます。</p>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<tr><th>Switch</th><th>What it finds</th></tr>
|
||||
<tr><td><span class="ui">Mask secrets</span></td><td>Private key blocks (<code>-----BEGIN … PRIVATE KEY-----</code>). API keys by their shape: <code>sk-…</code> (OpenAI, Anthropic, OpenRouter), <code>ghp_</code>/<code>github_pat_</code>, <code>glpat-</code>, <code>AIza…</code>, <code>xox…-</code>, <code>sk_live_</code>, <code>AKIA</code>/<code>ASIA</code>, <code>hf_</code>, <code>gsk_</code>, <code>xai-</code>, <code>npm_</code>, <code>pypi-</code>, <code>dop_v1_</code>, <code>SG.</code>, and relay keys like <code>oc_sk_…</code>. JWTs. The password in <code>user:password@host</code>. The value of a field named for a secret, as <code>.env</code> files and configs have them: <code>DB_PASSWORD=…</code>, <code>api_key: …</code>, <code>client_secret</code>, <code>token</code>, <code>credential</code>. Your own <span class="ui">Masking rules</span>.</td></tr>
|
||||
<tr><td><span class="ui">Mask personal data</span></td><td>Emails, mainland China mobile numbers, Chinese ID numbers and bank card numbers whose checksum adds up. Also on by default: US Social Security numbers, passport numbers (after <em>passport</em>, 护照 or パスポート), IBANs, birthdays (next to <em>birthday</em>, <em>DOB</em> or 生日, and over a year ago, so today’s date stays), MAC addresses and serial numbers (after <em>S/N</em>). Off until you turn them on, since agents send them in nearly every request: the user name in home folders, user and computer names (<code>user@host</code>), public IP addresses and cloud storage buckets.</td></tr>
|
||||
<tr><td><span class="ui">Masked words</span></td><td>Each word you listed, exactly, as <code>{{TERM_…}}</code>.</td></tr>
|
||||
<tr><td><span class="ui">Masked words</span></td><td>Each word you listed, exactly, as <code>{{TERM_…}}</code>. A date, such as <em>1990-05-12</em>, matches that day however it is written: <em>1990/5/12</em>, <em>1990.05.12</em>, <em>1990年5月12日</em>, <em>19900512</em>, <em>May 12, 1990</em>, and <em>13/05/1990</em> style only where the day can’t be read as a month. Never another date or a version like <em>1990.5.12.1</em>.</td></tr>
|
||||
<tr><td><span class="ui">Find with a local model</span></td><td>Under <span class="ui">How it’s found</span>. A model on this computer finds what no rule can: a name or an address in free text. It needs <span class="ui">Mask secrets</span> or <span class="ui">Mask personal data</span> on, and finds under the same switches. The menu beside it picks the model: AstrLink Guard (Chinese and English, a 39 MB download, few false alarms in code, on a Mac it runs on the Neural Engine; the default) or OpenAI’s Privacy Filter (1.6 GB, uses the GPU, masks more ordinary values in code). <span class="ui">Confidence threshold</span> under it is how sure the model must be before a value is masked: Privacy Filter’s default is 0.5, AstrLink Guard’s 0.8, its publisher’s. Higher masks fewer ordinary values, and lets more real names and addresses through: the rules after the model drop most false alarms already, so the default is where we measured the fewest real values lost.</td></tr>
|
||||
</table></div>
|
||||
<p>A placeholder is the kind plus eight characters of a keyed hash. The same value gets the same placeholder every time, so the conversation reads the same turn after turn and the vendor’s prompt cache stays valid. The values are held in memory only.</p>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<tr><th>开关</th><th>能找到什么</th></tr>
|
||||
<tr><td><span class="ui">脱敏密钥</span></td><td>私钥块(<code>-----BEGIN … PRIVATE KEY-----</code>)。按格式识别的 API Key:<code>sk-…</code>(OpenAI、Anthropic、OpenRouter)、<code>ghp_</code>/<code>github_pat_</code>、<code>glpat-</code>、<code>AIza…</code>、<code>xox…-</code>、<code>sk_live_</code>、<code>AKIA</code>/<code>ASIA</code>、<code>hf_</code>、<code>gsk_</code>、<code>xai-</code>、<code>npm_</code>、<code>pypi-</code>、<code>dop_v1_</code>、<code>SG.</code>,以及 <code>oc_sk_…</code> 这类中转站的 key。JWT。<code>user:password@host</code> 里的密码。<code>.env</code> 和配置文件里以密钥命名的字段的值:<code>DB_PASSWORD=…</code>、<code>api_key: …</code>、<code>client_secret</code>、<code>token</code>、<code>credential</code>。以及你的 <span class="ui">自定义脱敏规则</span>。</td></tr>
|
||||
<tr><td><span class="ui">脱敏个人信息</span></td><td>邮箱、中国大陆手机号、校验位对得上的身份证号和银行卡号。默认也开着的:美国社会安全号、护照号(跟在 <em>passport</em>、护照或パスポート后面)、IBAN、生日(旁边有 <em>birthday</em>、<em>DOB</em> 或「生日」,且是一年以前的日期,所以今天的日期不动)、MAC 地址、序列号(跟在 <em>S/N</em> 后面)。默认关闭、需要自己打开的(Agent 几乎每个请求都会带):主目录里的用户名、用户名和主机名(<code>user@host</code>)、公网 IP 地址、云存储桶。</td></tr>
|
||||
<tr><td><span class="ui">脱敏词</span></td><td>你填的每个词,精确匹配,换成 <code>{{TERM_…}}</code>。</td></tr>
|
||||
<tr><td><span class="ui">脱敏词</span></td><td>你填的每个词,精确匹配,换成 <code>{{TERM_…}}</code>。填的是日期(比如 <em>1990-05-12</em>)时,同一天的各种写法都会遮掉:<em>1990/5/12</em>、<em>1990.05.12</em>、<em>1990年5月12日</em>、<em>19900512</em>、<em>May 12, 1990</em>;<em>13/05/1990</em> 这种日在前的写法只在日和月不会混淆时才算。别的日期和 <em>1990.5.12.1</em> 这样的版本号不会被遮。</td></tr>
|
||||
<tr><td><span class="ui">用本地模型查找</span></td><td>在 <span class="ui">怎么找</span> 下面。一个在这台电脑上运行的模型能找出规则找不到的东西:自由文本里的人名、地址。需要先打开 <span class="ui">脱敏密钥</span> 或 <span class="ui">脱敏个人信息</span>,找到的内容按同样的开关处理。旁边的菜单选择模型:AstrLink Guard(中英文,下载 39 MB,代码里很少误判,在 Mac 上用神经网络引擎运行;默认)或 OpenAI 的 Privacy Filter(1.6 GB,可用 GPU,代码里会遮盖更多普通值)。下面的 <span class="ui">置信度阈值</span> 是模型要多确定才遮盖一个值:Privacy Filter 默认 0.5,AstrLink Guard 默认 0.8(发布者的值)。调高会少遮一些普通值,也会让更多真实的人名、地址原样发出去;模型之后的规则已经去掉了大部分误判,所以默认值是我们测下来漏掉真实信息最少的那一档。</td></tr>
|
||||
</table></div>
|
||||
<p>占位符是「类型 + 8 位带密钥的哈希」。同一个值每次得到同一个占位符,所以对话每一轮读起来都一样,厂商的提示词缓存也不会失效。原值只保存在内存里。</p>
|
||||
|
||||
Reference in New Issue
Block a user