4
0

config.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package base
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. "github.com/zricethezav/gitleaks/v8/regexp"
  7. )
  8. func CreateGlobalConfig() config.Config {
  9. return config.Config{
  10. Title: "gitleaks config",
  11. Allowlist: config.Allowlist{
  12. Description: "global allow lists",
  13. Regexes: []*regexp.Regexp{
  14. // ----------- General placeholders -----------
  15. regexp.MustCompile(`(?i)^true|false|null$`),
  16. // Awkward workaround to detect repeated characters.
  17. func() *regexp.Regexp {
  18. var (
  19. letters = "abcdefghijklmnopqrstuvwxyz*."
  20. patterns []string
  21. )
  22. for _, char := range letters {
  23. if char == '*' || char == '.' {
  24. patterns = append(patterns, fmt.Sprintf("\\%c+", char))
  25. } else {
  26. patterns = append(patterns, fmt.Sprintf("%c+", char))
  27. }
  28. }
  29. return regexp.MustCompile("^(?i:" + strings.Join(patterns, "|") + ")$")
  30. }(),
  31. // ----------- Environment Variables -----------
  32. regexp.MustCompile(`^\$(\d+|{\d+})$`),
  33. regexp.MustCompile(`^\$([A-Z_]+|[a-z_]+)$`),
  34. regexp.MustCompile(`^\${([A-Z_]+|[a-z_]+)}$`),
  35. // ----------- Interpolated Variables -----------
  36. // Ansible (https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html)
  37. regexp.MustCompile(`^\{\{[ \t]*[\w ().|]+[ \t]*}}$`),
  38. // GitHub Actions
  39. // https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables
  40. // https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions
  41. regexp.MustCompile(`^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$`),
  42. // NuGet (https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables)
  43. regexp.MustCompile(`^%([A-Z_]+|[a-z_]+)%$`),
  44. // String formatting.
  45. regexp.MustCompile(`^%[+\-# 0]?[bcdeEfFgGoOpqstTUvxX]$`), // Golang (https://pkg.go.dev/fmt)
  46. regexp.MustCompile(`^\{\d{0,2}}$`), // Python (https://docs.python.org/3/tutorial/inputoutput.html)
  47. // Urban Code Deploy (https://www.ibm.com/support/pages/replace-token-step-replaces-replacement-values-windows-variables)
  48. regexp.MustCompile(`^@([A-Z_]+|[a-z_]+)@$`),
  49. // ----------- Miscellaneous -----------
  50. },
  51. Paths: []*regexp.Regexp{
  52. regexp.MustCompile(`gitleaks\.toml`),
  53. // ----------- Documents and media -----------
  54. regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`), // Images
  55. regexp.MustCompile(`\.(eot|[ot]tf|woff2?)$`), // Fonts
  56. regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`),
  57. // ----------- Golang files -----------
  58. regexp.MustCompile(`go\.(mod|sum|work(\.sum)?)$`),
  59. regexp.MustCompile(`(^|/)vendor/modules\.txt$`),
  60. regexp.MustCompile(`(^|/)vendor/(github\.com|golang\.org/x|google\.golang\.org|gopkg\.in|istio\.io|k8s\.io|sigs\.k8s\.io)(/.*)?$`),
  61. // ----------- Java files -----------
  62. // Gradle
  63. regexp.MustCompile(`(^|/)gradlew(\.bat)?$`),
  64. regexp.MustCompile(`(^|/)gradle\.lockfile$`),
  65. regexp.MustCompile(`(^|/)mvnw(\.cmd)?$`),
  66. regexp.MustCompile(`(^|/)\.mvn/wrapper/MavenWrapperDownloader\.java$`),
  67. // ----------- JavaScript files -----------
  68. // Dependencies and lock files.
  69. regexp.MustCompile(`(^|/)node_modules(/.*)?$`),
  70. regexp.MustCompile(`(^|/)(npm-shrinkwrap\.json|package-lock\.json|pnpm-lock\.yaml|yarn\.lock)$`),
  71. regexp.MustCompile(`(^|/)bower_components(/.*)?$`),
  72. // TODO: Add more common static assets, such as swagger-ui.
  73. regexp.MustCompile(`(^|/)(angular|bootstrap|jquery(-?ui)?|plotly|swagger-?ui)[a-zA-Z0-9.-]*(\.min)?\.js(\.map)?$`),
  74. regexp.MustCompile(`(^|/)javascript\.json$`),
  75. // ----------- Python files -----------
  76. // Dependencies and lock files.
  77. regexp.MustCompile(`(^|/)(Pipfile|poetry)\.lock$`),
  78. // Virtual environments
  79. regexp.MustCompile(`(?i)/?(v?env|virtualenv)/lib(64)?(/.*)?$`),
  80. regexp.MustCompile(`(?i)(^|/)(lib(64)?/python[23](\.\d{1,2})+|python/[23](\.\d{1,2})+/lib(64)?)(/.*)?$`),
  81. // dist-info directory (https://py-pkgs.org/04-package-structure.html#building-sdists-and-wheels)
  82. regexp.MustCompile(`(?i)(^|/)[a-z0-9_.]+-[0-9.]+\.dist-info(/.+)?$`),
  83. // ----------- Ruby files -----------
  84. regexp.MustCompile(`(^|/)vendor/(bundle|ruby)(/.*?)?$`),
  85. regexp.MustCompile(`\.gem$`), // tar archive
  86. // Misc
  87. regexp.MustCompile(`verification-metadata\.xml`),
  88. regexp.MustCompile(`Database.refactorlog`),
  89. // regexp.MustCompile(`vendor`),
  90. },
  91. StopWords: []string{
  92. "abcdefghijklmnopqrstuvwxyz", // character range
  93. // ----------- Secrets -----------
  94. // Checkmarx client secret. (https://github.com/checkmarx-ts/checkmarx-python-sdk/blob/86560f6e2a3e46d16322101294da10d5d190312d/README.md?plain=1#L56)
  95. "014df517-39d1-4453-b7b3-9930c563627c",
  96. },
  97. },
  98. }
  99. }