github.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package rules
  2. import (
  3. "regexp"
  4. "github.com/zricethezav/gitleaks/v8/config"
  5. )
  6. func GitHubPat() *config.Rule {
  7. // define rule
  8. r := config.Rule{
  9. Description: "GitHub Personal Access Token",
  10. RuleID: "github-pat",
  11. Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`),
  12. Keywords: []string{"ghp_"},
  13. }
  14. // validate
  15. tps := []string{"gihubPAT := \"ghp_" + sampleAlphaNumeric36Token + "\""}
  16. return validate(r, tps)
  17. }
  18. func GitHubOauth() *config.Rule {
  19. // define rule
  20. r := config.Rule{
  21. Description: "GitHub OAuth Access Token",
  22. RuleID: "github-oauth",
  23. Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
  24. Keywords: []string{"gho_"},
  25. }
  26. // validate
  27. tps := []string{"gihubAuth := \"gho_" + sampleAlphaNumeric36Token + "\""}
  28. return validate(r, tps)
  29. }
  30. func GitHubApp() *config.Rule {
  31. // define rule
  32. r := config.Rule{
  33. Description: "GitHub App Token",
  34. RuleID: "github-app-token",
  35. Regex: regexp.MustCompile(`(ghu|ghs)_[0-9a-zA-Z]{36}`),
  36. Keywords: []string{"ghu_", "ghs_"},
  37. }
  38. // validate
  39. tps := []string{"gihubAuth := \"ghs_" + sampleAlphaNumeric36Token + "\""}
  40. return validate(r, tps)
  41. }
  42. func GitHubRefresh() *config.Rule {
  43. // define rule
  44. r := config.Rule{
  45. Description: "GitHub Refresh Token",
  46. RuleID: "github-refresh-token",
  47. Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
  48. Keywords: []string{"ghr_"},
  49. }
  50. // validate
  51. tps := []string{"gihubAuth := \"ghr_" + sampleAlphaNumeric36Token + "\""}
  52. return validate(r, tps)
  53. }