config.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package base
  2. import (
  3. "fmt"
  4. "github.com/zricethezav/gitleaks/v8/config"
  5. "regexp"
  6. "strings"
  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. },
  50. Paths: []*regexp.Regexp{
  51. regexp.MustCompile(`gitleaks\.toml`),
  52. // ----------- Documents and media -----------
  53. regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`), // Images
  54. regexp.MustCompile(`\.(eot|[ot]tf|woff2?)$`), // Fonts
  55. regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`),
  56. // ----------- Golang files -----------
  57. regexp.MustCompile(`go\.(mod|sum|work(\.sum)?)$`),
  58. regexp.MustCompile(`(^|/)vendor/modules\.txt$`),
  59. regexp.MustCompile(`(^|/)vendor/(github\.com|golang\.org/x|google\.golang\.org|gopkg\.in|istio\.io|k8s\.io|sigs\.k8s\.io)/.*$`),
  60. // ----------- Java files -----------
  61. // Gradle
  62. regexp.MustCompile(`(^|/)gradlew(\.bat)?$`),
  63. regexp.MustCompile(`(^|/)gradle\.lockfile$`),
  64. regexp.MustCompile(`(^|/)mvnw(\.cmd)?$`),
  65. regexp.MustCompile(`(^|/)\.mvn/wrapper/MavenWrapperDownloader\.java$`),
  66. // ----------- Node.js files -----------
  67. // Dependencies and lock files.
  68. regexp.MustCompile(`(^|/)node_modules/.*?$`),
  69. regexp.MustCompile(`(^|/)package-lock\.json$`),
  70. regexp.MustCompile(`(^|/)yarn\.lock$`),
  71. regexp.MustCompile(`(^|/)pnpm-lock\.yaml$`),
  72. regexp.MustCompile(`(^|/)npm-shrinkwrap\.json$`),
  73. regexp.MustCompile(`(^|/)bower_components/.*?$`),
  74. // ----------- Python files -----------
  75. // Dependencies and lock files.
  76. regexp.MustCompile(`(^|/)Pipfile\.lock$`),
  77. regexp.MustCompile(`(^|/)poetry\.lock$`),
  78. // Virtual environments
  79. // env/lib/python3.7/site-packages/urllib3/util/url.py
  80. regexp.MustCompile(`(?i)/?(v?env|virtualenv)/lib/.+$`),
  81. // /python/3.7.4/Lib/site-packages/dask/bytes/tests/test_bytes_utils.py
  82. // python/3.7.4/Lib/site-packages/fsspec/utils.py
  83. // python/2.7.16.32/Lib/bsddb/test/test_dbenv.py
  84. regexp.MustCompile(`(?i)/?python/[23](\.\d{1,2})+/lib/.+$`),
  85. // python/lib/python3.8/site-packages/boto3/data/ec2/2016-04-01/resources-1.json
  86. // python/lib/python3.8/site-packages/botocore/data/alexaforbusiness/2017-11-09/service-2.json
  87. regexp.MustCompile(`(?i)/?python/lib/python[23](\.\d{1,2})+/.+$`),
  88. // dist-info directory (https://py-pkgs.org/04-package-structure.html#building-sdists-and-wheels)
  89. regexp.MustCompile(`(?i)(^|/)[a-z0-9_.]+-[0-9.]+\.dist-info/.+$`),
  90. // ----------- Ruby files -----------
  91. regexp.MustCompile(`(^|/)vendor/(bundle|ruby)/.*?$`),
  92. regexp.MustCompile(`\.gem$`), // tar archive
  93. // Misc
  94. regexp.MustCompile(`verification-metadata.xml`),
  95. regexp.MustCompile(`Database.refactorlog`),
  96. //regexp.MustCompile(`vendor`),
  97. },
  98. },
  99. }
  100. }