Skip to content

Commit

Permalink
bugfix: reduce false positives for stripe tokens by using word bounda…
Browse files Browse the repository at this point in the history
…ries in regex (#1278)
  • Loading branch information
BattleRattle committed Oct 16, 2023
1 parent 6d0d8b5 commit bd9a25a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions cmd/generate/config/rules/stripe.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package rules

import (
"regexp"

"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
Expand All @@ -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",
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion config/gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down

0 comments on commit bd9a25a

Please sign in to comment.