diff --git a/internal/redact/model.go b/internal/redact/model.go index 749f01c19..bf9c16666 100644 --- a/internal/redact/model.go +++ b/internal/redact/model.go @@ -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 } diff --git a/internal/redact/modelfits_test.go b/internal/redact/modelfits_test.go index d2335f3e3..5ee960e0b 100644 --- a/internal/redact/modelfits_test.go +++ b/internal/redact/modelfits_test.go @@ -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"},