shopify.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 ShopifySharedSecret() *config.Rule {
  9. // define rule
  10. r := config.Rule{
  11. Description: "Shopify shared secret",
  12. RuleID: "shopify-shared-secret",
  13. Regex: regexp.MustCompile(`shpss_[a-fA-F0-9]{32}`),
  14. Keywords: []string{"shpss_"},
  15. }
  16. // validate
  17. tps := []string{"shopifySecret := \"shpss_" + sampleHex32Token + "\""}
  18. d := detect.NewDetector(config.Config{
  19. Rules: []*config.Rule{&r},
  20. })
  21. for _, tp := range tps {
  22. if len(d.DetectString(tp)) != 1 {
  23. log.Fatal().Msg("Failed to validate shopify-shared-secret")
  24. }
  25. }
  26. return &r
  27. }
  28. func ShopifyAccessToken() *config.Rule {
  29. // define rule
  30. r := config.Rule{
  31. Description: "Shopify access token",
  32. RuleID: "shopify-access-token",
  33. Regex: regexp.MustCompile(`shpat_[a-fA-F0-9]{32}`),
  34. Keywords: []string{"shpat_"},
  35. }
  36. // validate
  37. tps := []string{"shopifyToken := \"shpat_" + sampleHex32Token + "\""}
  38. d := detect.NewDetector(config.Config{
  39. Rules: []*config.Rule{&r},
  40. })
  41. for _, tp := range tps {
  42. if len(d.DetectString(tp)) != 1 {
  43. log.Fatal().Msg("Failed to validate shopify-access-token")
  44. }
  45. }
  46. return &r
  47. }
  48. func ShopifyCustomAccessToken() *config.Rule {
  49. // define rule
  50. r := config.Rule{
  51. Description: "Shopify custom access token",
  52. RuleID: "shopify-custom-access-token",
  53. Regex: regexp.MustCompile(`shpca_[a-fA-F0-9]{32}`),
  54. Keywords: []string{"shpca_"},
  55. }
  56. // validate
  57. tps := []string{"shopifyToken := \"shpca_" + sampleHex32Token + "\""}
  58. d := detect.NewDetector(config.Config{
  59. Rules: []*config.Rule{&r},
  60. })
  61. for _, tp := range tps {
  62. if len(d.DetectString(tp)) != 1 {
  63. log.Fatal().Msg("Failed to validate shopify-custom-access-token")
  64. }
  65. }
  66. return &r
  67. }
  68. func ShopifyPrivateAppAccessToken() *config.Rule {
  69. // define rule
  70. r := config.Rule{
  71. Description: "Shopify private app access token",
  72. RuleID: "shopify-private-app-access-token",
  73. Regex: regexp.MustCompile(`shppa_[a-fA-F0-9]{32}`),
  74. Keywords: []string{"shppa_"},
  75. }
  76. // validate
  77. tps := []string{"shopifyToken := \"shppa_" + sampleHex32Token + "\""}
  78. d := detect.NewDetector(config.Config{
  79. Rules: []*config.Rule{&r},
  80. })
  81. for _, tp := range tps {
  82. if len(d.DetectString(tp)) != 1 {
  83. log.Fatal().Msg("Failed to validate shopify-private-app-access-token")
  84. }
  85. }
  86. return &r
  87. }