mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 13:34:23 +01:00
3 files changed
+55
-6
No files matched your search
+1
-4
@@ -21,9 +21,6 @@ regex = '''(?i)facebook.*['\"][0-9a-f]{32}['\"]'''
|
|||||||
description = "Twitter"
|
description = "Twitter"
|
||||||
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "Telegram"
|
|
||||||
regex = '''(?i)telegram.*['\"][0-9]{1,12}+:[0-9a-zA-Z-]{32,44}['\"]'''
|
|
||||||
[[regexes]]
|
|
||||||
description = "PGP"
|
description = "PGP"
|
||||||
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
@@ -38,5 +35,5 @@ regexes = [
|
|||||||
# "AKIA.*EXAMPLE",
|
# "AKIA.*EXAMPLE",
|
||||||
]
|
]
|
||||||
files = [
|
files = [
|
||||||
"(.*?)(jpg|gif|doc|pdf|bin|go)$"
|
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||||
]
|
]
|
||||||
@@ -489,6 +489,14 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
whiteListRegexes []*regexp.Regexp
|
whiteListRegexes []*regexp.Regexp
|
||||||
configPath string
|
configPath string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
repo: leaksRepo,
|
||||||
|
description: "pinned config",
|
||||||
|
numLeaks: 0,
|
||||||
|
testOpts: Options{
|
||||||
|
RepoConfig: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "commit depth = 1, one leak",
|
description: "commit depth = 1, one leak",
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ type Options struct {
|
|||||||
ExcludeForks bool `long:"exclude-forks" description:"exclude forks for organization/user audits"`
|
ExcludeForks bool `long:"exclude-forks" description:"exclude forks for organization/user audits"`
|
||||||
Entropy float64 `long:"entropy" short:"e" description:"Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)"`
|
Entropy float64 `long:"entropy" short:"e" description:"Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)"`
|
||||||
NoiseReduction bool `long:"noise-reduction" description:"Reduce the number of finds when entropy checks are enabled"`
|
NoiseReduction bool `long:"noise-reduction" description:"Reduce the number of finds when entropy checks are enabled"`
|
||||||
|
RepoConfig bool `long:"repo-config" description:"Load config from target repo. Config file must be \".gitleaks.toml\""`
|
||||||
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
||||||
|
|
||||||
// Output options
|
// Output options
|
||||||
@@ -437,6 +438,14 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if target contains an external gitleaks toml
|
||||||
|
if opts.RepoConfig {
|
||||||
|
err := externalConfig(repo)
|
||||||
|
if err != nil {
|
||||||
|
return leaks, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// clear commit cache
|
// clear commit cache
|
||||||
commitMap = make(map[string]bool)
|
commitMap = make(map[string]bool)
|
||||||
|
|
||||||
@@ -457,6 +466,29 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
return leaks, err
|
return leaks, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// externalConfig will attempt to load a pinned ".gitleaks.toml" configuration file
|
||||||
|
// from a remote or local repo. Use the --repo-config option to trigger this.
|
||||||
|
func externalConfig(repo *RepoDescriptor) error {
|
||||||
|
var config Config
|
||||||
|
wt, err := repo.repository.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f, err := wt.Filesystem.Open(".gitleaks.toml")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := toml.DecodeReader(f, &config); err != nil {
|
||||||
|
return fmt.Errorf("problem loading config: %v", err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateConfig(config)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// auditGitReference beings the audit for a git reference. This function will
|
// auditGitReference beings the audit for a git reference. This function will
|
||||||
// traverse the git reference and audit each line of each diff.
|
// traverse the git reference and audit each line of each diff.
|
||||||
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
||||||
@@ -515,7 +547,7 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
}
|
}
|
||||||
for _, re := range whiteListFiles {
|
for _, re := range whiteListFiles {
|
||||||
if re.FindString(f.Name) != "" {
|
if re.FindString(f.Name) != "" {
|
||||||
log.Infof("skipping whitelisted file (matched regex '%s'): %s", re.String(), f.Name)
|
log.Debugf("skipping whitelisted file (matched regex '%s'): %s", re.String(), f.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -588,7 +620,7 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
}
|
}
|
||||||
for _, re := range whiteListFiles {
|
for _, re := range whiteListFiles {
|
||||||
if re.FindString(filePath) != "" {
|
if re.FindString(filePath) != "" {
|
||||||
log.Infof("skipping whitelisted file (matched regex '%s'): %s", re.String(), filePath)
|
log.Debugf("skipping whitelisted file (matched regex '%s'): %s", re.String(), filePath)
|
||||||
skipFile = true
|
skipFile = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -894,6 +926,17 @@ func loadToml() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(config.Misc.Entropy) != 0 {
|
||||||
|
err := entropyLimits(config.Misc.Entropy)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return updateConfig(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateConfig will update a the global config values
|
||||||
|
func updateConfig(config Config) error {
|
||||||
if len(config.Misc.Entropy) != 0 {
|
if len(config.Misc.Entropy) != 0 {
|
||||||
err := entropyLimits(config.Misc.Entropy)
|
err := entropyLimits(config.Misc.Entropy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -927,6 +970,7 @@ func loadToml() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// entropyLimits hydrates entropyRanges which allows for fine tuning entropy checking
|
// entropyLimits hydrates entropyRanges which allows for fine tuning entropy checking
|
||||||
|
|||||||
Reference in new issue
Block a user