redact: a dotted name a call is made on is no secret to the masking model (#4444)
kewab's redaction shot: gctx.GetInt64("user_id") went out with
gctx.GetInt64 replaced by a made-up key. No rule reaches such a span;
the local model called it a SECRET, and modelFits let it through.
modelFits's SECRET case now turns away an identifier path (identPath)
that a '(' touches: the name a call is made on. ggbdpq's patch (via
gua2100) asked notCode there, the rules' check, which also skips a name
with a space before its '(' and one after a colon that a comma follows.
The model is asked about prose too, and there those are secrets: with
notCode, "tell Bob it is Pw7nK4xQ9rTe (rotated today)" and "note:
hunterTwoThree, keep it" went out as written. Only the touching '(' is
taken.
Run at this tree on mote: go test ./internal/redact ./internal/usage
-count=1: ok. gofmt -l clean.
Broken by hand: the guard gone: TestModelMisreadsNotMasked red on
gctx.GetInt64; the patch's notCode in its place: TestModelFindsStill
Masked red on the three prose secrets above.
Not tried: the real local masking model (the tests use the stand-in
model the suite's other model finds use).
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
This commit is contained in:
@@ -344,6 +344,15 @@ func modelFits(s string, a, b int, kind string) bool {
|
||||
}
|
||||
return strings.IndexFunc(v, unicode.IsLetter) >= 0
|
||||
case "SECRET":
|
||||
// a name a call is made on is no value: gctx.GetInt64 in
|
||||
// gctx.GetInt64("user_id") went as a made-up key (#4444). Only a
|
||||
// name the '(' touches is a call's: in prose a secret may stand
|
||||
// before a bracket of words ("the token is k3Xq9vB2mZ (rotated)"),
|
||||
// and the model is asked about prose too, so notCode's wider
|
||||
// reading of the rules' values isn't taken here
|
||||
if b < len(s) && s[b] == '(' && identPath.MatchString(v) {
|
||||
return false
|
||||
}
|
||||
if !wordByte(v[0]) || patternWords(v) || regexpLike(v) || idAfter(s, a) || strings.ContainsRune(v, ' ') && clockIn.MatchString(v) || uuidIn.MatchString(v) || strings.Contains(v, `": `) || strings.Contains(v, `", "`) || linkRe.MatchString(v) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -69,6 +69,9 @@ func TestModelMisreadsNotMasked(t *testing.T) {
|
||||
{"wait until CI is green", "CI", "private_person"},
|
||||
{"CodeRabbit\tpending\t0", "CodeRabbit", "private_person"},
|
||||
{"Greptile Review at https://app.greptile.com/r/1", "Greptile", "private_person"},
|
||||
// the method a call is made on: gctx.GetInt64 went as a made-up key
|
||||
// in the reporter's redaction shot (#4444)
|
||||
{`rows, err := gctx.GetInt64("user_id")`, "gctx.GetInt64", "secret"},
|
||||
} {
|
||||
f := &fakeModel{values: map[string]string{c.value: c.label}}
|
||||
if out, n := Mask(c.text, Options{Secrets: true, Personal: true, Model: f.find}); n != 0 {
|
||||
@@ -94,6 +97,14 @@ func TestModelFindsStillMasked(t *testing.T) {
|
||||
{"write to rina.k@kowalczyk.pl", "rina.k@kowalczyk.pl", "private_email"},
|
||||
// beside what the checks above leave out
|
||||
{"the stripe one is sk_test_AbCdEfGh_IjKlMn", "sk_test_AbCdEfGh_IjKlMn", "secret"},
|
||||
// a real secret of dotted parts, where no rule reaches it
|
||||
{"the vault phrase is alpha.bravo.charlie9", "alpha.bravo.charlie9", "secret"},
|
||||
// one a bracket of words follows is no call, nor one after a colon
|
||||
// a comma follows (#4444's guard); values of their own, as a value
|
||||
// found once is masked again wherever it stands
|
||||
{"tell Bob it is Pw7nK4xQ9rTe (rotated today)", "Pw7nK4xQ9rTe", "secret"},
|
||||
{"tell Bob it is delta.echo.foxtrot7 (keep it)", "delta.echo.foxtrot7", "secret"},
|
||||
{"note: hunterTwoThree, keep it", "hunterTwoThree", "secret"},
|
||||
{"the token is 9f2c4e1a7b3d5c8e9f2c", "9f2c4e1a7b3d5c8e9f2c", "secret"},
|
||||
{"ask McDonald, he knows", "McDonald", "private_person"},
|
||||
{"write to Rina at rina.lee@kowalczyk.pl", "Rina", "private_person"},
|
||||
|
||||
Reference in New Issue
Block a user