mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 05:04:22 +01:00
Define multiple allowlists per rule (#1496)
* feat: multiple rule allowlists * feat(config): add allowlist 'condition'
This commit is contained in:
1 parent
8ea608595c
commit
aabe381539
26 files changed
+778
-247
No files matched your search
@@ -43,23 +43,23 @@ keywords = [{{ range $j, $keyword := . }}"{{ $keyword }}"{{ end }}]{{end}}{{ end
|
||||
tags = [
|
||||
{{ range $j, $tag := . }}"{{ $tag }}",{{ end }}
|
||||
]{{ end }}
|
||||
{{ if or $rule.Allowlist.Regexes $rule.Allowlist.Paths $rule.Allowlist.Commits $rule.Allowlist.StopWords }}
|
||||
[rules.allowlist]
|
||||
{{- with $rule.Allowlist.RegexTarget }}
|
||||
regexTarget = "{{ . }}"{{ end -}}
|
||||
{{- with $rule.Allowlist.Regexes }}
|
||||
regexes = [{{ range $i, $regex := . }}
|
||||
'''{{ $regex }}''',{{ end }}
|
||||
]{{ end }}
|
||||
{{- with $rule.Allowlist.Paths }}paths = [
|
||||
{{ range $j, $path := . }}'''{{ $path }}''',{{ end }}
|
||||
]{{ end }}
|
||||
{{- with $rule.Allowlist.Commits }}commits = [
|
||||
{{ with $rule.Allowlists }}{{ range $i, $allowlist := . }}{{ if or $allowlist.Regexes $allowlist.Paths $allowlist.Commits $allowlist.StopWords }}
|
||||
[[rules.allowlists]]
|
||||
{{ with $allowlist.MatchCondition }}condition = "{{ . }}"
|
||||
{{ end -}}
|
||||
{{- with $allowlist.Commits }}commits = [
|
||||
{{ range $j, $commit := . }}"{{ $commit }}",{{ end }}
|
||||
]{{ end }}
|
||||
{{- with $rule.Allowlist.StopWords }}
|
||||
stopwords = [{{ range $j, $stopword := . }}
|
||||
"{{ $stopword }}",{{ end }}
|
||||
{{- with $allowlist.Paths }}paths = [
|
||||
{{ range $j, $path := . }}'''{{ $path }}''',{{ end }}
|
||||
]{{ end }}
|
||||
{{- with $allowlist.RegexTarget }}regexTarget = "{{ . }}"
|
||||
{{ end -}}
|
||||
{{- with $allowlist.Regexes }}regexes = [{{ range $i, $regex := . }}
|
||||
'''{{ $regex }}''',{{ end }}
|
||||
]{{ end }}
|
||||
{{- with $allowlist.StopWords }}stopwords = [{{ range $j, $stopword := . }}
|
||||
"{{ $stopword }}",{{ end }}
|
||||
]{{ end }}{{ end }}{{ end }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
@@ -33,8 +33,10 @@ func GenericCredential() *config.Rule {
|
||||
"access",
|
||||
},
|
||||
Entropy: 3.5,
|
||||
Allowlist: config.Allowlist{
|
||||
StopWords: DefaultStopWords,
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
StopWords: DefaultStopWords,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,12 @@ func VaultServiceToken() *config.Rule {
|
||||
Regex: utils.GenerateUniqueTokenRegex(`(?:hvs\.[\w-]{90,120}|s\.(?i:[a-z0-9]{24}))`, false),
|
||||
Entropy: 3.5,
|
||||
Keywords: []string{"hvs", "s."},
|
||||
Allowlist: config.Allowlist{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// https://github.com/gitleaks/gitleaks/issues/1490#issuecomment-2334166357
|
||||
regexp.MustCompile(`s\.[A-Za-z]{24}`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// https://github.com/gitleaks/gitleaks/issues/1490#issuecomment-2334166357
|
||||
regexp.MustCompile(`s\.[A-Za-z]{24}`),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -31,13 +31,15 @@ func KubernetesSecret() *config.Rule {
|
||||
},
|
||||
// Kubernetes secrets are usually yaml files.
|
||||
Path: regexp.MustCompile(`(?i)\.ya?ml$`),
|
||||
Allowlist: config.Allowlist{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// Ignore empty or placeholder values.
|
||||
// variable: {{ .Values.Example }} (https://helm.sh/docs/chart_template_guide/variables/)
|
||||
// variable: ""
|
||||
// variable: ''
|
||||
regexp.MustCompile(`[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// Ignore empty or placeholder values.
|
||||
// variable: {{ .Values.Example }} (https://helm.sh/docs/chart_template_guide/variables/)
|
||||
// variable: ""
|
||||
// variable: ''
|
||||
regexp.MustCompile(`[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')`),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -16,13 +16,15 @@ func NugetConfigPassword() *config.Rule {
|
||||
Path: regexp.MustCompile(`(?i)nuget\.config$`),
|
||||
Keywords: []string{"<add key="},
|
||||
Entropy: 1,
|
||||
Allowlist: config.Allowlist{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// samples from https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
|
||||
regexp.MustCompile(`33f!!lloppa`),
|
||||
regexp.MustCompile(`hal\+9ooo_da!sY`),
|
||||
// exclude environment variables
|
||||
regexp.MustCompile(`^\%\S.*\%$`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// samples from https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
|
||||
regexp.MustCompile(`33f!!lloppa`),
|
||||
regexp.MustCompile(`hal\+9ooo_da!sY`),
|
||||
// exclude environment variables
|
||||
regexp.MustCompile(`^\%\S.*\%$`),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -21,10 +21,13 @@ func SumoLogicAccessID() *config.Rule {
|
||||
Keywords: []string{
|
||||
"sumo",
|
||||
},
|
||||
Allowlist: config.Allowlist{
|
||||
RegexTarget: "line",
|
||||
Regexes: []*regexp.Regexp{
|
||||
regexp.MustCompile(`sumOf`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
RegexTarget: "line",
|
||||
Regexes: []*regexp.Regexp{regexp.MustCompile(`sumOf`)},
|
||||
},
|
||||
{
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`tests/.+$`)},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user