From ace8de93a935703a94e9e54f4989333be403ffe6 Mon Sep 17 00:00:00 2001 From: zach rice Date: Sun, 1 Dec 2019 21:30:40 -0500 Subject: [PATCH] limit leak len to 200 characters --- audit/util.go | 7 +------ manager/manager.go | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/audit/util.go b/audit/util.go index 50e85d5f..3bd72245 100644 --- a/audit/util.go +++ b/audit/util.go @@ -123,12 +123,8 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string for _, line := range strings.Split(content, "\n") { entropyTripped := trippedEntropy(line, rule) if entropyTripped && !ruleContainRegex(rule) { - _line := line - if len(_line) > maxLineLen { - _line = line[0 : maxLineLen-1] - } repo.Manager.SendLeaks(manager.Leak{ - Line: _line, + Line: line, Offender: fmt.Sprintf("Entropy range %+v", rule.Entropy), Commit: c.Hash.String(), Repo: repo.Name, @@ -226,7 +222,6 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string line = strings.ReplaceAll(line, offender, "REDACTED") offender = "REDACTED" } - repo.Manager.SendLeaks(manager.Leak{ Line: line, Offender: offender, diff --git a/manager/manager.go b/manager/manager.go index c4d9baae..af9dcaae 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -22,6 +22,8 @@ import ( "gopkg.in/src-d/go-git.v4" ) +const maxLineLen = 200 + // Manager is a struct containing options and configs as well CloneOptions and CloneDir. // This struct is passed into each NewRepo so we are not passing around the manager in func params. type Manager struct { @@ -111,6 +113,12 @@ func (manager *Manager) GetLeaks() []Leak { // SendLeaks accepts a leak and is used by the audit pkg. This is the public function // that allows other packages to send leaks to the manager. func (manager *Manager) SendLeaks(l Leak) { + if len(l.Line) > maxLineLen { + l.Line = l.Line[0:maxLineLen-1] + "..." + } + if len(l.Offender) > maxLineLen { + l.Offender = l.Offender[0:maxLineLen-1] + "..." + } h := sha1.New() h.Write([]byte(l.Commit + l.Offender + l.File)) l.lookupHash = hex.EncodeToString(h.Sum(nil))