From f735c9a5c9b6fd0599668a0c4dceccaab600779d Mon Sep 17 00:00:00 2001 From: AmitHofree Date: Sun, 2 May 2021 15:47:05 +0300 Subject: [PATCH 01/14] Removed unnecessary backslashes --- config/default.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/default.go b/config/default.go index cb9d8f1a..345d0e2b 100644 --- a/config/default.go +++ b/config/default.go @@ -80,7 +80,7 @@ title = "gitleaks config" [[rules]] description = "Google API key" - regex = '''AIza[0-9A-Za-z\\-_]{35}''' + regex = '''AIza[0-9A-Za-z\-_]{35}''' tags = ["key", "Google"] [[rules]] @@ -135,7 +135,7 @@ title = "gitleaks config" [[rules]] description = "Square OAuth secret" - regex = '''sq0csp-[0-9A-Za-z\\-_]{43}''' + regex = '''sq0csp-[0-9A-Za-z\-_]{43}''' tags = ["key", "square"] [[rules]] From 45c898c5ea56ee503a048c1bac1404cf63855edc Mon Sep 17 00:00:00 2001 From: amith-legit Date: Thu, 9 Sep 2021 11:26:10 +0300 Subject: [PATCH 02/14] Added a test for fixed Google and Square config --- scan/scan_test.go | 10 ++++++ ...t_dir_one_google_leak_and_square_leak.json | 36 +++++++++++++++++++ test_data/test_repos/test_dir_2/env | 3 ++ 3 files changed, 49 insertions(+) create mode 100644 test_data/test_dir_one_google_leak_and_square_leak.json create mode 100644 test_data/test_repos/test_dir_2/env diff --git a/scan/scan_test.go b/scan/scan_test.go index c8b4f845..4e690115 100644 --- a/scan/scan_test.go +++ b/scan/scan_test.go @@ -533,6 +533,16 @@ func TestScan(t *testing.T) { }, wantEmpty: true, }, + { + description: "test dir two google api key leak AND square oauth leak", + opts: options.Options{ + Path: "../test_data/test_repos/test_dir_2", + Report: "../test_data/test_dir_one_google_leak_and_square_leak.json.got", + ReportFormat: "json", + NoGit: true, + }, + wantPath: "../test_data/test_dir_one_google_leak_and_square_leak.json", + }, } for _, test := range tests { diff --git a/test_data/test_dir_one_google_leak_and_square_leak.json b/test_data/test_dir_one_google_leak_and_square_leak.json new file mode 100644 index 00000000..cb4eb956 --- /dev/null +++ b/test_data/test_dir_one_google_leak_and_square_leak.json @@ -0,0 +1,36 @@ +[ + { + "line": "SQUARE_OAUTH=sq0csp-QZxqK3fHycIxFsjZ7_HoqRN08qY2by3wLXcfJCfsKEg", + "lineNumber": 1, + "offender": "sq0csp-QZxqK3fHycIxFsjZ7_HoqRN08qY2by3wLXcfJCfsKEg", + "offenderEntropy": -1, + "commit": "", + "repo": "", + "repoURL": "", + "leakURL": "", + "rule": "Square OAuth secret", + "commitMessage": "", + "author": "", + "email": "", + "file": ".", + "date": "0001-01-01T00:00:00Z", + "tags": "key, square" + }, + { + "line": "GOOGLE_MAPS_KEY=AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg", + "lineNumber": 3, + "offender": "AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg", + "offenderEntropy": -1, + "commit": "", + "repo": "", + "repoURL": "", + "leakURL": "", + "rule": "Google API key", + "commitMessage": "", + "author": "", + "email": "", + "file": ".", + "date": "0001-01-01T00:00:00Z", + "tags": "key, Google" + } + ] \ No newline at end of file diff --git a/test_data/test_repos/test_dir_2/env b/test_data/test_repos/test_dir_2/env new file mode 100644 index 00000000..5472a5cf --- /dev/null +++ b/test_data/test_repos/test_dir_2/env @@ -0,0 +1,3 @@ +SQUARE_OAUTH=sq0csp-QZxqK3fHycIxFsjZ7_HoqRN08qY2by3wLXcfJCfsKEg + +GOOGLE_MAPS_KEY=AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg \ No newline at end of file From 5f87c4137c9685040dbe3cfd52311a780fd60099 Mon Sep 17 00:00:00 2001 From: Nick Russler Date: Mon, 4 Oct 2021 21:51:59 +0200 Subject: [PATCH 03/14] Bump alpine to v3.14.2 This alpine release includes fixes for openssl CVE-2021-3711 and CVE-2021-3712 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ce6a7cba..a8775bd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG ldflags COPY . . RUN GO111MODULE=on CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X="${ldflags} *.go -FROM alpine:3.14.1 +FROM alpine:3.14.2 RUN adduser -D gitleaks && \ apk add --no-cache bash git openssh-client COPY --from=build /go/src/github.com/zricethezav/gitleaks/bin/* /usr/bin/ From 05e346202567c6aefabff201a9526285ca307e7a Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Fri, 8 Oct 2021 16:53:00 -0400 Subject: [PATCH 04/14] build: add apple m1 support Signed-off-by: Rui Chen --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ebfdc6ad..f8dcb314 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ release-builds: env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" $(LDFLAGS) env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" $(LDFLAGS) env GOOS="darwin" GOARCH="amd64" go build -o "build/gitleaks-darwin-amd64" $(LDFLAGS) + env GOOS="darwin" GOARCH="arm64" go build -o "build/gitleaks-darwin-arm64" $(LDFLAGS) deploy: @echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin From d8e3a694f29e810e350b4ae4b885132f84b349ed Mon Sep 17 00:00:00 2001 From: "Matthew E. Grahlman" Date: Sat, 9 Oct 2021 10:55:39 -0400 Subject: [PATCH 05/14] Fixed bug in extractLine function which was returning incorrect line # when the line contains multiple vuln types --- scan/utils.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scan/utils.go b/scan/utils.go index f9ec4cfd..92bb6de7 100644 --- a/scan/utils.go +++ b/scan/utils.go @@ -212,6 +212,8 @@ func extractLine(patchContent string, leak Leak, lineLookup map[string]bool) int if _, ok := lineLookup[fmt.Sprintf("%s%s%d%s", leak.Offender, leak.Line, lineNumber, leak.File)]; !ok { lineLookup[fmt.Sprintf("%s%s%d%s", leak.Offender, leak.Line, lineNumber, leak.File)] = true return lineNumber + } else if ok { + return lineNumber } } currLine++ From 14a00e1ffd3fef8e04670b5f7cad79d5f63b111e Mon Sep 17 00:00:00 2001 From: dani Date: Sun, 10 Oct 2021 12:47:46 +0200 Subject: [PATCH 06/14] chore: lint code --- scan/report.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scan/report.go b/scan/report.go index cbbb2f92..1dd04f77 100644 --- a/scan/report.go +++ b/scan/report.go @@ -4,8 +4,8 @@ import ( "encoding/csv" "encoding/json" "os" - "strings" "regexp" + "strings" "time" "github.com/sirupsen/logrus" From 3a3e13c3b5f85b0116cf2a0cd92529baf22d0ac9 Mon Sep 17 00:00:00 2001 From: amith-legit Date: Sun, 10 Oct 2021 22:51:44 +0300 Subject: [PATCH 07/14] Added EOL to sample file --- testdata/repos/with_square_and_google/env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdata/repos/with_square_and_google/env b/testdata/repos/with_square_and_google/env index 5472a5cf..db967dae 100644 --- a/testdata/repos/with_square_and_google/env +++ b/testdata/repos/with_square_and_google/env @@ -1,3 +1,3 @@ SQUARE_OAUTH=sq0csp-QZxqK3fHycIxFsjZ7_HoqRN08qY2by3wLXcfJCfsKEg -GOOGLE_MAPS_KEY=AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg \ No newline at end of file +GOOGLE_MAPS_KEY=AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg From c85ebbb2baf2ab6c406349ef4656073f4b7a615e Mon Sep 17 00:00:00 2001 From: amith-legit Date: Sun, 10 Oct 2021 22:51:54 +0300 Subject: [PATCH 08/14] Try to revert index file --- testdata/repos/basic/dotGit/index | Bin 217 -> 217 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/testdata/repos/basic/dotGit/index b/testdata/repos/basic/dotGit/index index 0c9a65b04099fa978906e627d30966bfef5b49dc..420b9edacff0039f2c2454fbccd2ab6b581c9f42 100644 GIT binary patch delta 65 zcmcb~c#~1Z#WTp6fq{VugcB_U4duJ0n}X>M{&kED46IDoTy{=WStt_!d#mLOuQv@$ QS`pz>% delta 65 zcmcb~c#~1Z#WTp6fq{VugcIW~Z+1i Date: Sun, 10 Oct 2021 16:38:24 -0400 Subject: [PATCH 09/14] Made changes to add support for cross-platform (os) testing as tests would pass on MacOS but no Windows --- config/config_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index d1eea0b8..7f7e7813 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -30,95 +30,95 @@ func TestParse(t *testing.T) { { description: "test successful load", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "aws_key.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "aws_key.toml")), }, }, { description: "test bad toml", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_aws_key.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key.toml")), }, wantErr: fmt.Errorf("Near line 7 (last key parsed 'rules.description'): expected value but found \"AWS\" instead"), }, { description: "test bad regex", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_regex_aws_key.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_regex_aws_key.toml")), }, wantErr: fmt.Errorf("problem loading config: error parsing regexp: invalid nested repetition operator: `???`"), }, { description: "test bad global allowlist file regex", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_aws_key_global_allowlist_file.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key_global_allowlist_file.toml")), }, wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"), }, { description: "test bad global file regex", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_aws_key_file_regex.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key_file_regex.toml")), }, wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"), }, { description: "test successful load big ol thing", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "large.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "large.toml")), }, }, { description: "test load entropy", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "entropy.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "entropy.toml")), }, }, { description: "test entropy bad range", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_1.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_1.toml")), }, wantErr: fmt.Errorf("problem loading config: entropy Min value cannot be higher than Max value"), }, { description: "test entropy value max", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_2.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_2.toml")), }, wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"), }, { description: "test entropy value min", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_3.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_3.toml")), }, wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"), }, { description: "test entropy value group", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_4.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_4.toml")), }, wantErr: fmt.Errorf("strconv.ParseInt: parsing \"x\": invalid syntax"), }, { description: "test entropy value group", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_5.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_5.toml")), }, wantErr: fmt.Errorf("problem loading config: group cannot be lower than 0"), }, { description: "test entropy value group", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_6.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_6.toml")), }, wantErr: fmt.Errorf("problem loading config: group cannot be higher than number of groups in regexp"), }, { description: "test entropy range limits", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_7.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_7.toml")), }, wantErr: fmt.Errorf("problem loading config: invalid entropy ranges, must be within 0.0-8.0"), }, @@ -200,7 +200,7 @@ func findRuleByDescription(rules []config.Rule, description string) (*config.Rul } func writeTestConfig(toml string) (string, error) { - tmpfile, err := ioutil.TempFile("", "testConfig") + tmpfile, err := ioutil.TempFile(".", "testConfig") if err != nil { return "", fmt.Errorf("Couldn't create test config got: %w", err) } From b8ff5eec73a4c1ccaac702ae930484d5edc777e5 Mon Sep 17 00:00:00 2001 From: "Matthew E. Grahlman" Date: Sun, 10 Oct 2021 16:40:13 -0400 Subject: [PATCH 10/14] Had to re-add testdata/ folder to project in order to get scan tests passing on Windows --- testdata/repos/basic/dotGit/index | Bin 217 -> 217 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/testdata/repos/basic/dotGit/index b/testdata/repos/basic/dotGit/index index 420b9edacff0039f2c2454fbccd2ab6b581c9f42..6099bcd069f778a2f63943e0ef046751e0d6fe42 100644 GIT binary patch delta 116 zcmcb~c$3k<#WTp6fq{VugcFnfb2xI-0}_+A1_Jp=pm7O|Gtod*8KkUxj|NbAhswM{&kED46IDoTy`=rG%jIaVEhVHBQnuI xRoO!Nxccp%yon(CW>y?TS=?q6Wfi_6@xQlPzVLd}z@!yX-tpFP4f9Q99RS6EA_xEg From 7cc3d7e4679bcc2266b840aa7aca26fc7a43b2fa Mon Sep 17 00:00:00 2001 From: "Matthew E. Grahlman" Date: Sun, 10 Oct 2021 17:27:45 -0400 Subject: [PATCH 11/14] Fix for Windows OS --- testdata/repos/basic/dotGit/index | Bin 217 -> 217 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/testdata/repos/basic/dotGit/index b/testdata/repos/basic/dotGit/index index 6099bcd069f778a2f63943e0ef046751e0d6fe42..7f7b84abfb326bf2400ef01acda157137b416370 100644 GIT binary patch delta 37 vcmV+=0NVfA0oehNUItb@Dg7VFkz`>Mws;}i)-|J@w@b5WCH?(8(eos_IujB@ delta 37 tcmcb~c$0BL9GicK%FP6oi7AO9U-Oxqucq?Hm+Eh}>U0ta6iY0Q2LKWW4Z;8b From d2e1e43a25528fae4a6e92fe0cb57eb393959785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Alc=C3=A2ntara?= Date: Wed, 13 Oct 2021 16:41:36 -0300 Subject: [PATCH 12/14] ADD_installation_from_bin ADD_installation_from_bin --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 4f40b6d3..a96faa21 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,16 @@ Go 1.16+ required. ```bash GO111MODULE=on go get github.com/zricethezav/gitleaks/v7 ``` + +##### From bin: +Curl required: +``` #!/bin/bash +GITLEAKS_VERSION=$(curl -s https://api.github.com/repos/zricethezav/gitleaks/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') && wget https://github.com/zricethezav/gitleaks/releases/download/$GITLEAKS_VERSION/gitleaks-linux-amd64 +mv gitleaks-linux-amd64 gitleaks +chmod +x gitleaks +sudo mv gitleaks /usr/local/bin/ +``` + ##### As a pre-commit hook See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions. From 290118cbbe64dc420cce16b1c9f41df41b06d0ee Mon Sep 17 00:00:00 2001 From: Fabian Kirschner Date: Thu, 14 Oct 2021 22:11:46 +0200 Subject: [PATCH 13/14] fix: typo in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4f40b6d3..12c46318 100644 --- a/README.md +++ b/README.md @@ -164,8 +164,8 @@ gitleaks --path=path/to/local/repo/main.go -v --no-git ``` #### Scan unstaged changes: -If you have unstaged changes are are currently at the root of the repo, you can run `gitleaks` with no `--path` or `--repo-url` specified which will run a scan on your uncommitted changes. Or if you want to specify a -path, you can run: +If you have unstaged changes that are currently at the root of the repo, you can run `gitleaks` with no `--path` or `--repo-url` specified which will run a scan on your uncommitted changes. +Or if you want to specify a path, you can run: ```bash gitleaks --path=path/to/local/repo -v --unstaged ``` From 8adf27b1ea6bdf337c63a4e0919853f7951b94e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Alc=C3=A2ntara?= Date: Tue, 19 Oct 2021 09:50:39 -0300 Subject: [PATCH 14/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a96faa21..60a00f38 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,8 @@ GO111MODULE=on go get github.com/zricethezav/gitleaks/v7 ``` ##### From bin: -Curl required: -``` #!/bin/bash + +```bash GITLEAKS_VERSION=$(curl -s https://api.github.com/repos/zricethezav/gitleaks/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') && wget https://github.com/zricethezav/gitleaks/releases/download/$GITLEAKS_VERSION/gitleaks-linux-amd64 mv gitleaks-linux-amd64 gitleaks chmod +x gitleaks