pypi.go 771 B

123456789101112131415161718192021222324252627282930313233343536
  1. package rules
  2. import (
  3. "regexp"
  4. "github.com/rs/zerolog/log"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. "github.com/zricethezav/gitleaks/v8/detect"
  7. )
  8. func PyPiUploadToken() *config.Rule {
  9. // define rule
  10. r := config.Rule{
  11. Description: "PyPI upload token",
  12. RuleID: "pypi-upload-token",
  13. Regex: regexp.MustCompile(
  14. `pypi-AgEIcHlwaS5vcmc[A-Za-z0-9\-_]{50,1000}`),
  15. Keywords: []string{
  16. "pypi-AgEIcHlwaS5vcmc",
  17. },
  18. }
  19. // validate
  20. tps := []string{"pypiToken := \"pypi-AgEIcHlwaS5vcmc" + sampleHex32Token +
  21. sampleHex32Token + "\""}
  22. d := detect.NewDetector(config.Config{
  23. Rules: []*config.Rule{&r},
  24. })
  25. for _, tp := range tps {
  26. if len(d.DetectString(tp)) != 1 {
  27. log.Fatal().Msg("Failed to validate pypi-upload-token")
  28. }
  29. }
  30. return &r
  31. }