mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e5e63956e | ||
|
|
57f9bc83d1 | ||
|
|
6e72472b60 |
No files matched your search
+18
-1
@@ -536,7 +536,24 @@ secretGroup = 4
|
|||||||
|
|
||||||
[allowlist]
|
[allowlist]
|
||||||
description = "global allow lists"
|
description = "global allow lists"
|
||||||
regexes = ['''219-09-9999''', '''078-05-1120''', '''(9[0-9]{2}|666)-\d{2}-\d{4}''']
|
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 = [
|
paths = [
|
||||||
'''gitleaks.toml''',
|
'''gitleaks.toml''',
|
||||||
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
|
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
|
||||||
|
|||||||
+10
-3
@@ -29,6 +29,8 @@ const (
|
|||||||
DetectType GitScanType = iota
|
DetectType GitScanType = iota
|
||||||
ProtectType
|
ProtectType
|
||||||
ProtectStagedType
|
ProtectStagedType
|
||||||
|
|
||||||
|
gitleaksAllowSignature = "gitleaks:allow"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Detector is the main detector struct
|
// Detector is the main detector struct
|
||||||
@@ -170,9 +172,8 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
|
|||||||
Tags: rule.Tags,
|
Tags: rule.Tags,
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the secret is in the allowlist
|
if strings.Contains(fragment.Raw[loc.startLineIndex:loc.endLineIndex],
|
||||||
if rule.Allowlist.RegexAllowed(finding.Secret) ||
|
gitleaksAllowSignature) {
|
||||||
d.Config.Allowlist.RegexAllowed(finding.Secret) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +188,12 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
|
|||||||
finding.Secret = secret
|
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
|
// check entropy
|
||||||
entropy := shannonEntropy(finding.Secret)
|
entropy := shannonEntropy(finding.Secret)
|
||||||
finding.Entropy = float32(entropy)
|
finding.Entropy = float32(entropy)
|
||||||
|
|||||||
+63
-8
@@ -23,6 +23,53 @@ func TestDetect(t *testing.T) {
|
|||||||
expectedFindings []report.Finding
|
expectedFindings []report.Finding
|
||||||
wantError error
|
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",
|
cfgName: "escaped_character_group",
|
||||||
fragment: Fragment{
|
fragment: Fragment{
|
||||||
@@ -37,8 +84,8 @@ func TestDetect(t *testing.T) {
|
|||||||
File: "tmp.go",
|
File: "tmp.go",
|
||||||
RuleID: "pypi-upload-token",
|
RuleID: "pypi-upload-token",
|
||||||
Tags: []string{"key", "pypi"},
|
Tags: []string{"key", "pypi"},
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 1,
|
StartColumn: 1,
|
||||||
EndColumn: 86,
|
EndColumn: 86,
|
||||||
Entropy: 1.9606875,
|
Entropy: 1.9606875,
|
||||||
@@ -59,8 +106,8 @@ func TestDetect(t *testing.T) {
|
|||||||
File: "tmp.go",
|
File: "tmp.go",
|
||||||
RuleID: "aws-access-key",
|
RuleID: "aws-access-key",
|
||||||
Tags: []string{"key", "AWS"},
|
Tags: []string{"key", "AWS"},
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 15,
|
StartColumn: 15,
|
||||||
EndColumn: 34,
|
EndColumn: 34,
|
||||||
Entropy: 3.0841837,
|
Entropy: 3.0841837,
|
||||||
@@ -107,8 +154,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "discord-api-key",
|
RuleID: "discord-api-key",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 3.7906237,
|
Entropy: 3.7906237,
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 7,
|
StartColumn: 7,
|
||||||
EndColumn: 93,
|
EndColumn: 93,
|
||||||
},
|
},
|
||||||
@@ -137,8 +184,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "generic-api-key",
|
RuleID: "generic-api-key",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 3.7906237,
|
Entropy: 3.7906237,
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 22,
|
StartColumn: 22,
|
||||||
EndColumn: 93,
|
EndColumn: 93,
|
||||||
},
|
},
|
||||||
@@ -185,6 +232,14 @@ func TestDetect(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedFindings: []report.Finding{},
|
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 {
|
for _, tt := range tests {
|
||||||
|
|||||||
+16
-2
@@ -46,8 +46,22 @@ func location(fragment Fragment, matchIndex []int) Location {
|
|||||||
// a newline
|
// a newline
|
||||||
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
|
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
|
||||||
location.endColumn = (end - prevNewLine)
|
location.endColumn = (end - prevNewLine)
|
||||||
location.startLine = _lineNum + 1
|
location.startLine = _lineNum
|
||||||
location.endLine = _lineNum + 1
|
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
|
||||||
}
|
}
|
||||||
return location
|
return location
|
||||||
}
|
}
|
||||||
@@ -79,6 +79,7 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if redact {
|
if redact {
|
||||||
f.Redact()
|
f.Redact()
|
||||||
}
|
}
|
||||||
|
|||||||
+27
@@ -7,3 +7,30 @@ regex = '''(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|
|
|||||||
path = '''.py'''
|
path = '''.py'''
|
||||||
entropy = 3.7
|
entropy = 3.7
|
||||||
secretGroup = 4
|
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)$'''
|
||||||
|
]
|
||||||
|
|
||||||
Reference in new issue
Block a user