Skip to content

Commit

Permalink
Keyword (#825)
Browse files Browse the repository at this point in the history
* wip keywords optimization

* update readme

* limit concurrency to 4

* update readme
  • Loading branch information
zricethezav committed Apr 5, 2022
1 parent 237b03a commit b0a958f
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 40 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ make build
- id: gitleaks
```
for a [native execution of GitLeaks](https://github.com/zricethezav/gitleaks/releases) or use the [`gitleaks-docker` pre-commit ID](https://github.com/zricethezav/gitleaks/blob/master/.pre-commit-hooks.yaml) for executing GitLeaks using the [official Docker images](#docker)

3. Install with `pre-commit install`
4. Now you're all set!
```
Expand Down Expand Up @@ -227,6 +227,17 @@ secretGroup = 3
# Float representing the minimum shannon entropy a regex group must have to be considered a secret.
entropy = 3.5

# Keywords are used for pre-regex check filtering. Rules that contain
# keywords will perform a quick string compare check to make sure the
# keyword(s) are in the content being scanned. Ideally these values should
# either be part of the idenitifer or unique strings specific to the rule's regex
# (introduced in v8.6.0)
keywords = [
"auth",
"password",
"token",
]

# You can include an allowlist table for a single rule to reduce false positives or ignore commits
# with known/rotated secrets
[rules.allowlist]
Expand All @@ -252,8 +263,8 @@ paths = [
'''(.*?)(jpg|gif|doc)'''
]
regexes = [
'''219-09-9999''',
'''078-05-1120''',
'''219-09-9999''',
'''078-05-1120''',
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
]
```
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ViperConfig struct {
Entropy float64
SecretGroup int
Regex string
Keywords []string
Path string
Tags []string

Expand Down Expand Up @@ -56,6 +57,10 @@ func (vc *ViperConfig) Translate() (Config, error) {
allowlistPaths = append(allowlistPaths, regexp.MustCompile(a))
}

if r.Keywords == nil {
r.Keywords = []string{}
}

if r.Tags == nil {
r.Tags = []string{}
}
Expand All @@ -80,6 +85,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
SecretGroup: r.SecretGroup,
Entropy: r.Entropy,
Tags: r.Tags,
Keywords: r.Keywords,
Allowlist: Allowlist{
Regexes: allowlistRegexes,
Paths: allowlistPaths,
Expand Down
4 changes: 4 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestTranslate(t *testing.T) {
Description: "AWS Access Key",
Regex: regexp.MustCompile("(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"),
Tags: []string{"key", "AWS"},
Keywords: []string{},
RuleID: "aws-access-key",
Allowlist: Allowlist{
Regexes: []*regexp.Regexp{
Expand All @@ -43,6 +44,7 @@ func TestTranslate(t *testing.T) {
Description: "AWS Access Key",
Regex: regexp.MustCompile("(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"),
Tags: []string{"key", "AWS"},
Keywords: []string{},
RuleID: "aws-access-key",
Allowlist: Allowlist{
Commits: []string{"allowthiscommit"},
Expand All @@ -59,6 +61,7 @@ func TestTranslate(t *testing.T) {
Description: "AWS Access Key",
Regex: regexp.MustCompile("(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"),
Tags: []string{"key", "AWS"},
Keywords: []string{},
RuleID: "aws-access-key",
Allowlist: Allowlist{
Paths: []*regexp.Regexp{
Expand All @@ -81,6 +84,7 @@ func TestTranslate(t *testing.T) {
Entropy: 3.5,
SecretGroup: 3,
Tags: []string{},
Keywords: []string{},
},
},
},
Expand Down

0 comments on commit b0a958f

Please sign in to comment.