github.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. Entropy: 3,
  15. Keywords: []string{"ghp_"},
  16. }
  17. // validate
  18. tps := []string{
  19. utils.GenerateSampleSecret("github", "ghp_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  20. }
  21. fps := []string{
  22. "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  23. }
  24. return utils.Validate(r, tps, fps)
  25. }
  26. func GitHubFineGrainedPat() *config.Rule {
  27. // define rule
  28. r := config.Rule{
  29. Description: "Found a GitHub Fine-Grained Personal Access Token, risking unauthorized repository access and code manipulation.",
  30. RuleID: "github-fine-grained-pat",
  31. Regex: regexp.MustCompile(`github_pat_\w{82}`),
  32. Entropy: 3,
  33. Keywords: []string{"github_pat_"},
  34. }
  35. // validate
  36. tps := []string{
  37. utils.GenerateSampleSecret("github", "github_pat_"+secrets.NewSecret(utils.AlphaNumeric("82"))),
  38. }
  39. fps := []string{
  40. "github_pat_xxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  41. }
  42. return utils.Validate(r, tps, fps)
  43. }
  44. func GitHubOauth() *config.Rule {
  45. // define rule
  46. r := config.Rule{
  47. Description: "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks.",
  48. RuleID: "github-oauth",
  49. Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
  50. Entropy: 3,
  51. Keywords: []string{"gho_"},
  52. }
  53. // validate
  54. tps := []string{
  55. utils.GenerateSampleSecret("github", "gho_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  56. }
  57. fps := []string{
  58. "gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  59. }
  60. return utils.Validate(r, tps, fps)
  61. }
  62. func GitHubApp() *config.Rule {
  63. // define rule
  64. r := config.Rule{
  65. Description: "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security.",
  66. RuleID: "github-app-token",
  67. Regex: regexp.MustCompile(`(?:ghu|ghs)_[0-9a-zA-Z]{36}`),
  68. Entropy: 3,
  69. Keywords: []string{"ghu_", "ghs_"},
  70. }
  71. // validate
  72. tps := []string{
  73. utils.GenerateSampleSecret("github", "ghu_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  74. utils.GenerateSampleSecret("github", "ghs_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  75. }
  76. fps := []string{
  77. "ghu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  78. "ghs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  79. }
  80. return utils.Validate(r, tps, fps)
  81. }
  82. func GitHubRefresh() *config.Rule {
  83. // define rule
  84. r := config.Rule{
  85. Description: "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services.",
  86. RuleID: "github-refresh-token",
  87. Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
  88. Entropy: 3,
  89. Keywords: []string{"ghr_"},
  90. }
  91. // validate
  92. tps := []string{
  93. utils.GenerateSampleSecret("github", "ghr_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
  94. }
  95. fps := []string{
  96. "ghr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  97. }
  98. return utils.Validate(r, tps, fps)
  99. }