From 94cae90d1eb208410073669de54a21fb65f23742 Mon Sep 17 00:00:00 2001 From: Zachary Rice Date: Wed, 26 Feb 2020 17:38:16 -0500 Subject: [PATCH] duplicate leak logic includes the line in hash (#345) --- audit/util.go | 3 +-- go.mod | 1 + go.sum | 2 ++ manager/manager.go | 2 +- test_data/test_local_owner_aws_leak.json | 13 +++++++++++++ test_data/test_local_repo_three_leaks.json | 13 +++++++++++++ test_data/test_local_repo_two_leaks.json | 13 +++++++++++++ .../test_local_repo_two_leaks_commit_from.json | 13 +++++++++++++ .../test_local_repo_two_leaks_commit_range.json | 13 +++++++++++++ 9 files changed, 70 insertions(+), 3 deletions(-) diff --git a/audit/util.go b/audit/util.go index 05e39736..27654ca7 100644 --- a/audit/util.go +++ b/audit/util.go @@ -98,7 +98,6 @@ func shannonEntropy(data string) (entropy float64) { return entropy } - // Checks if the given rule has a regex func ruleContainRegex(rule config.Rule) bool { if rule.Regex == nil { @@ -189,7 +188,7 @@ func InspectFile(content string, fullpath string, c *object.Commit, repo *Repo) if isFileNameWhiteListed(filename, rule.Whitelist) || isFilePathWhiteListed(path, rule.Whitelist) { continue } - + // If it has fileNameRegex and it doesnt match we continue to next rule if ruleContainFileNameRegex(rule) && !fileMatched(filename, rule.FileNameRegex) { continue diff --git a/go.mod b/go.mod index d523190f..91a37a14 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/sergi/go-diff v1.0.0 github.com/sirupsen/logrus v1.4.2 github.com/xanzy/go-gitlab v0.21.0 + golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 gopkg.in/src-d/go-billy.v4 v4.3.2 gopkg.in/src-d/go-git.v4 v4.13.1 diff --git a/go.sum b/go.sum index 9e1039e0..8c05702b 100644 --- a/go.sum +++ b/go.sum @@ -76,6 +76,8 @@ golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/manager/manager.go b/manager/manager.go index a7a100ab..2bc06742 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -156,7 +156,7 @@ func (manager *Manager) SendLeaks(l Leak) { l.Offender = l.Offender[0:maxLineLen-1] + "..." } h := sha1.New() - h.Write([]byte(l.Commit + l.Offender + l.File)) + h.Write([]byte(l.Commit + l.Offender + l.File + l.Line)) l.lookupHash = hex.EncodeToString(h.Sum(nil)) manager.leakWG.Add(1) manager.leakChan <- l diff --git a/test_data/test_local_owner_aws_leak.json b/test_data/test_local_owner_aws_leak.json index 7b06075c..31de4489 100644 --- a/test_data/test_local_owner_aws_leak.json +++ b/test_data/test_local_owner_aws_leak.json @@ -116,6 +116,19 @@ "date": "2019-10-25T13:01:27-04:00", "tags": "key, API, generic" }, + { + "line": "Here's an AWS secret: AKIALALEMEL33243OLIAE", + "offender": "AKIALALEMEL33243OLIA", + "commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c", + "repo": "test_repo_2", + "rule": "AWS Manager ID", + "commitMessage": "wait this is actually adding an aws secret\n", + "author": "zach rice", + "email": "zricer@protonmail.com", + "file": "secrets.md", + "date": "2019-10-25T13:01:27-04:00", + "tags": "key, AWS" + }, { "line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE", "offender": "AKIALALEMEL33243OLIA", diff --git a/test_data/test_local_repo_three_leaks.json b/test_data/test_local_repo_three_leaks.json index a06f1d40..024003a4 100644 --- a/test_data/test_local_repo_three_leaks.json +++ b/test_data/test_local_repo_three_leaks.json @@ -77,6 +77,19 @@ "date": "2019-10-25T13:01:27-04:00", "tags": "key, AWS" }, + { + "line": "Here's an AWS secret: AKIALALEMEL33243OLIAE", + "offender": "AKIALALEMEL33243OLIA", + "commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c", + "repo": "test_repo_3", + "rule": "AWS Manager ID", + "commitMessage": "wait this is actually adding an aws secret\n", + "author": "zach rice", + "email": "zricer@protonmail.com", + "file": "secrets.md", + "date": "2019-10-25T13:01:27-04:00", + "tags": "key, AWS" + }, { "line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE", "offender": "AKIALALEMEL33243OLIA", diff --git a/test_data/test_local_repo_two_leaks.json b/test_data/test_local_repo_two_leaks.json index 53e0af16..187e7afb 100644 --- a/test_data/test_local_repo_two_leaks.json +++ b/test_data/test_local_repo_two_leaks.json @@ -103,6 +103,19 @@ "date": "2019-10-25T13:01:27-04:00", "tags": "key, API, generic" }, + { + "line": "Here's an AWS secret: AKIALALEMEL33243OLIAE", + "offender": "AKIALALEMEL33243OLIA", + "commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c", + "repo": "test_repo_2", + "rule": "AWS Manager ID", + "commitMessage": "wait this is actually adding an aws secret\n", + "author": "zach rice", + "email": "zricer@protonmail.com", + "file": "secrets.md", + "date": "2019-10-25T13:01:27-04:00", + "tags": "key, AWS" + }, { "line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE", "offender": "AKIALALEMEL33243OLIA", diff --git a/test_data/test_local_repo_two_leaks_commit_from.json b/test_data/test_local_repo_two_leaks_commit_from.json index 5be94d46..ea3286e9 100644 --- a/test_data/test_local_repo_two_leaks_commit_from.json +++ b/test_data/test_local_repo_two_leaks_commit_from.json @@ -51,6 +51,19 @@ "date": "2019-10-25T13:01:27-04:00", "tags": "key, API, generic" }, + { + "line": "Here's an AWS secret: AKIALALEMEL33243OLIAE", + "offender": "AKIALALEMEL33243OLIA", + "commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c", + "repo": "test_repo_2", + "rule": "AWS Manager ID", + "commitMessage": "wait this is actually adding an aws secret\n", + "author": "zach rice", + "email": "zricer@protonmail.com", + "file": "secrets.md", + "date": "2019-10-25T13:01:27-04:00", + "tags": "key, AWS" + }, { "line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE", "offender": "AKIALALEMEL33243OLIA", diff --git a/test_data/test_local_repo_two_leaks_commit_range.json b/test_data/test_local_repo_two_leaks_commit_range.json index 4d75cdcc..34d7b366 100644 --- a/test_data/test_local_repo_two_leaks_commit_range.json +++ b/test_data/test_local_repo_two_leaks_commit_range.json @@ -50,5 +50,18 @@ "file": "secrets.md", "date": "2019-10-25T13:01:27-04:00", "tags": "key, API, generic" + }, + { + "line": "Here's an AWS secret: AKIALALEMEL33243OLIAE", + "offender": "AKIALALEMEL33243OLIA", + "commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c", + "repo": "test_repo_2", + "rule": "AWS Manager ID", + "commitMessage": "wait this is actually adding an aws secret\n", + "author": "zach rice", + "email": "zricer@protonmail.com", + "file": "secrets.md", + "date": "2019-10-25T13:01:27-04:00", + "tags": "key, AWS" } ]