Compare commits

..
3 Commits
14 changed files with 3012 additions and 47 deletions

No files matched your search

+1 -7
View File
@@ -50,7 +50,6 @@ func main() {
configRules = append(configRules, rules.FlutterwaveSecretKey())
configRules = append(configRules, rules.FlutterwaveSecretKey())
configRules = append(configRules, rules.FrameIO())
configRules = append(configRules, rules.GenericCredential())
configRules = append(configRules, rules.GoCardless())
// TODO figure out what makes sense for GCP
// configRules = append(configRules, rules.GCPServiceAccount())
@@ -101,12 +100,10 @@ func main() {
configRules = append(configRules, rules.TwitchAPIToken())
configRules = append(configRules, rules.Twitter())
configRules = append(configRules, rules.Typeform())
configRules = append(configRules, rules.GenericCredential())
config := config.Config{
Rules: configRules,
Allowlist: config.Allowlist{
StopWords: rules.DefaultStopWords,
},
}
tmpl, err := template.ParseFiles(templatePath)
if err != nil {
@@ -120,6 +117,3 @@ func main() {
tmpl.Execute(f, config)
}
// TODO introduce skiplists:
// https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/wordlist-skipfish.fuzz.txt
+1
View File
@@ -28,6 +28,7 @@ func AsanaClientSecret() *config.Rule {
Description: "Asana Client Secret",
RuleID: "asana-client-secret",
Regex: generateSemiGenericRegex([]string{"asana"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{"asana"},
}
+13 -4
View File
@@ -16,12 +16,21 @@ paths = [
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
'''(go.mod|go.sum)$'''
]
stopwords = [{{ range $i, $stopword := .Allowlist.StopWords }}
'''{{ $stopword }}''',{{ end }}
]
{{ range $i, $rule := .Rules }}[[rules]]
{{ if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}"
{{ if and $rule.SecretGroup $rule.Entropy $rule.Allowlist.StopWords }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }}
entropy = {{ $rule.Entropy}}
keywords = [
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
]
[rules.allowlist]
stopwords= [{{ range $j, $stopword := $rule.Allowlist.StopWords }}
"{{$stopword}}",{{end}}
]
{{ else if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }}
+4 -2
View File
@@ -30,7 +30,10 @@ func GenericCredential() *config.Rule {
"password",
"auth",
},
Entropy: 3.7,
Entropy: 3.5,
Allowlist: config.Allowlist{
StopWords: DefaultStopWords,
},
}
// validate
@@ -39,7 +42,6 @@ func GenericCredential() *config.Rule {
generateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
`"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
// TODO add more
}
fps := []string{
`client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.client-vpn-endpoint.id`,
+1
View File
@@ -11,6 +11,7 @@ func GoCardless() *config.Rule {
RuleID: "gocardless-api-token",
Description: "GoCardless API token",
Regex: generateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`),
SecretGroup: 1,
Keywords: []string{
"live_",
"gocardless",
+1
View File
@@ -30,6 +30,7 @@ func LinearClientSecret() *config.Rule {
RuleID: "linear-client-secret",
Regex: generateSemiGenericRegex([]string{"linear"}, hex("32")),
Keywords: []string{"linear"},
SecretGroup: 1,
}
// validate
+2
View File
@@ -11,6 +11,7 @@ func LobPubAPIToken() *config.Rule {
Description: "Lob Publishable API Key",
RuleID: "lob-pub-api-key",
Regex: generateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`),
SecretGroup: 1,
Keywords: []string{
"test_pub",
"live_pub",
@@ -35,6 +36,7 @@ func LobAPIToken() *config.Rule {
"test_",
"live_",
},
SecretGroup: 1,
}
// validate
+7 -2
View File
@@ -12,12 +12,17 @@ func PrivateKey() *config.Rule {
Description: "Private Key",
RuleID: "private-key",
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY-----[\s\S-]*KEY----`),
Keywords: []string{"-----BEGIN PRIVATE"},
Keywords: []string{"-----BEGIN"},
}
// validate
tps := []string{`-----BEGIN PRIVATE KEY-----
anything
-----END PRIVATE KEY-----`} // gitleaks:allow
-----END PRIVATE KEY-----`,
`-----BEGIN RSA PRIVATE KEY-----
abcdefghijklmnopqrstuvwxyz
-----END RSA PRIVATE KEY-----
`,
} // gitleaks:allow
return validate(r, tps, nil)
}
+1 -12
View File
@@ -28,14 +28,6 @@ const (
secretSuffix = `)(?:['|\"|\n|\r|\s|\x60]|$)`
)
var DefaultStopWords = []string{
"client",
"endpoint",
"vpn",
"_ec2_",
"aws_",
}
func generateSemiGenericRegex(identifiers []string, secretRegex string) *regexp.Regexp {
var sb strings.Builder
sb.WriteString(caseInsensitive)
@@ -73,13 +65,10 @@ func validate(r config.Rule, truePositives []string, falsePositives []string) *c
d := detect.NewDetector(config.Config{
Rules: []*config.Rule{&r},
Keywords: keywords,
Allowlist: config.Allowlist{
StopWords: DefaultStopWords,
},
})
for _, tp := range truePositives {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msgf("Failed to validate (tp) %s", r.RuleID)
log.Fatal().Msgf("Failed to validate (tp) %s %s", r.RuleID, tp)
}
}
for _, fp := range falsePositives {
+1 -1
View File
@@ -44,7 +44,7 @@ func SlackWebHook() *config.Rule {
// validate
tps := []string{
"https://hooks.slack.com/services/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", // gitleaks:allow
"https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
}
return validate(r, tps, nil)
}
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -50,8 +50,9 @@ func (a *Allowlist) RegexAllowed(s string) bool {
}
func (a *Allowlist) ContainsStopWord(s string) bool {
s = strings.ToLower(s)
for _, stopWord := range a.StopWords {
if strings.Contains(s, stopWord) {
if strings.Contains(s, strings.ToLower(stopWord)) {
return true
}
}
+1490 -18
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -22,6 +22,7 @@ func location(fragment Fragment, matchIndex []int) Location {
end := matchIndex[1]
for lineNum, pair := range fragment.newlineIndices {
_lineNum = lineNum
newLineByteIndex := pair[0]
if prevNewLine <= start && start < newLineByteIndex {
lineSet = true