@@ -28,8 +28,8 @@ func (Scanner) CloudEndpoint() string { return "https://api.github.com" }
28
28
var (
29
29
// Oauth token
30
30
// https://developer.github.com/v3/#oauth2-token-sent-in-a-header
31
- // the middle regex `\b [a-zA-Z0-9.\/?=&]{0,40}` is to match the prefix of token match to avoid processing common known patterns
32
- keyPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"github" , "gh" , "pat" , "token" }) + `\b[a-zA-Z0-9.\/?=&]{0,40}` + `\b ([a-f0-9]{40})\b` )
31
+ // the middle regex `(?: [a-zA-Z0-9.\/?=&:- ]{0,40}) ` is to match the prefix of token match to avoid processing common known patterns
32
+ keyPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"github" , "gh" , "pat" , "token" }) + `\b(?: [a-zA-Z0-9.\/?=&:- ]{0,40}) ([a-f0-9]{40})\b` )
33
33
34
34
// TODO: Oauth2 client_id and client_secret
35
35
// https://developer.github.com/v3/#oauth2-keysecret
@@ -73,7 +73,15 @@ var ghFalsePositives = map[detectors.FalsePositive]struct{}{
73
73
}
74
74
75
75
var ghKnownNonSensitivePrefixes = []string {
76
- "avatars.githubusercontent.com" , // github avatar urls prefix
76
+ "avatars.githubusercontent.com" , // GitHub avatar URLs
77
+ "actions/" , // GitHub Actions paths
78
+ "raw.githubusercontent.com/" , // Raw file URLs from GitHub
79
+ "api.github.com/repos/" , // GitHub API repository endpoints
80
+ "gist.github.com/" , // GitHub Gist URLs
81
+ "sha256:" , // SHA256 hash prefix
82
+ "github.com/" , // General GitHub repo URLs
83
+ "pipelines.actions.githubusercontent.com/" , // GitHub Actions infrastructure
84
+ "ghcr.io/" , // GitHub Container Registry
77
85
}
78
86
79
87
// FromData will find and optionally verify GitHub secrets in a given set of bytes.
@@ -93,11 +101,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
93
101
continue
94
102
}
95
103
96
- // to avoid false positives
97
- if isKnownNonSensitiveCommonPrefix (matchPrefix ) {
98
- continue
99
- }
100
-
101
104
if detectors .StringShannonEntropy (token ) < 3.5 {
102
105
continue
103
106
}
@@ -116,6 +119,14 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
116
119
client := common .SaneHttpClient ()
117
120
118
121
isVerified , userResponse , headers , err := s .VerifyGithub (ctx , client , token )
122
+
123
+ if ! isVerified {
124
+ // to avoid false positives for unverified findings
125
+ if isKnownNonSensitiveCommonPrefix (matchPrefix ) {
126
+ continue
127
+ }
128
+ }
129
+
119
130
s1 .Verified = isVerified
120
131
s1 .SetVerificationError (err , token )
121
132
0 commit comments