mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Include offenderEntropy in the JSON output (#549)
* Pass the entropy data back to the Leak struct Do this to make it easier to tune entropy checks and make decisions in systems consuming the output. ~ B'ezrat Hashem ~ * Return negative number when entropy not checked That way you can tell the difference between not checking or an actual entropy level of 0 ~ B'ezrat Hashem ~ * Make sure to handle range checks properly Make sure to show when something had an entropy returned but was outside range, or didn't have a hit at all, etc... ~ B'zrat Hashem ~ * Add a few doc strings Follow the project's conventiona add a comment above the methods ~ B'ezrat Hashem ~ * Update tests and get them to pass ~ B'ezrat Hashem ~ * Remove checked in `.got` files ~ B'ezrat Hashem ~ * Add `*.got` to the `.gitignore` Make sure the test output files aren't checked-in ~ B'ezrat Hashem ~
This commit is contained in:
1 parent
e7553b0168
commit
8250e40a75
52 files changed
+240
-50
No files matched your search
+4
-4
@@ -87,7 +87,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
||||
lineNumber++
|
||||
for _, rule := range us.cfg.Rules {
|
||||
offender := rule.Inspect(line)
|
||||
if offender == "" {
|
||||
if offender.IsEmpty() {
|
||||
continue
|
||||
}
|
||||
if us.cfg.Allowlist.RegexAllowed(line) ||
|
||||
@@ -101,7 +101,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
||||
if rule.Path.String() != "" && !rule.HasFilePathLeak(filepath.Base(workTreeFile.Name())) {
|
||||
continue
|
||||
}
|
||||
leak := NewLeak(line, offender, defaultLineNumber).WithCommit(emptyCommit())
|
||||
leak := NewLeak(line, offender.ToString(), defaultLineNumber).WithCommit(emptyCommit()).WithEntropy(offender.EntropyLevel)
|
||||
leak.File = workTreeFile.Name()
|
||||
leak.LineNumber = lineNumber
|
||||
leak.Repo = us.repoName
|
||||
@@ -206,7 +206,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
||||
for _, line := range strings.Split(diffContents, "\n") {
|
||||
for _, rule := range us.cfg.Rules {
|
||||
offender := rule.Inspect(line)
|
||||
if offender == "" {
|
||||
if offender.IsEmpty() {
|
||||
continue
|
||||
}
|
||||
if us.cfg.Allowlist.RegexAllowed(line) ||
|
||||
@@ -220,7 +220,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
||||
if rule.Path.String() != "" && !rule.HasFilePathLeak(filepath.Base(filename)) {
|
||||
continue
|
||||
}
|
||||
leak := NewLeak(line, offender, defaultLineNumber).WithCommit(emptyCommit())
|
||||
leak := NewLeak(line, offender.ToString(), defaultLineNumber).WithCommit(emptyCommit()).WithEntropy(offender.EntropyLevel)
|
||||
leak.File = filename
|
||||
leak.LineNumber = extractLine(prettyDiff, leak, lineLookup) + 1
|
||||
leak.Repo = us.repoName
|
||||
|
||||
Reference in new issue
Block a user