mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 20:54:22 +01:00
last updates?
This commit is contained in:
1 parent
2e7325ce03
commit
7dfa3f2b48
6 files changed
+35
-38
No files matched your search
+1
-1
@@ -9,4 +9,4 @@
|
|||||||
*.test
|
*.test
|
||||||
*.out
|
*.out
|
||||||
|
|
||||||
tmp
|
examples
|
||||||
+11
-6
@@ -66,11 +66,16 @@ files = [
|
|||||||
# [[rules]]
|
# [[rules]]
|
||||||
# description = "Generic Key"
|
# description = "Generic Key"
|
||||||
# regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
# regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||||
# entropies = ["4.1-4.3"]
|
# entropies = [
|
||||||
|
# "4.1-4.3",
|
||||||
|
# "5.5-6.3",
|
||||||
|
# ]
|
||||||
# entropyROI = "line"
|
# entropyROI = "line"
|
||||||
|
# filetypes = [".go", ".py", ".c"]
|
||||||
# tags = ["key"]
|
# tags = ["key"]
|
||||||
# severity = "8"
|
# severity = "8"
|
||||||
#
|
#
|
||||||
|
#
|
||||||
# [[rules]]
|
# [[rules]]
|
||||||
# description = "Generic Key"
|
# description = "Generic Key"
|
||||||
# regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
# regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||||
@@ -79,9 +84,9 @@ files = [
|
|||||||
# entropyROI = "line"
|
# entropyROI = "line"
|
||||||
# tags = ["key"]
|
# tags = ["key"]
|
||||||
# severity = "medium"
|
# severity = "medium"
|
||||||
#
|
|
||||||
# [[rules]]
|
# [[rules]]
|
||||||
# description = "Any go file"
|
# description = "Any pem file"
|
||||||
# filetypes = [".go"]
|
# filetypes = [".key"]
|
||||||
# tags = ["go files"]
|
# tags = ["pem"]
|
||||||
# severity = "low"
|
# severity = "high"
|
||||||
@@ -71,14 +71,14 @@ entropies = [
|
|||||||
]
|
]
|
||||||
`
|
`
|
||||||
|
|
||||||
const testEntropyLineRegexRange = `
|
const testEntropyWordRegexRange = `
|
||||||
[[rules]]
|
[[rules]]
|
||||||
description = "test entropy regex ranges"
|
description = "test entropy regex ranges"
|
||||||
regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||||
entropies = [
|
entropies = [
|
||||||
"4.1-4.3",
|
"4.1-4.3",
|
||||||
]
|
]
|
||||||
entropyROI="line"
|
entropyROI="word"
|
||||||
`
|
`
|
||||||
|
|
||||||
const testEntropyRegexRange = `
|
const testEntropyRegexRange = `
|
||||||
@@ -104,13 +104,12 @@ entropies = [
|
|||||||
"4.1-4.3",
|
"4.1-4.3",
|
||||||
]
|
]
|
||||||
filetypes = [".go"]
|
filetypes = [".go"]
|
||||||
entropyROI="line"
|
|
||||||
`
|
`
|
||||||
|
|
||||||
func testTomlLoader() string {
|
func testTomlLoader() string {
|
||||||
tmpDir, _ := ioutil.TempDir("", "whiteListConfigs")
|
tmpDir, _ := ioutil.TempDir("", "whiteListConfigs")
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "regex"), []byte(testWhitelistRegex), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "regex"), []byte(testWhitelistRegex), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "entropyLineRegex"), []byte(testEntropyLineRegexRange), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "entropyWordRegex"), []byte(testEntropyWordRegexRange), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "entropyRegex"), []byte(testEntropyRegexRange), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "entropyRegex"), []byte(testEntropyRegexRange), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
|
||||||
@@ -119,6 +118,6 @@ func testTomlLoader() string {
|
|||||||
ioutil.WriteFile(path.Join(tmpDir, "badEntropy"), []byte(testBadEntropyRange), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "badEntropy"), []byte(testBadEntropyRange), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "badEntropy2"), []byte(testBadEntropyRange2), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "badEntropy2"), []byte(testBadEntropyRange2), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "mdFiles"), []byte(testMDFileType), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "mdFiles"), []byte(testMDFileType), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "entropyLineRegexGo"), []byte(testEntropyRegexRangeGoFilter), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "entropyRegexGo"), []byte(testEntropyRegexRangeGoFilter), 0644)
|
||||||
return tmpDir
|
return tmpDir
|
||||||
}
|
}
|
||||||
+6
-13
@@ -561,29 +561,22 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "toml entropy range from opts",
|
description: "toml entropy range from opts",
|
||||||
numLeaks: 426,
|
numLeaks: 266,
|
||||||
testOpts: &Options{
|
testOpts: &Options{
|
||||||
ConfigPath: path.Join(configsDir, "entropy"),
|
ConfigPath: path.Join(configsDir, "entropy"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "toml entropy range",
|
description: "toml entropy regex word range",
|
||||||
numLeaks: 426,
|
numLeaks: 0,
|
||||||
testOpts: &Options{},
|
testOpts: &Options{},
|
||||||
configPath: path.Join(configsDir, "entropy"),
|
configPath: path.Join(configsDir, "entropyWordRegex"),
|
||||||
},
|
|
||||||
{
|
|
||||||
repo: leaksRepo,
|
|
||||||
description: "toml entropy regex line range",
|
|
||||||
numLeaks: 2,
|
|
||||||
testOpts: &Options{},
|
|
||||||
configPath: path.Join(configsDir, "entropyLineRegex"),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "toml entropy regex range",
|
description: "toml entropy regex range",
|
||||||
numLeaks: 0,
|
numLeaks: 2,
|
||||||
testOpts: &Options{},
|
testOpts: &Options{},
|
||||||
configPath: path.Join(configsDir, "entropyRegex"),
|
configPath: path.Join(configsDir, "entropyRegex"),
|
||||||
},
|
},
|
||||||
@@ -615,7 +608,7 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
description: "toml entropys line regex go",
|
description: "toml entropys line regex go",
|
||||||
numLeaks: 2,
|
numLeaks: 2,
|
||||||
testOpts: &Options{},
|
testOpts: &Options{},
|
||||||
configPath: path.Join(configsDir, "entropyLineRegexGo"),
|
configPath: path.Join(configsDir, "entropyRegexGo"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
g := goblin.Goblin(t)
|
g := goblin.Goblin(t)
|
||||||
|
|||||||
+3
-3
@@ -60,13 +60,13 @@ func ParseOpts() *Options {
|
|||||||
_, err := parser.Parse()
|
_, err := parser.Parse()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
|
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
|
||||||
os.Exit(0)
|
parser.WriteHelp(os.Stdout)
|
||||||
}
|
}
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) == 1 {
|
if len(os.Args) == 1 {
|
||||||
// TODO: this will be a feature, check locally
|
|
||||||
parser.WriteHelp(os.Stdout)
|
parser.WriteHelp(os.Stdout)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -103,16 +103,7 @@ func (rule *Rule) check(line string, commit *commitInfo) (*Leak, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rule.entropies != nil {
|
if rule.entropies != nil {
|
||||||
if rule.entropyROI == "line" {
|
if rule.entropyROI == "word" {
|
||||||
_entropy := getShannonEntropy(line)
|
|
||||||
for _, e := range rule.entropies {
|
|
||||||
if _entropy > e.v1 && _entropy < e.v2 {
|
|
||||||
entropy = _entropy
|
|
||||||
entropyWord = line
|
|
||||||
goto postEntropy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
words := strings.Fields(line)
|
words := strings.Fields(line)
|
||||||
for _, word := range words {
|
for _, word := range words {
|
||||||
_entropy := getShannonEntropy(word)
|
_entropy := getShannonEntropy(word)
|
||||||
@@ -124,6 +115,15 @@ func (rule *Rule) check(line string, commit *commitInfo) (*Leak, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_entropy := getShannonEntropy(line)
|
||||||
|
for _, e := range rule.entropies {
|
||||||
|
if _entropy > e.v1 && _entropy < e.v2 {
|
||||||
|
entropy = _entropy
|
||||||
|
entropyWord = line
|
||||||
|
goto postEntropy
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user