bugfix: reduce false positives for stripe tokens by using word boundaries in regex (#1278)

This commit is contained in:
Norman Soetbeer authored and GitHub committed 2023-10-15 21:41:38 -05:00
1 parent 6d0d8b5068
commit bd9a25a379
2 files changed
+4 -5

No files matched your search

+3 -4
View File
@@ -1,8 +1,6 @@
package rules package rules
import ( import (
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -12,7 +10,7 @@ func StripeAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Stripe Access Token", Description: "Stripe Access Token",
RuleID: "stripe-access-token", RuleID: "stripe-access-token",
Regex: regexp.MustCompile(`(?i)(sk|pk)_(test|live)_[0-9a-z]{10,32}`), Regex: generateUniqueTokenRegex(`(sk|pk)_(test|live)_[0-9a-z]{10,32}`, true),
Keywords: []string{ Keywords: []string{
"sk_test", "sk_test",
"pk_test", "pk_test",
@@ -23,5 +21,6 @@ func StripeAccessToken() *config.Rule {
// validate // validate
tps := []string{"stripeToken := \"sk_test_" + secrets.NewSecret(alphaNumeric("30")) + "\""} tps := []string{"stripeToken := \"sk_test_" + secrets.NewSecret(alphaNumeric("30")) + "\""}
return validate(r, tps, nil) fps := []string{"nonMatchingToken := \"task_test_" + secrets.NewSecret(alphaNumeric("30")) + "\""}
return validate(r, tps, fps)
} }
+1 -1
View File
@@ -2777,7 +2777,7 @@ keywords = [
[[rules]] [[rules]]
id = "stripe-access-token" id = "stripe-access-token"
description = "Stripe Access Token" description = "Stripe Access Token"
regex = '''(?i)(sk|pk)_(test|live)_[0-9a-z]{10,32}''' regex = '''(?i)\b((sk|pk)_(test|live)_[0-9a-z]{10,32})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
keywords = [ keywords = [
"sk_test","pk_test","sk_live","pk_live", "sk_test","pk_test","sk_live","pk_live",
] ]