github.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package rules
  2. import (
  3. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  4. "regexp"
  5. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  6. "github.com/zricethezav/gitleaks/v8/config"
  7. )
  8. func GitHubPat() *config.Rule {
  9. // define rule
  10. r := config.Rule{
  11. Description: "Uncovered a GitHub Personal Access Token, potentially leading to unauthorized repository access and sensitive content exposure.",
  12. RuleID: "github-pat",
  13. Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`),
  14. Keywords: []string{"ghp_"},
  15. }
  16. // validate
  17. tps := []string{
  18. utils.GenerateSampleSecret("github", "ghp_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  19. }
  20. return utils.Validate(r, tps, nil)
  21. }
  22. func GitHubFineGrainedPat() *config.Rule {
  23. // define rule
  24. r := config.Rule{
  25. Description: "Found a GitHub Fine-Grained Personal Access Token, risking unauthorized repository access and code manipulation.",
  26. RuleID: "github-fine-grained-pat",
  27. Regex: regexp.MustCompile(`github_pat_[0-9a-zA-Z_]{82}`),
  28. Keywords: []string{"github_pat_"},
  29. }
  30. // validate
  31. tps := []string{
  32. utils.GenerateSampleSecret("github", "github_pat_"+secrets.NewSecret(utils.AlphaNumeric("82"))),
  33. }
  34. return utils.Validate(r, tps, nil)
  35. }
  36. func GitHubOauth() *config.Rule {
  37. // define rule
  38. r := config.Rule{
  39. Description: "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks.",
  40. RuleID: "github-oauth",
  41. Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
  42. Keywords: []string{"gho_"},
  43. }
  44. // validate
  45. tps := []string{
  46. utils.GenerateSampleSecret("github", "gho_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  47. }
  48. return utils.Validate(r, tps, nil)
  49. }
  50. func GitHubApp() *config.Rule {
  51. // define rule
  52. r := config.Rule{
  53. Description: "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security.",
  54. RuleID: "github-app-token",
  55. Regex: regexp.MustCompile(`(?:ghu|ghs)_[0-9a-zA-Z]{36}`),
  56. Keywords: []string{"ghu_", "ghs_"},
  57. }
  58. // validate
  59. tps := []string{
  60. utils.GenerateSampleSecret("github", "ghu_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  61. utils.GenerateSampleSecret("github", "ghs_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  62. }
  63. return utils.Validate(r, tps, nil)
  64. }
  65. func GitHubRefresh() *config.Rule {
  66. // define rule
  67. r := config.Rule{
  68. Description: "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services.",
  69. RuleID: "github-refresh-token",
  70. Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
  71. Keywords: []string{"ghr_"},
  72. }
  73. // validate
  74. tps := []string{
  75. utils.GenerateSampleSecret("github", "ghr_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  76. }
  77. return utils.Validate(r, tps, nil)
  78. }