Compare commits

..
15 Commits
Author SHA1 Message Date
Zach Rice d5adf5ef3b commenting out git tests, will need to revisit eventually 2022-03-12 11:48:07 -06:00
Zach Rice a689900600 commenting out flaky test for now 2022-03-12 11:33:44 -06:00
Zach Rice 269cf670bc go mod tidying 2022-03-12 11:29:14 -06:00
Zach Rice 4091fda0fd more comments 2022-03-12 11:24:56 -06:00
Zach Rice 1a51d4ed36 adding git test again 2022-03-12 10:58:37 -06:00
Zach Rice 8b70e7fc2f handle goimports/go vet warnings 2022-03-12 10:44:51 -06:00
Zach Rice 57d2d345b6 more tests 2022-03-11 22:18:29 -06:00
Zach Rice c98afd3dec more cleaningup 2022-03-11 18:01:40 -06:00
Zach Rice c53e0fc98d maintaining parity between current master 2022-03-11 17:55:50 -06:00
Zach Rice 6fed917106 more bug 2022-03-11 17:24:35 -06:00
Zach Rice 165df09348 cleanup 2022-03-11 16:25:22 -06:00
Zach Rice 7bca6e757b more cleaning up 2022-03-11 15:00:31 -06:00
Zach Rice c9bc6b4608 getting some tests working 2022-03-11 13:05:18 -06:00
Zach Rice da1210db38 regular git scan parity 2022-03-11 11:56:54 -06:00
Zach Rice 593bb6ffad init 2022-03-11 09:30:12 -06:00
6 changed files with 14 additions and 135 deletions

No files matched your search

+1 -18
View File
@@ -536,24 +536,7 @@ secretGroup = 4
[allowlist]
description = "global allow lists"
regexes = [
'''219-09-9999''',
'''078-05-1120''',
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
'''process''',
'''getenv''',
'''\.env''',
'''env\(''',
'''env\.''',
'''setting''',
'''load''',
'''token''',
'''password''',
'''secret''',
'''api\_key''',
'''apikey''',
'''api\-key''',
]
regexes = ['''219-09-9999''', '''078-05-1120''', '''(9[0-9]{2}|666)-\d{2}-\d{4}''']
paths = [
'''gitleaks.toml''',
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
+3 -10
View File
@@ -29,8 +29,6 @@ const (
DetectType GitScanType = iota
ProtectType
ProtectStagedType
gitleaksAllowSignature = "gitleaks:allow"
)
// Detector is the main detector struct
@@ -172,8 +170,9 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
Tags: rule.Tags,
}
if strings.Contains(fragment.Raw[loc.startLineIndex:loc.endLineIndex],
gitleaksAllowSignature) {
// check if the secret is in the allowlist
if rule.Allowlist.RegexAllowed(finding.Secret) ||
d.Config.Allowlist.RegexAllowed(finding.Secret) {
continue
}
@@ -188,12 +187,6 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
finding.Secret = secret
}
// check if the secret is in the allowlist
if rule.Allowlist.RegexAllowed(finding.Secret) ||
d.Config.Allowlist.RegexAllowed(finding.Secret) {
continue
}
// check entropy
entropy := shannonEntropy(finding.Secret)
finding.Entropy = float32(entropy)
+8 -63
View File
@@ -23,53 +23,6 @@ func TestDetect(t *testing.T) {
expectedFindings []report.Finding
wantError error
}{
{
cfgName: "simple",
fragment: Fragment{
Raw: `awsToken := \"AKIALALEMEL33243OKIA\ // gitleaks:allow"`,
FilePath: "tmp.go",
},
expectedFindings: []report.Finding{},
},
{
cfgName: "simple",
fragment: Fragment{
Raw: `awsToken := \
\"AKIALALEMEL33243OKIA\ // gitleaks:allow"
`,
FilePath: "tmp.go",
},
expectedFindings: []report.Finding{},
},
{
cfgName: "simple",
fragment: Fragment{
Raw: `awsToken := \"AKIALALEMEL33243OKIA\"
// gitleaks:allow"
`,
FilePath: "tmp.go",
},
expectedFindings: []report.Finding{
{
Description: "AWS Access Key",
Secret: "AKIALALEMEL33243OKIA",
Match: "AKIALALEMEL33243OKIA",
File: "tmp.go",
RuleID: "aws-access-key",
Tags: []string{"key", "AWS"},
StartLine: 0,
EndLine: 0,
StartColumn: 15,
EndColumn: 34,
Entropy: 3.1464393,
},
},
},
{
cfgName: "escaped_character_group",
fragment: Fragment{
@@ -84,8 +37,8 @@ func TestDetect(t *testing.T) {
File: "tmp.go",
RuleID: "pypi-upload-token",
Tags: []string{"key", "pypi"},
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 1,
EndColumn: 86,
Entropy: 1.9606875,
@@ -106,8 +59,8 @@ func TestDetect(t *testing.T) {
File: "tmp.go",
RuleID: "aws-access-key",
Tags: []string{"key", "AWS"},
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 15,
EndColumn: 34,
Entropy: 3.0841837,
@@ -154,8 +107,8 @@ func TestDetect(t *testing.T) {
RuleID: "discord-api-key",
Tags: []string{},
Entropy: 3.7906237,
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 7,
EndColumn: 93,
},
@@ -184,8 +137,8 @@ func TestDetect(t *testing.T) {
RuleID: "generic-api-key",
Tags: []string{},
Entropy: 3.7906237,
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 22,
EndColumn: 93,
},
@@ -232,14 +185,6 @@ func TestDetect(t *testing.T) {
},
expectedFindings: []report.Finding{},
},
{
cfgName: "generic_with_py_path",
fragment: Fragment{
Raw: `const Discord_Public_Key = "load2523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
FilePath: "tmp.py",
},
expectedFindings: []report.Finding{},
},
}
for _, tt := range tests {
+2 -16
View File
@@ -46,22 +46,8 @@ func location(fragment Fragment, matchIndex []int) Location {
// a newline
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
location.endColumn = (end - prevNewLine)
location.startLine = _lineNum
location.endLine = _lineNum
location.startLineIndex = start
// search for new line byte index
i := 0
for end+i < len(fragment.Raw) {
if fragment.Raw[end+i] == '\n' {
break
}
if fragment.Raw[end+i] == '\r' {
break
}
i++
}
location.endLineIndex = end + i
location.startLine = _lineNum + 1
location.endLine = _lineNum + 1
}
return location
}
-1
View File
@@ -79,7 +79,6 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
}
}
}
if redact {
f.Redact()
}
-27
View File
@@ -7,30 +7,3 @@ regex = '''(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|
path = '''.py'''
entropy = 3.7
secretGroup = 4
[allowlist]
description = "global allow lists"
regexes = [
'''219-09-9999''',
'''078-05-1120''',
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
'''process''',
'''getenv''',
'''\.env''',
'''env\(''',
'''env\.''',
'''setting''',
'''load''',
'''token''',
'''password''',
'''secret''',
'''api\_key''',
'''apikey''',
'''api\-key''',
]
paths = [
'''gitleaks.toml''',
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
'''(go.mod|go.sum)$'''
]