mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Use allowlist (#411)
This commit is contained in:
1 parent
fe69a17c9c
commit
94f5950d68
21 files changed
+111
-111
No files matched your search
+2
-2
@@ -76,8 +76,8 @@ func Run(m *manager.Manager) error {
|
||||
}
|
||||
|
||||
func runHelper(r *Repo) error {
|
||||
// Ignore whitelisted repos
|
||||
for _, wlRepo := range r.Manager.Config.Whitelist.Repos {
|
||||
// Ignore allowlisted repos
|
||||
for _, wlRepo := range r.Manager.Config.Allowlist.Repos {
|
||||
if RegexMatched(r.Manager.Opts.RepoPath, wlRepo) {
|
||||
return nil
|
||||
}
|
||||
|
||||
+22
-22
@@ -34,21 +34,21 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
|
||||
|
||||
bundle.lineLookup = make(map[string]bool)
|
||||
|
||||
// We want to check if there is a whitelist for this file
|
||||
if len(repo.config.Whitelist.Files) != 0 {
|
||||
for _, reFileName := range repo.config.Whitelist.Files {
|
||||
// We want to check if there is a allowlist for this file
|
||||
if len(repo.config.Allowlist.Files) != 0 {
|
||||
for _, reFileName := range repo.config.Allowlist.Files {
|
||||
if RegexMatched(filename, reFileName) {
|
||||
log.Debugf("whitelisted file found, skipping scan of file: %s", filename)
|
||||
log.Debugf("allowlisted file found, skipping scan of file: %s", filename)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We want to check if there is a whitelist for this path
|
||||
if len(repo.config.Whitelist.Paths) != 0 {
|
||||
for _, reFilePath := range repo.config.Whitelist.Paths {
|
||||
// We want to check if there is a allowlist for this path
|
||||
if len(repo.config.Allowlist.Paths) != 0 {
|
||||
for _, reFilePath := range repo.config.Allowlist.Paths {
|
||||
if RegexMatched(path, reFilePath) {
|
||||
log.Debugf("file in whitelisted path found, skipping scan of file: %s", filename)
|
||||
log.Debugf("file in allowlisted path found, skipping scan of file: %s", filename)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -57,8 +57,8 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
|
||||
for _, rule := range repo.config.Rules {
|
||||
start := time.Now()
|
||||
|
||||
// For each rule we want to check filename whitelists
|
||||
if isFileNameWhiteListed(filename, rule.Whitelist) || isFilePathWhiteListed(path, rule.Whitelist) {
|
||||
// For each rule we want to check filename allowlists
|
||||
if isFileNameWhiteListed(filename, rule.Allowlist) || isFilePathWhiteListed(path, rule.Allowlist) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
|
||||
offender := bundle.Content[loc[0]:loc[1]]
|
||||
groups := rule.Regex.FindStringSubmatch(offender)
|
||||
|
||||
if isOffenderWhiteListed(offender, rule.Whitelist) {
|
||||
if isOffenderWhiteListed(offender, rule.Allowlist) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -352,8 +352,8 @@ func ruleContainFilePathRegex(rule config.Rule) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func isCommitWhiteListed(commitHash string, whitelistedCommits []string) bool {
|
||||
for _, hash := range whitelistedCommits {
|
||||
func isCommitWhiteListed(commitHash string, allowlistedCommits []string) bool {
|
||||
for _, hash := range allowlistedCommits {
|
||||
if commitHash == hash {
|
||||
return true
|
||||
}
|
||||
@@ -361,9 +361,9 @@ func isCommitWhiteListed(commitHash string, whitelistedCommits []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func isOffenderWhiteListed(offender string, whitelist []config.Whitelist) bool {
|
||||
if len(whitelist) != 0 {
|
||||
for _, wl := range whitelist {
|
||||
func isOffenderWhiteListed(offender string, allowlist []config.Allowlist) bool {
|
||||
if len(allowlist) != 0 {
|
||||
for _, wl := range allowlist {
|
||||
if wl.Regex.FindString(offender) != "" {
|
||||
return true
|
||||
}
|
||||
@@ -372,9 +372,9 @@ func isOffenderWhiteListed(offender string, whitelist []config.Whitelist) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func isFileNameWhiteListed(filename string, whitelist []config.Whitelist) bool {
|
||||
if len(whitelist) != 0 {
|
||||
for _, wl := range whitelist {
|
||||
func isFileNameWhiteListed(filename string, allowlist []config.Allowlist) bool {
|
||||
if len(allowlist) != 0 {
|
||||
for _, wl := range allowlist {
|
||||
if RegexMatched(filename, wl.File) {
|
||||
return true
|
||||
}
|
||||
@@ -383,9 +383,9 @@ func isFileNameWhiteListed(filename string, whitelist []config.Whitelist) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func isFilePathWhiteListed(filepath string, whitelist []config.Whitelist) bool {
|
||||
if len(whitelist) != 0 {
|
||||
for _, wl := range whitelist {
|
||||
func isFilePathWhiteListed(filepath string, allowlist []config.Allowlist) bool {
|
||||
if len(allowlist) != 0 {
|
||||
for _, wl := range allowlist {
|
||||
if RegexMatched(filepath, wl.Path) {
|
||||
return true
|
||||
}
|
||||
|
||||
+5
-5
@@ -95,8 +95,8 @@ func (repo *Repo) Scan() error {
|
||||
return storer.ErrStop
|
||||
}
|
||||
|
||||
// Check if Commit is whitelisted
|
||||
if isCommitWhiteListed(c.Hash.String(), repo.config.Whitelist.Commits) {
|
||||
// Check if Commit is allowlisted
|
||||
if isCommitWhiteListed(c.Hash.String(), repo.config.Allowlist.Commits) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ func (repo *Repo) scanUncommitted() error {
|
||||
|
||||
// scan accepts a Patch, Commit, and repo. If the patches contains files that are
|
||||
// binary, then gitleaks will skip scanning that file OR if a file is matched on
|
||||
// whitelisted files set in the configuration. If a global rule for files is defined and a filename
|
||||
// allowlisted files set in the configuration. If a global rule for files is defined and a filename
|
||||
// matches said global rule, then a leak is sent to the manager.
|
||||
// After that, file chunks are created which are then inspected by InspectString()
|
||||
func scanPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
|
||||
@@ -360,7 +360,7 @@ func scanCommit(commit string, repo *Repo, f commitScanner) error {
|
||||
// scanCommitPatches accepts a Commit object and a repo. This function is only called when the --Commit=
|
||||
// option has been set. That option tells gitleaks to look only at a single Commit and check the contents
|
||||
// of said Commit. Similar to scan(), if the files contained in the Commit are a binaries or if they are
|
||||
// whitelisted then those files will be skipped.
|
||||
// allowlisted then those files will be skipped.
|
||||
func scanCommitPatches(c *object.Commit, repo *Repo) error {
|
||||
if len(c.ParentHashes) == 0 {
|
||||
err := scanFilesAtCommit(c, repo)
|
||||
@@ -400,7 +400,7 @@ func scanCommitPatches(c *object.Commit, repo *Repo) error {
|
||||
// scanFilesAtCommit accepts a Commit object and a repo. This function is only called when the --files-at-Commit=
|
||||
// option has been set. That option tells gitleaks to look only at ALL the files at a Commit and check the contents
|
||||
// of said Commit. Similar to scan(), if the files contained in the Commit are a binaries or if they are
|
||||
// whitelisted then those files will be skipped.
|
||||
// allowlisted then those files will be skipped.
|
||||
func scanFilesAtCommit(c *object.Commit, repo *Repo) error {
|
||||
fIter, err := c.Files()
|
||||
if err != nil {
|
||||
|
||||
+20
-20
@@ -58,11 +58,11 @@ func TestScan(t *testing.T) {
|
||||
emptyRepo: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo one aws leak whitelisted",
|
||||
description: "test local repo one aws leak allowlisted",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_1",
|
||||
ReportFormat: "json",
|
||||
Config: "../test_data/test_configs/aws_key_whitelist_python_files.toml",
|
||||
Config: "../test_data/test_configs/aws_key_allowlist_python_files.toml",
|
||||
},
|
||||
wantEmpty: true,
|
||||
},
|
||||
@@ -107,19 +107,19 @@ func TestScan(t *testing.T) {
|
||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_range.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks globally whitelisted",
|
||||
description: "test local repo two leaks globally allowlisted",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||
Config: "../test_data/test_configs/aws_key_global_whitelist_file.toml",
|
||||
Config: "../test_data/test_configs/aws_key_global_allowlist_file.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks whitelisted",
|
||||
description: "test local repo two leaks allowlisted",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||
Config: "../test_data/test_configs/aws_key_whitelist_files.toml",
|
||||
Config: "../test_data/test_configs/aws_key_allowlist_files.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantEmpty: true,
|
||||
@@ -174,14 +174,14 @@ func TestScan(t *testing.T) {
|
||||
wantPath: "../test_data/test_local_owner_aws_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test owner path whitelist repo",
|
||||
description: "test owner path allowlist repo",
|
||||
opts: options.Options{
|
||||
OwnerPath: "../test_data/test_repos/",
|
||||
Report: "../test_data/test_local_owner_aws_leak_whitelist_repo.json.got",
|
||||
Report: "../test_data/test_local_owner_aws_leak_allowlist_repo.json.got",
|
||||
ReportFormat: "json",
|
||||
Config: "../test_data/test_configs/aws_key_local_owner_whitelist_repo.toml",
|
||||
Config: "../test_data/test_configs/aws_key_local_owner_allowlist_repo.toml",
|
||||
},
|
||||
wantPath: "../test_data/test_local_owner_aws_leak_whitelist_repo.json",
|
||||
wantPath: "../test_data/test_local_owner_aws_leak_allowlist_repo.json",
|
||||
},
|
||||
{
|
||||
description: "test entropy and regex",
|
||||
@@ -207,8 +207,8 @@ func TestScan(t *testing.T) {
|
||||
description: "test local repo four entropy alternative config",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_regex_whitelist.json.got",
|
||||
Config: "../test_data/test_configs/aws_key_aws_whitelisted.toml",
|
||||
Report: "../test_data/test_regex_allowlist.json.got",
|
||||
Config: "../test_data/test_configs/aws_key_aws_allowlisted.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantEmpty: true,
|
||||
@@ -316,14 +316,14 @@ func TestScan(t *testing.T) {
|
||||
wantPath: "../test_data/test_local_repo_six_filepath_filename.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six path globally whitelisted",
|
||||
description: "test local repo six path globally allowlisted",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_path_globally_whitelisted.json.got",
|
||||
Config: "../test_data/test_configs/aws_key_global_whitelist_path.toml",
|
||||
Report: "../test_data/test_local_repo_six_path_globally_allowlisted.json.got",
|
||||
Config: "../test_data/test_configs/aws_key_global_allowlist_path.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_path_globally_whitelisted.json",
|
||||
wantPath: "../test_data/test_local_repo_six_path_globally_allowlisted.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six leaks since date",
|
||||
@@ -357,14 +357,14 @@ func TestScan(t *testing.T) {
|
||||
wantPath: "../test_data/test_local_repo_four_leaks_commit_timerange.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two whitelist Commit config",
|
||||
description: "test local repo two allowlist Commit config",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_whitelist_commits.json.got",
|
||||
Config: "../test_data/test_configs/whitelist_commit.toml",
|
||||
Report: "../test_data/test_local_repo_two_allowlist_commits.json.got",
|
||||
Config: "../test_data/test_configs/allowlist_commit.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_whitelist_commits.json",
|
||||
wantPath: "../test_data/test_local_repo_two_allowlist_commits.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two deletion",
|
||||
|
||||
Reference in new issue
Block a user