Merge pull request #305 from zricethezav/limit-leak-len

Limit leak len
This commit is contained in:
Zachary Rice authored and GitHub committed 2019-12-04 14:46:36 -05:00
commit 7c5594c39d
3 files changed
+11 -8

No files matched your search

+1 -6
View File
@@ -123,12 +123,8 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
for _, line := range strings.Split(content, "\n") { for _, line := range strings.Split(content, "\n") {
entropyTripped := trippedEntropy(line, rule) entropyTripped := trippedEntropy(line, rule)
if entropyTripped && !ruleContainRegex(rule) { if entropyTripped && !ruleContainRegex(rule) {
_line := line
if len(_line) > maxLineLen {
_line = line[0 : maxLineLen-1]
}
repo.Manager.SendLeaks(manager.Leak{ repo.Manager.SendLeaks(manager.Leak{
Line: _line, Line: line,
Offender: fmt.Sprintf("Entropy range %+v", rule.Entropy), Offender: fmt.Sprintf("Entropy range %+v", rule.Entropy),
Commit: c.Hash.String(), Commit: c.Hash.String(),
Repo: repo.Name, Repo: repo.Name,
@@ -226,7 +222,6 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
line = strings.ReplaceAll(line, offender, "REDACTED") line = strings.ReplaceAll(line, offender, "REDACTED")
offender = "REDACTED" offender = "REDACTED"
} }
repo.Manager.SendLeaks(manager.Leak{ repo.Manager.SendLeaks(manager.Leak{
Line: line, Line: line,
Offender: offender, Offender: offender,
+8
View File
@@ -22,6 +22,8 @@ import (
"gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4"
) )
const maxLineLen = 200
// Manager is a struct containing options and configs as well CloneOptions and CloneDir. // 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. // This struct is passed into each NewRepo so we are not passing around the manager in func params.
type Manager struct { 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 // 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. // that allows other packages to send leaks to the manager.
func (manager *Manager) SendLeaks(l Leak) { 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 := sha1.New()
h.Write([]byte(l.Commit + l.Offender + l.File)) h.Write([]byte(l.Commit + l.Offender + l.File))
l.lookupHash = hex.EncodeToString(h.Sum(nil)) l.lookupHash = hex.EncodeToString(h.Sum(nil))
@@ -1,6 +1,6 @@
[ [
{ {
"line": " Just moments after the Cessna's inquiry, a Twin Beech piped up on frequency, in a rather superior tone, asking for his ground speed. \"I have you at one hundred and twenty-five knots of ground spe", "line": " Just moments after the Cessna's inquiry, a Twin Beech piped up on frequency, in a rather superior tone, asking for his ground speed. \"I have you at one hundred and twenty-five knots of ground spe...",
"offender": "Entropy range [{P1:4.5 P2:4.7}]", "offender": "Entropy range [{P1:4.5 P2:4.7}]",
"commit": "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a", "commit": "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a",
"repo": "test_repo_4", "repo": "test_repo_4",
@@ -13,7 +13,7 @@
"tags": "entropy" "tags": "entropy"
}, },
{ {
"line": " Just moments after the Cessna's inquiry, a Twin Beech piped up on frequency, in a rather superior tone, asking for his ground speed. \"I have you at one hundred and twenty-five knots of ground spe", "line": " Just moments after the Cessna's inquiry, a Twin Beech piped up on frequency, in a rather superior tone, asking for his ground speed. \"I have you at one hundred and twenty-five knots of ground spe...",
"offender": "Entropy range [{P1:4.5 P2:4.7}]", "offender": "Entropy range [{P1:4.5 P2:4.7}]",
"commit": "996865bb912f3bc45898a370a13aadb315014b55", "commit": "996865bb912f3bc45898a370a13aadb315014b55",
"repo": "test_repo_4", "repo": "test_repo_4",