stripe.go 762 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package rules
  2. import (
  3. "regexp"
  4. "github.com/rs/zerolog/log"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. "github.com/zricethezav/gitleaks/v8/detect"
  7. )
  8. func StripeAccessToken() *config.Rule {
  9. // define rule
  10. r := config.Rule{
  11. Description: "Stripe",
  12. RuleID: "stripe-access-token",
  13. Regex: regexp.MustCompile(`(?i)(sk|pk)_(test|live)_[0-9a-z]{10,32}`),
  14. Keywords: []string{
  15. "sk_test",
  16. "pk_test",
  17. "sk_live",
  18. "pk_live",
  19. },
  20. }
  21. // validate
  22. tps := []string{"stripeToken := \"sk_test_" + sampleHex32Token + "\""}
  23. d := detect.NewDetector(config.Config{
  24. Rules: []*config.Rule{&r},
  25. })
  26. for _, tp := range tps {
  27. if len(d.DetectString(tp)) != 1 {
  28. log.Fatal().Msg("Failed to validate stripe-access-token")
  29. }
  30. }
  31. return &r
  32. }