github.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package rules
  2. import (
  3. "regexp"
  4. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. )
  7. func GitHubPat() *config.Rule {
  8. // define rule
  9. r := config.Rule{
  10. Description: "GitHub Personal Access Token",
  11. RuleID: "github-pat",
  12. Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`),
  13. Keywords: []string{"ghp_"},
  14. }
  15. // validate
  16. tps := []string{
  17. generateSampleSecret("github", "ghp_"+secrets.NewSecret(alphaNumeric("36"))),
  18. }
  19. return validate(r, tps, nil)
  20. }
  21. func GitHubFineGrainedPat() *config.Rule {
  22. // define rule
  23. r := config.Rule{
  24. Description: "GitHub Fine-Grained Personal Access Token",
  25. RuleID: "github-fine-grained-pat",
  26. Regex: regexp.MustCompile(`github_pat_[0-9a-zA-Z_]{82}`),
  27. Keywords: []string{"github_pat_"},
  28. }
  29. // validate
  30. tps := []string{
  31. generateSampleSecret("github", "github_pat_"+secrets.NewSecret(alphaNumeric("82"))),
  32. }
  33. return validate(r, tps, nil)
  34. }
  35. func GitHubOauth() *config.Rule {
  36. // define rule
  37. r := config.Rule{
  38. Description: "GitHub OAuth Access Token",
  39. RuleID: "github-oauth",
  40. Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
  41. Keywords: []string{"gho_"},
  42. }
  43. // validate
  44. tps := []string{
  45. generateSampleSecret("github", "gho_"+secrets.NewSecret(alphaNumeric("36"))),
  46. }
  47. return validate(r, tps, nil)
  48. }
  49. func GitHubApp() *config.Rule {
  50. // define rule
  51. r := config.Rule{
  52. Description: "GitHub App Token",
  53. RuleID: "github-app-token",
  54. Regex: regexp.MustCompile(`(ghu|ghs)_[0-9a-zA-Z]{36}`),
  55. Keywords: []string{"ghu_", "ghs_"},
  56. }
  57. // validate
  58. tps := []string{
  59. generateSampleSecret("github", "ghu_"+secrets.NewSecret(alphaNumeric("36"))),
  60. generateSampleSecret("github", "ghs_"+secrets.NewSecret(alphaNumeric("36"))),
  61. }
  62. return validate(r, tps, nil)
  63. }
  64. func GitHubRefresh() *config.Rule {
  65. // define rule
  66. r := config.Rule{
  67. Description: "GitHub Refresh Token",
  68. RuleID: "github-refresh-token",
  69. Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
  70. Keywords: []string{"ghr_"},
  71. }
  72. // validate
  73. tps := []string{
  74. generateSampleSecret("github", "ghr_"+secrets.NewSecret(alphaNumeric("36"))),
  75. }
  76. return validate(r, tps, nil)
  77. }