mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 05:24:22 +01:00
Update base config allowlist (#1555)
* feat(config): add String fmt placeholders * feat(config): ignore font files * feat(config): ignore repeated characters
This commit is contained in:
1 parent
8fb39ba8dc
commit
9988e5224c
3 files changed
+56
-14
No files matched your search
@@ -1,8 +1,10 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateGlobalConfig() config.Config {
|
func CreateGlobalConfig() config.Config {
|
||||||
@@ -13,6 +15,27 @@ func CreateGlobalConfig() config.Config {
|
|||||||
Regexes: []*regexp.Regexp{
|
Regexes: []*regexp.Regexp{
|
||||||
// ----------- General placeholders -----------
|
// ----------- General placeholders -----------
|
||||||
regexp.MustCompile(`(?i)^true|false|null$`),
|
regexp.MustCompile(`(?i)^true|false|null$`),
|
||||||
|
// Awkward workaround to detect repeated characters.
|
||||||
|
func() *regexp.Regexp {
|
||||||
|
var (
|
||||||
|
letters = "abcdefghijklmnopqrstuvwxyz*."
|
||||||
|
patterns []string
|
||||||
|
)
|
||||||
|
for _, char := range letters {
|
||||||
|
if char == '*' || char == '.' {
|
||||||
|
patterns = append(patterns, fmt.Sprintf("\\%c+", char))
|
||||||
|
} else {
|
||||||
|
patterns = append(patterns, fmt.Sprintf("%c+", char))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return regexp.MustCompile("^(?i:" + strings.Join(patterns, "|") + ")$")
|
||||||
|
}(),
|
||||||
|
|
||||||
|
// ----------- Environment Variables -----------
|
||||||
|
regexp.MustCompile(`^\$(\d+|{\d+})$`),
|
||||||
|
regexp.MustCompile(`^\$([A-Z_]+|[a-z_]+)$`),
|
||||||
|
regexp.MustCompile(`^\${([A-Z_]+|[a-z_]+)}$`),
|
||||||
|
|
||||||
// ----------- Interpolated Variables -----------
|
// ----------- Interpolated Variables -----------
|
||||||
// Ansible (https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html)
|
// Ansible (https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html)
|
||||||
regexp.MustCompile(`^\{\{[ \t]*[\w ().|]+[ \t]*}}$`),
|
regexp.MustCompile(`^\{\{[ \t]*[\w ().|]+[ \t]*}}$`),
|
||||||
@@ -22,19 +45,18 @@ func CreateGlobalConfig() config.Config {
|
|||||||
regexp.MustCompile(`^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$`),
|
regexp.MustCompile(`^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$`),
|
||||||
// NuGet (https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables)
|
// NuGet (https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables)
|
||||||
regexp.MustCompile(`^%([A-Z_]+|[a-z_]+)%$`),
|
regexp.MustCompile(`^%([A-Z_]+|[a-z_]+)%$`),
|
||||||
|
// String formatting.
|
||||||
|
regexp.MustCompile(`^%[+\-# 0]?[bcdeEfFgGoOpqstTUvxX]$`), // Golang (https://pkg.go.dev/fmt)
|
||||||
|
regexp.MustCompile(`^\{\d{0,2}}$`), // Python (https://docs.python.org/3/tutorial/inputoutput.html)
|
||||||
// Urban Code Deploy (https://www.ibm.com/support/pages/replace-token-step-replaces-replacement-values-windows-variables)
|
// Urban Code Deploy (https://www.ibm.com/support/pages/replace-token-step-replaces-replacement-values-windows-variables)
|
||||||
regexp.MustCompile(`^@([A-Z_]+|[a-z_]+)@$`),
|
regexp.MustCompile(`^@([A-Z_]+|[a-z_]+)@$`),
|
||||||
|
|
||||||
// ----------- Environment Variables -----------
|
|
||||||
regexp.MustCompile(`^\$(\d+|{\d+})$`),
|
|
||||||
regexp.MustCompile(`^\$([A-Z_]+|[a-z_]+)$`),
|
|
||||||
regexp.MustCompile(`^\${([A-Z_]+|[a-z_]+)}$`),
|
|
||||||
},
|
},
|
||||||
Paths: []*regexp.Regexp{
|
Paths: []*regexp.Regexp{
|
||||||
regexp.MustCompile(`gitleaks\.toml`),
|
regexp.MustCompile(`gitleaks\.toml`),
|
||||||
|
|
||||||
// ----------- Documents and media -----------
|
// ----------- Documents and media -----------
|
||||||
regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`),
|
regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`), // Images
|
||||||
|
regexp.MustCompile(`\.(eot|[ot]tf|woff2?)$`), // Fonts
|
||||||
regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`),
|
regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`),
|
||||||
|
|
||||||
// ----------- Golang files -----------
|
// ----------- Golang files -----------
|
||||||
|
|||||||
@@ -14,6 +14,16 @@ func TestConfigAllowlistRegexes(t *testing.T) {
|
|||||||
`true`, `True`, `false`, `False`, `null`, `NULL`,
|
`true`, `True`, `false`, `False`, `null`, `NULL`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"general placeholders - repeated characters": {
|
||||||
|
invalid: []string{
|
||||||
|
`aaaaaaaaaaaaaaaaa`, `BBBBBBBBBBbBBBBBBBbBB`, `********************`,
|
||||||
|
},
|
||||||
|
valid: []string{`aaaaaaaaaaaaaaaaaaabaa`, `pas*************d`},
|
||||||
|
},
|
||||||
|
"environment variables": {
|
||||||
|
invalid: []string{`$2`, `$GIT_PASSWORD`, `${GIT_PASSWORD}`, `$password`},
|
||||||
|
valid: []string{`$yP@R.@=ibxI`, `$2a6WCust9aE`, `${not_complete1`},
|
||||||
|
},
|
||||||
"interpolated variables - ansible": {
|
"interpolated variables - ansible": {
|
||||||
invalid: []string{
|
invalid: []string{
|
||||||
`{{ x }}`, `{{ password }}`, `{{password}}`, `{{ data.proxy_password }}`,
|
`{{ x }}`, `{{ password }}`, `{{password}}`, `{{ data.proxy_password }}`,
|
||||||
@@ -39,14 +49,20 @@ func TestConfigAllowlistRegexes(t *testing.T) {
|
|||||||
`%MY_PASSWORD%`, `%password%`,
|
`%MY_PASSWORD%`, `%password%`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"interpolated variables - string fmt - golang": {
|
||||||
|
invalid: []string{
|
||||||
|
`%b`, `%c`, `%d`, `% d`, `%e`, `%E`, `%f`, `%F`, `%g`, `%G`, `%o`, `%O`, `%p`, `%q`, `%-s`, `%s`, `%t`, `%T`, `%U`, `%#U`, `%+v`, `%#v`, `%v`, `%x`, `%X`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"interpolated variables - string fmt - python": {
|
||||||
|
invalid: []string{
|
||||||
|
`{}`, `{0}`, `{10}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
"interpolated variables - ucd": {
|
"interpolated variables - ucd": {
|
||||||
invalid: []string{`@password@`, `@LDAP_PASS@`},
|
invalid: []string{`@password@`, `@LDAP_PASS@`},
|
||||||
valid: []string{`@username@mastodon.example`},
|
valid: []string{`@username@mastodon.example`},
|
||||||
},
|
},
|
||||||
"environment variables": {
|
|
||||||
invalid: []string{`$2`, `$GIT_PASSWORD`, `${GIT_PASSWORD}`, `$password`},
|
|
||||||
valid: []string{`$yP@R.@=ibxI`, `$2a6WCust9aE`, `${not_complete1`},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := CreateGlobalConfig()
|
cfg := CreateGlobalConfig()
|
||||||
|
|||||||
@@ -14,17 +14,21 @@ title = "gitleaks config"
|
|||||||
description = "global allow lists"
|
description = "global allow lists"
|
||||||
regexes = [
|
regexes = [
|
||||||
'''(?i)^true|false|null$''',
|
'''(?i)^true|false|null$''',
|
||||||
'''^\{\{[ \t]*[\w ().|]+[ \t]*}}$''',
|
'''^(?i:a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+|y+|z+|\*+|\.+)$''',
|
||||||
'''^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$''',
|
|
||||||
'''^%([A-Z_]+|[a-z_]+)%$''',
|
|
||||||
'''^@([A-Z_]+|[a-z_]+)@$''',
|
|
||||||
'''^\$(\d+|{\d+})$''',
|
'''^\$(\d+|{\d+})$''',
|
||||||
'''^\$([A-Z_]+|[a-z_]+)$''',
|
'''^\$([A-Z_]+|[a-z_]+)$''',
|
||||||
'''^\${([A-Z_]+|[a-z_]+)}$''',
|
'''^\${([A-Z_]+|[a-z_]+)}$''',
|
||||||
|
'''^\{\{[ \t]*[\w ().|]+[ \t]*}}$''',
|
||||||
|
'''^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$''',
|
||||||
|
'''^%([A-Z_]+|[a-z_]+)%$''',
|
||||||
|
'''^%[+\-# 0]?[bcdeEfFgGoOpqstTUvxX]$''',
|
||||||
|
'''^\{\d{0,2}}$''',
|
||||||
|
'''^@([A-Z_]+|[a-z_]+)@$''',
|
||||||
]
|
]
|
||||||
paths = [
|
paths = [
|
||||||
'''gitleaks\.toml''',
|
'''gitleaks\.toml''',
|
||||||
'''(?i)\.(bmp|gif|jpe?g|svg|tiff?)$''',
|
'''(?i)\.(bmp|gif|jpe?g|svg|tiff?)$''',
|
||||||
|
'''\.(eot|[ot]tf|woff2?)$''',
|
||||||
'''(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$''',
|
'''(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$''',
|
||||||
'''go\.(mod|sum|work(\.sum)?)$''',
|
'''go\.(mod|sum|work(\.sum)?)$''',
|
||||||
'''(^|/)vendor/modules\.txt$''',
|
'''(^|/)vendor/modules\.txt$''',
|
||||||
|
|||||||
Reference in new issue
Block a user