mailgun.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package rules
  2. import (
  3. "github.com/rs/zerolog/log"
  4. "github.com/zricethezav/gitleaks/v8/config"
  5. "github.com/zricethezav/gitleaks/v8/detect"
  6. )
  7. func MailGunPrivateAPIToken() *config.Rule {
  8. // define rule
  9. r := config.Rule{
  10. RuleID: "mailgun-private-api-token",
  11. Description: "Mailgun private API token",
  12. Regex: generateSemiGenericRegex([]string{"mailgun"}, `key-[a-f0-9]{32}`),
  13. SecretGroup: 1,
  14. Keywords: []string{
  15. "mailgun",
  16. },
  17. }
  18. // validate
  19. tps := []string{
  20. generateSampleSecret("mailgun", "key-"+sampleHex32Token),
  21. }
  22. d := detect.NewDetector(config.Config{
  23. Rules: []*config.Rule{&r},
  24. })
  25. for _, tp := range tps {
  26. if len(d.DetectString(tp)) != 1 {
  27. log.Fatal().Msg("Failed to validate mailgun-private-api-token")
  28. }
  29. }
  30. return &r
  31. }
  32. func MailGunPubAPIToken() *config.Rule {
  33. // define rule
  34. r := config.Rule{
  35. RuleID: "mailgun-pub-key",
  36. Description: "Mailgun public validation key",
  37. Regex: generateSemiGenericRegex([]string{"mailgun"}, `pubkey-[a-f0-9]{32}`),
  38. SecretGroup: 1,
  39. Keywords: []string{
  40. "mailgun",
  41. },
  42. }
  43. // validate
  44. tps := []string{
  45. generateSampleSecret("mailgun", "pubkey-"+sampleHex32Token),
  46. }
  47. d := detect.NewDetector(config.Config{
  48. Rules: []*config.Rule{&r},
  49. })
  50. for _, tp := range tps {
  51. if len(d.DetectString(tp)) != 1 {
  52. log.Fatal().Msg("Failed to validate mailgun-pub-key")
  53. }
  54. }
  55. return &r
  56. }
  57. func MailGunSigningKey() *config.Rule {
  58. // define rule
  59. r := config.Rule{
  60. RuleID: "mailgun-signing-key",
  61. Description: "Mailgun webhook signing key",
  62. Regex: generateSemiGenericRegex([]string{"mailgun"}, `[a-h0-9]{32}-[a-h0-9]{8}-[a-h0-9]{8}`),
  63. SecretGroup: 1,
  64. Keywords: []string{
  65. "mailgun",
  66. },
  67. }
  68. // validate
  69. tps := []string{
  70. generateSampleSecret("mailgun", sampleHex32Token+"-00001111-22223333"),
  71. }
  72. return validate(r, tps)
  73. }