config.go 5.4 KB

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