瀏覽代碼

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

Norman Soetbeer 2 年之前
父節點
當前提交
bd9a25a379
共有 2 個文件被更改,包括 4 次插入5 次删除
  1. 3 4
      cmd/generate/config/rules/stripe.go
  2. 1 1
      config/gitleaks.toml

+ 3 - 4
cmd/generate/config/rules/stripe.go

@@ -1,8 +1,6 @@
 package rules
 
 import (
-	"regexp"
-
 	"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
 	"github.com/zricethezav/gitleaks/v8/config"
 )
@@ -12,7 +10,7 @@ func StripeAccessToken() *config.Rule {
 	r := config.Rule{
 		Description: "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{
 			"sk_test",
 			"pk_test",
@@ -23,5 +21,6 @@ func StripeAccessToken() *config.Rule {
 
 	// validate
 	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
config/gitleaks.toml

@@ -2777,7 +2777,7 @@ keywords = [
 [[rules]]
 id = "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 = [
     "sk_test","pk_test","sk_live","pk_live",
 ]