Skip to content

Commit 1a1c56d

Browse files
authored
Exclusion of FalsePositive GH's usernames in PrivateKeyDetector (#4046)
* ignore false positive github username * moved false positive statements to detector for code simplicity. * removed the username false positive filtration logic from ssh_integration.go
1 parent f573da3 commit 1a1c56d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

pkg/detectors/privatekey/privatekey.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import (
1818
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
1919
)
2020

21+
var (
22+
falsePositiveGHUsernames = map[detectors.FalsePositive]struct{}{
23+
// This hack is because it's probably one of the most widely distributed github keys
24+
// and a frequent annoyance.
25+
// It is active at the time of this commit, but the developer is unresponsive.
26+
detectors.FalsePositive("aaron1234567890123"): {},
27+
}
28+
)
29+
2130
type Scanner struct {
2231
IncludeExpired bool
2332
}
@@ -109,12 +118,15 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
109118
wg.Add(1)
110119
go func() {
111120
defer wg.Done()
112-
user, err := VerifyGitHubUser(ctx, parsedKey)
121+
username, err := VerifyGitHubUser(ctx, parsedKey)
113122
if err != nil && !errors.Is(err, errPermissionDenied) {
114123
verificationErrors.Add(err)
115124
}
116-
if user != nil {
117-
extraData.Add("github_user", *user)
125+
if username != nil {
126+
isFalsePositive, _ := detectors.IsKnownFalsePositive(*username, falsePositiveGHUsernames, false)
127+
if !isFalsePositive {
128+
extraData.Add("github_user", *username)
129+
}
118130
}
119131
}()
120132

pkg/detectors/privatekey/ssh_integration.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ func VerifyGitHubUser(ctx context.Context, parsedKey any) (*string, error) {
115115

116116
if strings.Contains(output, "successfully authenticated") {
117117
username := strings.TrimSuffix(strings.Split(output, " ")[1], "!")
118-
// This hack is because it's probably one of the most widely distributed github keys
119-
// and a frequent annoyance.
120-
// It is active at the time of this commit, but the developer is unresponsive.
121-
if username == "aaron1234567890123" {
122-
return nil, nil
123-
}
124118
return &username, nil
125119
}
126120

0 commit comments

Comments
 (0)