github.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 GitHubOauth() *config.Rule {
  22. // define rule
  23. r := config.Rule{
  24. Description: "GitHub OAuth Access Token",
  25. RuleID: "github-oauth",
  26. Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
  27. Keywords: []string{"gho_"},
  28. }
  29. // validate
  30. tps := []string{
  31. generateSampleSecret("github", "gho_"+secrets.NewSecret(alphaNumeric("36"))),
  32. }
  33. return validate(r, tps, nil)
  34. }
  35. func GitHubApp() *config.Rule {
  36. // define rule
  37. r := config.Rule{
  38. Description: "GitHub App Token",
  39. RuleID: "github-app-token",
  40. Regex: regexp.MustCompile(`(ghu|ghs)_[0-9a-zA-Z]{36}`),
  41. Keywords: []string{"ghu_", "ghs_"},
  42. }
  43. // validate
  44. tps := []string{
  45. generateSampleSecret("github", "ghu_"+secrets.NewSecret(alphaNumeric("36"))),
  46. generateSampleSecret("github", "ghs_"+secrets.NewSecret(alphaNumeric("36"))),
  47. }
  48. return validate(r, tps, nil)
  49. }
  50. func GitHubRefresh() *config.Rule {
  51. // define rule
  52. r := config.Rule{
  53. Description: "GitHub Refresh Token",
  54. RuleID: "github-refresh-token",
  55. Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
  56. Keywords: []string{"ghr_"},
  57. }
  58. // validate
  59. tps := []string{
  60. generateSampleSecret("github", "ghr_"+secrets.NewSecret(alphaNumeric("36"))),
  61. }
  62. return validate(r, tps, nil)
  63. }