mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
[update] seems to be working with concurrency upgrades... do some timing
This commit is contained in:
1 parent
06b3a9b4e7
commit
61c4987cd2
2 files changed
+109
-53
No files matched your search
@@ -3,38 +3,47 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/nbutton23/zxcvbn-go"
|
"github.com/nbutton23/zxcvbn-go"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// checkDiff operates on a single diff between to chronological commits
|
// checkDiff operates on a single diff between to chronological commits
|
||||||
func checkDiff(commit1 string, commit2 string) []string {
|
func checkDiff(commit1 string, commit2 string, repoName string) []string {
|
||||||
var leakPrs bool
|
// var leakPrs bool
|
||||||
var leaks []string
|
// var leaks []string
|
||||||
_, seen := cache[commit1+commit2]
|
// _, seen := cache[commit1+commit2]
|
||||||
if seen {
|
// if seen {
|
||||||
fmt.Println("WE HAVE SEEN THIS")
|
// fmt.Println("WE HAVE SEEN THIS")
|
||||||
return []string{}
|
// return []string{}
|
||||||
|
// }
|
||||||
|
|
||||||
|
if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repoName)); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := exec.Command("git", "diff", commit1, commit2).Output()
|
cmd := exec.Command("git", "diff", commit1, commit2)
|
||||||
|
_, err := cmd.Output()
|
||||||
|
// fmt.Println(string(out))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
return []string{}
|
||||||
|
|
||||||
cache[commit1+commit2] = true
|
// cache[commit1+commit2] = true
|
||||||
lines := checkRegex(string(out))
|
// lines := checkRegex(string(out))
|
||||||
if len(lines) == 0 {
|
// if len(lines) == 0 {
|
||||||
return []string{}
|
// return []string{}
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for _, line := range lines {
|
// for _, line := range lines {
|
||||||
leakPrs = checkEntropy(line)
|
// leakPrs = checkEntropy(line)
|
||||||
if leakPrs {
|
// if leakPrs {
|
||||||
leaks = append(leaks, line)
|
// leaks = append(leaks, line)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return leaks
|
// return leaks
|
||||||
}
|
}
|
||||||
|
|
||||||
// check each line of a diff and see if there are any potential secrets
|
// check each line of a diff and see if there are any potential secrets
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ type Repo struct {
|
|||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MemoMessage struct {
|
||||||
|
hash string
|
||||||
|
leaks []string
|
||||||
|
commitA string
|
||||||
|
commitB string
|
||||||
|
branch string
|
||||||
|
}
|
||||||
|
|
||||||
|
var lock = sync.RWMutex{}
|
||||||
|
|
||||||
func repoStart(repoUrl string) {
|
func repoStart(repoUrl string) {
|
||||||
err := exec.Command("git", "clone", repoUrl).Run()
|
err := exec.Command("git", "clone", repoUrl).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -61,8 +71,10 @@ func (repo Repo) audit() []ReportElem {
|
|||||||
err error
|
err error
|
||||||
branch string
|
branch string
|
||||||
commits [][]byte
|
commits [][]byte
|
||||||
leaks []string
|
// leaks []string
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
commitA string
|
||||||
|
commitB string
|
||||||
)
|
)
|
||||||
|
|
||||||
out, err = exec.Command("git", "branch", "--all").Output()
|
out, err = exec.Command("git", "branch", "--all").Output()
|
||||||
@@ -73,53 +85,88 @@ func (repo Repo) audit() []ReportElem {
|
|||||||
// iterate through branches, git rev-list <branch>
|
// iterate through branches, git rev-list <branch>
|
||||||
branches := bytes.Split(out, []byte("\n"))
|
branches := bytes.Split(out, []byte("\n"))
|
||||||
|
|
||||||
// TODO instead of making branches concurrent use commits
|
messages := make(chan MemoMessage)
|
||||||
// make the wait group update the cache. Use channel to communicate
|
|
||||||
// cache misses and leaks
|
|
||||||
messages := make(chan string)
|
|
||||||
wg.Add(len(branches) - 3)
|
|
||||||
|
|
||||||
for i, branchB := range branches {
|
for i, branchB := range branches {
|
||||||
if i < 2 || i == len(branches)-1 {
|
if i < 2 || i == len(branches)-1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
branch = string(bytes.Trim(branchB, " "))
|
branch = string(bytes.Trim(branchB, " "))
|
||||||
go func(branch string) {
|
cmd := exec.Command("git", "rev-list", branch)
|
||||||
defer wg.Done()
|
|
||||||
cmd := exec.Command("git", "rev-list", branch)
|
|
||||||
|
|
||||||
if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repo.name)); err != nil {
|
out, err := cmd.Output()
|
||||||
log.Fatal(err)
|
if err != nil {
|
||||||
}
|
fmt.Println("skipping branch", branch)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
out, err := cmd.Output()
|
// iterate through commits
|
||||||
if err != nil {
|
commits = bytes.Split(out, []byte("\n"))
|
||||||
log.Fatal(err)
|
wg.Add(len(commits) - 2)
|
||||||
|
for j, currCommit := range commits {
|
||||||
|
if j == len(commits)-2 {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
// iterate through commits
|
commitA = string(commits[j+1])
|
||||||
commits = bytes.Split(out, []byte("\n"))
|
commitB = string(currCommit)
|
||||||
for j, commitB := range commits {
|
|
||||||
// fmt.Println(branch, string(commitB), j)
|
go func(commitA string, commitB string,
|
||||||
if j == len(commits)-2 {
|
j int) {
|
||||||
break
|
defer wg.Done()
|
||||||
|
var leakPrs bool
|
||||||
|
var leaks []string
|
||||||
|
fmt.Println(j, branch)
|
||||||
|
|
||||||
|
lock.RLock()
|
||||||
|
_, seen := cache[commitA+commitB]
|
||||||
|
lock.RUnlock()
|
||||||
|
if seen {
|
||||||
|
fmt.Println("WE HAVE SEEN THIS")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repo.name)); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
cmd := exec.Command("git", "diff", commitA, commitB)
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lines := checkRegex(string(out))
|
||||||
|
if len(lines) == 0 {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
leaks = checkDiff(string(commitB), string(commits[j+1]))
|
for _, line := range lines {
|
||||||
if len(leaks) != 0 {
|
leakPrs = checkEntropy(line)
|
||||||
report = append(report, ReportElem{leaks, branch,
|
if leakPrs {
|
||||||
string(commitB), string(commits[j+1])})
|
leaks = append(leaks, line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
messages <- branch
|
// if len(leaks) != 0 {
|
||||||
}(branch)
|
// report = append(report, ReportElem{leaks, branch,
|
||||||
|
// string(commitB), string(commits[j+1])})
|
||||||
|
// }
|
||||||
|
messages <- MemoMessage{commitA + commitB, leaks, commitA, commitB, branch}
|
||||||
|
|
||||||
|
}(commitA, commitB, j)
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for i := range messages {
|
for memoMsg := range messages {
|
||||||
fmt.Println(i)
|
fmt.Println(memoMsg)
|
||||||
|
lock.Lock()
|
||||||
|
cache[memoMsg.hash] = true
|
||||||
|
lock.Unlock()
|
||||||
|
if len(memoMsg.leaks) != 0 {
|
||||||
|
report = append(report, ReportElem{memoMsg.leaks, memoMsg.branch,
|
||||||
|
memoMsg.commitA, memoMsg.commitB})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
return report
|
return report
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user