redact: sk- and a UUID in lower case is a key again
3e96197da left an sk- value unmasked when it had no capital and no run
of 16 between hyphens, so an SK hynix article's address is not a key.
A key that is sk- and a UUID in lower case (groups of 8, 4, 4, 4 and 12
hex digits) met both and went to the vendor as written. A value that is
hex digits alone after sk- is masked again; no slug of words is.
Run on mote at this tree: go test ./internal/redact ok. TestSlugIsNoKey
with the UUID case is red on 3e96197da's rule ("0 masked"). The SK hynix
addresses stay unmasked.
Not run: the full suite.
This commit is contained in:
@@ -404,11 +404,17 @@ func inUserinfo(s string, a int) bool {
|
||||
// (cnbc.com/…/sk-hynix-third-quarter-profit.html), which went to the model
|
||||
// as a key. A key's characters are random: it has a capital, or a run of
|
||||
// 16 or more with no hyphen (DeepSeek's sk- and 32 hex digits, OpenRouter's
|
||||
// sk-or-v1- and 64).
|
||||
// sk-or-v1- and 64), or hex digits alone, as a UUID's groups (sk- and a
|
||||
// UUID in lower case) are, which no word but a few like "face" is.
|
||||
func notASlug(v string) bool {
|
||||
if strings.ContainsFunc(v, func(r rune) bool { return r >= 'A' && r <= 'Z' }) {
|
||||
return true
|
||||
}
|
||||
if !strings.ContainsFunc(strings.TrimPrefix(v, "sk-"), func(r rune) bool {
|
||||
return r != '-' && r != '_' && (r < '0' || r > '9') && (r < 'a' || r > 'f')
|
||||
}) {
|
||||
return true
|
||||
}
|
||||
for _, w := range strings.FieldsFunc(v, func(r rune) bool { return r == '-' || r == '_' }) {
|
||||
if len(w) >= 16 {
|
||||
return true
|
||||
|
||||
@@ -26,6 +26,7 @@ func TestSlugIsNoKey(t *testing.T) {
|
||||
"sk-" + strings.Repeat("0123456789abcdef", 2),
|
||||
"sk-or-v1-" + strings.Repeat("0123456789abcdef", 4), // built, as a literal one stops GitHub's push
|
||||
"sk-ant-api03-Ab3dE-fGh1_jKl2mN-oPq3rSt4",
|
||||
"sk-" + "1f0e3dad-9990-4b5c-8a1b-2c3d4e5f6a7b", // a UUID in lower case: no capital, no run of 16
|
||||
} {
|
||||
in := "url sk-hynix-third-quarter-profit key " + key
|
||||
out, n := Mask(in, o)
|
||||
|
||||
Reference in New Issue
Block a user