From c0a9580a650a82166fb01058fc4953ee53f94c94 Mon Sep 17 00:00:00 2001 From: seb-elttam <68209237+seb-elttam@users.noreply.github.com> Date: Fri, 22 Jan 2021 06:31:21 +1000 Subject: [PATCH] Fix dotgit regex again (#507) * fix dotgit regex again * Revert accidentally modified files Co-authored-by: Seb Elttam --- config/allowlist.go | 2 +- test_data/test_allow_list_docx_no_git.json | 32 +++++++++++++++++++ test_data/test_allow_list_file_no_git.json | 16 ++++++++++ test_data/test_configs/allowlist_docx.toml | 2 +- test_data/test_repos/test_repo_10/creds.git | 0 .../test_repo_10/somedir.git/secret.key | 1 + 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test_data/test_repos/test_repo_10/creds.git create mode 100644 test_data/test_repos/test_repo_10/somedir.git/secret.key diff --git a/config/allowlist.go b/config/allowlist.go index daaed7db..8055a9bf 100644 --- a/config/allowlist.go +++ b/config/allowlist.go @@ -6,7 +6,7 @@ import ( // used for ignoring .git directories when the --no-git flag is set // related issue: https://github.com/zricethezav/gitleaks/issues/486 -const dotGit = `\.git/` +const dotGit = `/\.git/` // AllowList is struct containing items that if encountered will allowlist // a commit/line of code that would be considered a leak. diff --git a/test_data/test_allow_list_docx_no_git.json b/test_data/test_allow_list_docx_no_git.json index 50e44713..6cd05d39 100644 --- a/test_data/test_allow_list_docx_no_git.json +++ b/test_data/test_allow_list_docx_no_git.json @@ -46,5 +46,37 @@ "file": "../test_data/test_repos/test_repo_10/gitfile.txt", "date": "0001-01-01T00:00:00Z", "tags": "key, extensions" + }, + { + "line": "", + "lineNumber": 1, + "offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/creds.git", + "commit": "", + "repo": "", + "repoURL": "", + "leakURL": "", + "rule": "Block dangerous filetypes", + "commitMessage": "", + "author": "", + "email": "", + "file": "../test_data/test_repos/test_repo_10/creds.git", + "date": "0001-01-01T00:00:00Z", + "tags": "key, extensions" + }, + { + "line": "", + "lineNumber": 1, + "offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/somedir.git/secret.key", + "commit": "", + "repo": "", + "repoURL": "", + "leakURL": "", + "rule": "Block dangerous filetypes", + "commitMessage": "", + "author": "", + "email": "", + "file": "../test_data/test_repos/test_repo_10/somedir.git/secret.key", + "date": "0001-01-01T00:00:00Z", + "tags": "key, extensions" } ] diff --git a/test_data/test_allow_list_file_no_git.json b/test_data/test_allow_list_file_no_git.json index 200638be..d019602e 100644 --- a/test_data/test_allow_list_file_no_git.json +++ b/test_data/test_allow_list_file_no_git.json @@ -1,4 +1,20 @@ [ +{ + "line": "", + "lineNumber": 1, + "offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/somedir.git/secret.key", + "commit": "", + "repo": "", + "repoURL": "", + "leakURL": "", + "rule": "Block dangerous filetypes", + "commitMessage": "", + "author": "", + "email": "", + "file": "../test_data/test_repos/test_repo_10/somedir.git/secret.key", + "date": "0001-01-01T00:00:00Z", + "tags": "key, extensions" + }, { "line": "", "lineNumber": 1, diff --git a/test_data/test_configs/allowlist_docx.toml b/test_data/test_configs/allowlist_docx.toml index e76bde28..baeee4d3 100644 --- a/test_data/test_configs/allowlist_docx.toml +++ b/test_data/test_configs/allowlist_docx.toml @@ -1,6 +1,6 @@ [[rules]] description = "Block dangerous filetypes" - file = '''(.*?)(gitfile.txt|gitignore|pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$''' + file = '''(.*?)(creds.git|gitfile.txt|gitignore|pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$''' tags = ["key", "extensions"] [rules.allowlist] paths = ['''.docx'''] diff --git a/test_data/test_repos/test_repo_10/creds.git b/test_data/test_repos/test_repo_10/creds.git new file mode 100644 index 00000000..e69de29b diff --git a/test_data/test_repos/test_repo_10/somedir.git/secret.key b/test_data/test_repos/test_repo_10/somedir.git/secret.key new file mode 100644 index 00000000..70b8a06c --- /dev/null +++ b/test_data/test_repos/test_repo_10/somedir.git/secret.key @@ -0,0 +1 @@ +hah