Compare commits

...
9 Commits
Author SHA1 Message Date
Zachary RiceandZach Rice 58d130c5f3 Quiet flag (#491)
* Adding a quiet option

* better description

Co-authored-by: Zach Rice <zrice@gitlab.com>
2020-12-11 09:56:09 -05:00
Zachary Rice 091ea81e68 nosec gosec (#490) 2020-12-10 22:32:32 -05:00
Zachary Rice f036dce6ab Dotgit bug (#488)
* fix allowlist bug

* Adding new repo for testing allowlisting

* adding additional constraints on the dotgit regex
2020-12-10 17:41:26 -05:00
Zachary Rice 2d58f1f94e Files at commit allow list bug (#485)
* fix allowlist bug

* Adding new repo for testing allowlisting

* Adding missing allowlist checks for commits and files/paths
2020-12-09 15:55:01 -05:00
Zachary Rice 86cfe0848b Allow list bugs (#484)
* fix allowlist bug
2020-12-09 13:21:15 -05:00
Zachary Rice 973d74e592 Update README.md 2020-12-08 20:55:53 -05:00
Zachary Rice 3909ebe03b Exit code update, introduce leaks-exit-code flag (#481) 2020-12-08 17:41:02 -05:00
Zachary Rice 65f42020af Go repo scan (#480)
* Real fast

* Addressing some golint stuff
2020-12-08 17:22:28 -05:00
Zachary Rice 65a91ae976 Removing base scanner (#477) 2020-12-08 09:24:38 -05:00
54 changed files with 794 additions and 397 deletions

No files matched your search

+7
View File
@@ -59,6 +59,7 @@ Application Options:
--branch= Branch to scan
--redact Redact secrets from log messages and leaks
--debug Log debug messages
--leaks-exit-code= Exit code when leaks have been encountered (default: 1)
--no-git Treat git repos as plain directories and scan those
files
-o, --report= Report output path
@@ -238,6 +239,12 @@ So you can use the following to effectively create the proper Perl regex:
### Exit Codes
You can always set the exit code when leaves are encountered with the `--leaks-exit-code` flag. Default exit codes below:
```
0 - no leaks present
1 - leaks or error encountered
```
### Sponsors ❤️
#### Corporate Sponsors
+6 -2
View File
@@ -4,6 +4,10 @@ import (
"regexp"
)
// used for ignoring .git directories when the --no-git flag is set
// related issue: https://github.com/zricethezav/gitleaks/issues/486
const dotGit = `\.git/`
// AllowList is struct containing items that if encountered will allowlist
// a commit/line of code that would be considered a leak.
type AllowList struct {
@@ -45,9 +49,9 @@ func (a *AllowList) RepoAllowed(repo string) bool {
return anyRegexMatch(repo, a.Repos)
}
// IgnoreDotGit appends a `.git$` rule to ignore all .git paths. This is used for --no-git scans
// IgnoreDotGit appends a `\.git` rule to ignore all .git paths. This is used for --no-git scans
func (a *AllowList) IgnoreDotGit() error {
re, err := regexp.Compile(".git$")
re, err := regexp.Compile(dotGit)
if err != nil {
return err
}
+1 -1
View File
@@ -159,6 +159,6 @@ title = "gitleaks config"
[allowlist]
description = "Allowlisted files"
files = ['''^\.?gitleaks.toml$''',
'''(.*?)(jpg|gif|doc|pdf|bin)$''',
'''(.*?)(png|jpg|gif|doc|docx|pdf|bin|xls|pyc|zip)$''',
'''(go.mod|go.sum)$''']
`
+3
View File
@@ -79,6 +79,9 @@ func (r *Rule) HasFileOrPathLeakOnly(filePath string) bool {
if len(r.Entropies) != 0 {
return false
}
if r.AllowList.FileAllowed(filepath.Base(filePath)) || r.AllowList.PathAllowed(filePath) {
return false
}
return r.HasFileLeak(filepath.Base(filePath)) || r.HasFilePathLeak(filePath)
}
+2
View File
@@ -2,6 +2,8 @@ module github.com/zricethezav/gitleaks/v7
go 1.15
replace github.com/go-git/go-git/v5 => github.com/zricethezav/go-git/v5 v5.2.2
require (
github.com/BurntSushi/toml v0.3.1
github.com/go-git/go-git/v5 v5.2.0
+6
View File
@@ -66,6 +66,10 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/zricethezav/go-git/v5 v5.2.1 h1:snaoKv8ksDSz7NfBRXsBr9Yr8IKEKWRWf1zdhFmcFvI=
github.com/zricethezav/go-git/v5 v5.2.1/go.mod h1:kh02eMX+wdqqxgNMEyq8YgwlIOsDOa9homkUq1PoTMs=
github.com/zricethezav/go-git/v5 v5.2.2 h1:VOVijF5OpIiHvFZXX94AJezdJ0b0kTyRyVNZ4yaqCRU=
github.com/zricethezav/go-git/v5 v5.2.2/go.mod h1:kh02eMX+wdqqxgNMEyq8YgwlIOsDOa9homkUq1PoTMs=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
@@ -78,6 +82,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -88,6 +93,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+4
View File
@@ -61,6 +61,10 @@ func main() {
log.Error(err)
os.Exit(1)
}
if len(scannerReport.Leaks) != 0 {
os.Exit(opts.CodeOnLeak)
}
}
func listenForInterrupt(stopScan chan os.Signal) {
+5
View File
@@ -21,6 +21,7 @@ import (
// Options stores values of command line options
type Options struct {
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from scan"`
Quiet bool `short:"q" long:"quiet" description:"Sets log level to error and only output leaks, one json object per line"`
RepoURL string `short:"r" long:"repo-url" description:"Repository URL"`
Path string `short:"p" long:"path" description:"Path to directory (repo if contains .git) or file"`
ConfigPath string `short:"c" long:"config-path" description:"Path to config"`
@@ -37,6 +38,7 @@ type Options struct {
Redact bool `long:"redact" description:"Redact secrets from log messages and leaks"`
Debug bool `long:"debug" description:"Log debug messages"`
NoGit bool `long:"no-git" description:"Treat git repos as plain directories and scan those files"`
CodeOnLeak int `long:"leaks-exit-code" default:"1" description:"Exit code when leaks have been encountered"`
// Report Options
Report string `short:"o" long:"report" description:"Report output path"`
@@ -82,6 +84,9 @@ func ParseOptions() (Options, error) {
if opts.Debug {
log.SetLevel(log.DebugLevel)
}
if opts.Quiet {
log.SetLevel(log.ErrorLevel)
}
return opts, nil
}
+43 -41
View File
@@ -5,6 +5,9 @@ import (
"path/filepath"
"strings"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/go-git/go-git/v5"
fdiff "github.com/go-git/go-git/v5/plumbing/format/diff"
"github.com/go-git/go-git/v5/plumbing/object"
@@ -12,22 +15,22 @@ import (
// CommitScanner is a commit scanner
type CommitScanner struct {
BaseScanner
cfg config.Config
opts options.Options
repo *git.Repository
repoName string
commit *object.Commit
patch *object.Patch
}
// NewCommitScanner creates and returns a commit scanner
func NewCommitScanner(base BaseScanner, repo *git.Repository, commit *object.Commit) *CommitScanner {
func NewCommitScanner(opts options.Options, cfg config.Config, repo *git.Repository, commit *object.Commit) *CommitScanner {
cs := &CommitScanner{
BaseScanner: base,
repo: repo,
commit: commit,
repoName: getRepoName(base.opts),
cfg: cfg,
opts: opts,
repo: repo,
commit: commit,
repoName: getRepoName(opts),
}
cs.scannerType = typeCommitScanner
return cs
}
@@ -36,39 +39,36 @@ func (cs *CommitScanner) SetRepoName(repoName string) {
cs.repoName = repoName
}
// SetPatch sets the patch to be inspected by the commit scanner. This is used to avoid
// a race condition when running a threaded repo scan
func (cs *CommitScanner) SetPatch(patch *object.Patch) {
cs.patch = patch
}
// Scan kicks off a CommitScanner Scan
func (cs *CommitScanner) Scan() (Report, error) {
var scannerReport Report
if cs.cfg.Allowlist.CommitAllowed(cs.commit.Hash.String()) {
return scannerReport, nil
}
if len(cs.commit.ParentHashes) == 0 {
facScanner := NewFilesAtCommitScanner(cs.BaseScanner, cs.repo, cs.commit)
facScanner := NewFilesAtCommitScanner(cs.opts, cs.cfg, cs.repo, cs.commit)
return facScanner.Scan()
}
if cs.patch == nil {
parent, err := cs.commit.Parent(0)
if err != nil {
return scannerReport, err
}
if parent == nil {
return scannerReport, nil
}
cs.patch, err = parent.Patch(cs.commit)
if err != nil {
return scannerReport, fmt.Errorf("could not generate Patch")
}
parent, err := cs.commit.Parent(0)
if err != nil {
return scannerReport, err
}
patchContent := cs.patch.String()
if parent == nil {
return scannerReport, nil
}
for _, f := range cs.patch.FilePatches() {
patch, err := parent.Patch(cs.commit)
if err != nil {
return scannerReport, fmt.Errorf("could not generate Patch")
}
patchContent := patch.String()
for _, f := range patch.FilePatches() {
if f.IsBinary() {
continue
}
@@ -95,9 +95,8 @@ func (cs *CommitScanner) Scan() (Report, error) {
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if cs.opts.Verbose {
leak.Log(cs.opts.Redact)
}
leak.Log(cs.opts)
scannerReport.Leaks = append(scannerReport.Leaks, leak)
continue
}
@@ -108,14 +107,17 @@ func (cs *CommitScanner) Scan() (Report, error) {
// Check the actual content
for _, line := range strings.Split(chunk.Content(), "\n") {
for _, rule := range cs.cfg.Rules {
if rule.AllowList.FileAllowed(filepath.Base(to.Path())) ||
rule.AllowList.PathAllowed(to.Path()) ||
rule.AllowList.CommitAllowed(cs.commit.Hash.String()) {
continue
}
offender := rule.Inspect(line)
if offender == "" {
continue
}
if cs.cfg.Allowlist.RegexAllowed(line) ||
rule.AllowList.FileAllowed(filepath.Base(to.Path())) ||
rule.AllowList.PathAllowed(to.Path()) ||
rule.AllowList.CommitAllowed(cs.commit.Hash.String()) {
if cs.cfg.Allowlist.RegexAllowed(line) {
continue
}
@@ -134,9 +136,9 @@ func (cs *CommitScanner) Scan() (Report, error) {
leak.LeakURL = leak.URL()
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if cs.opts.Verbose {
leak.Log(cs.opts.Redact)
}
leak.Log(cs.opts)
scannerReport.Leaks = append(scannerReport.Leaks, leak)
}
}
+11 -7
View File
@@ -2,11 +2,14 @@ package scan
import (
"github.com/go-git/go-git/v5"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
)
// CommitsScanner is a commit scanner
type CommitsScanner struct {
BaseScanner
opts options.Options
cfg config.Config
repo *git.Repository
repoName string
@@ -14,12 +17,13 @@ type CommitsScanner struct {
}
// NewCommitsScanner creates and returns a commits scanner, notice the 's' in commits
func NewCommitsScanner(base BaseScanner, repo *git.Repository, commits []string) *CommitsScanner {
func NewCommitsScanner(opts options.Options, cfg config.Config, repo *git.Repository, commits []string) *CommitsScanner {
return &CommitsScanner{
BaseScanner: base,
repo: repo,
commits: commits,
repoName: getRepoName(base.opts),
opts: opts,
cfg: cfg,
repo: repo,
commits: commits,
repoName: getRepoName(opts),
}
}
@@ -31,7 +35,7 @@ func (css *CommitsScanner) Scan() (Report, error) {
if err != nil {
return scannerReport, nil
}
cs := NewCommitScanner(css.BaseScanner, css.repo, c)
cs := NewCommitScanner(css.opts, css.cfg, css.repo, c)
commitReport, err := cs.Scan()
if err != nil {
return scannerReport, err
+34 -18
View File
@@ -4,6 +4,9 @@ import (
"path/filepath"
"strings"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
)
@@ -13,28 +16,33 @@ import (
// files available at a commit's worktree and scans the entire content of said files.
// Apologies for the awful struct name...
type FilesAtCommitScanner struct {
BaseScanner
opts options.Options
cfg config.Config
repo *git.Repository
commit *object.Commit
repoName string
}
// NewFilesAtCommitScanner creates and returns a files at commit scanner
func NewFilesAtCommitScanner(base BaseScanner, repo *git.Repository, commit *object.Commit) *FilesAtCommitScanner {
func NewFilesAtCommitScanner(opts options.Options, cfg config.Config, repo *git.Repository, commit *object.Commit) *FilesAtCommitScanner {
fs := &FilesAtCommitScanner{
BaseScanner: base,
repo: repo,
commit: commit,
repoName: getRepoName(base.opts),
opts: opts,
cfg: cfg,
repo: repo,
commit: commit,
repoName: getRepoName(opts),
}
fs.scannerType = typeFilesAtCommitScanner
return fs
}
// Scan kicks off a FilesAtCommitScanner Scan
func (fs *FilesAtCommitScanner) Scan() (Report, error) {
var scannerReport Report
if fs.cfg.Allowlist.CommitAllowed(fs.commit.Hash.String()) {
return scannerReport, nil
}
fIter, err := fs.commit.Files()
if err != nil {
return scannerReport, err
@@ -48,6 +56,11 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
return err
}
if fs.cfg.Allowlist.FileAllowed(filepath.Base(f.Name)) ||
fs.cfg.Allowlist.PathAllowed(f.Name) {
return nil
}
content, err := f.Contents()
if err != nil {
return err
@@ -68,9 +81,8 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if fs.opts.Verbose {
leak.Log(fs.opts.Redact)
}
leak.Log(fs.opts)
scannerReport.Leaks = append(scannerReport.Leaks, leak)
continue
}
@@ -78,15 +90,19 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
for i, line := range strings.Split(content, "\n") {
for _, rule := range fs.cfg.Rules {
if rule.AllowList.FileAllowed(filepath.Base(f.Name)) ||
rule.AllowList.PathAllowed(f.Name) ||
rule.AllowList.CommitAllowed(fs.commit.Hash.String()) {
continue
}
offender := rule.Inspect(line)
if offender == "" {
continue
}
if fs.cfg.Allowlist.RegexAllowed(line) ||
rule.AllowList.FileAllowed(filepath.Base(f.Name)) ||
rule.AllowList.PathAllowed(f.Name) ||
rule.AllowList.CommitAllowed(fs.commit.Hash.String()) {
if fs.cfg.Allowlist.RegexAllowed(line) {
continue
}
@@ -105,9 +121,9 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
leak.LeakURL = leak.URL()
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if fs.opts.Verbose {
leak.Log(fs.opts.Redact)
}
leak.Log(fs.opts)
scannerReport.Leaks = append(scannerReport.Leaks, leak)
}
}
+16 -5
View File
@@ -6,6 +6,8 @@ import (
"strings"
"time"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/go-git/go-git/v5/plumbing/object"
)
@@ -56,13 +58,22 @@ func (leak Leak) WithCommit(commit *object.Commit) Leak {
}
// Log logs a leak and redacts if necessary
func (leak Leak) Log(redact bool) {
if redact {
func (leak Leak) Log(opts options.Options) {
if !opts.Quiet && !opts.Verbose {
return
}
if opts.Redact {
leak = RedactLeak(leak)
}
var b []byte
b, _ = json.MarshalIndent(leak, "", " ")
fmt.Println(string(b))
if opts.Quiet {
var b []byte
b, _ = json.Marshal(leak)
fmt.Println(string(b))
} else {
var b []byte
b, _ = json.MarshalIndent(leak, "", " ")
fmt.Println(string(b))
}
}
// URL generates a url to the leak if leak.RepoURL is set
+24 -17
View File
@@ -9,22 +9,25 @@ import (
log "github.com/sirupsen/logrus"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"golang.org/x/sync/errgroup"
)
// NoGitScanner is a scanner that absolutely despises git
type NoGitScanner struct {
BaseScanner
opts options.Options
cfg config.Config
}
// NewNoGitScanner creates and returns a nogit scanner. This is used for scanning files and directories
func NewNoGitScanner(base BaseScanner) *NoGitScanner {
func NewNoGitScanner(opts options.Options, cfg config.Config) *NoGitScanner {
ngs := &NoGitScanner{
BaseScanner: base,
opts: opts,
cfg: cfg,
}
ngs.scannerType = typeNoGitScanner
// no-git scans should ignore .git folders by default
// issue: https://github.com/zricethezav/gitleaks/issues/474
// ngs.cfg.Allowlist
@@ -33,7 +36,6 @@ func NewNoGitScanner(base BaseScanner) *NoGitScanner {
log.Error(err)
return nil
}
return ngs
}
@@ -75,14 +77,13 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if ngs.opts.Verbose {
leak.Log(ngs.opts.Redact)
}
leak.Log(ngs.opts)
leaks <- leak
}
}
f, err := os.Open(p)
f, err := os.Open(p) // #nosec
if err != nil {
return err
}
@@ -92,13 +93,17 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
lineNumber++
for _, rule := range ngs.cfg.Rules {
line := scanner.Text()
if rule.AllowList.FileAllowed(filepath.Base(p)) ||
rule.AllowList.PathAllowed(p) {
continue
}
offender := rule.Inspect(line)
if offender == "" {
continue
}
if ngs.cfg.Allowlist.RegexAllowed(line) ||
rule.AllowList.FileAllowed(filepath.Base(p)) ||
rule.AllowList.PathAllowed(p) {
if ngs.cfg.Allowlist.RegexAllowed(line) {
continue
}
@@ -114,9 +119,9 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
leak.LineNumber = lineNumber
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if ngs.opts.Verbose {
leak.Log(ngs.opts.Redact)
}
leak.Log(ngs.opts)
leaks <- leak
}
}
@@ -125,7 +130,9 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
}
go func() {
g.Wait()
if err := g.Wait(); err != nil {
log.Error(err)
}
close(leaks)
}()
+9 -6
View File
@@ -4,6 +4,8 @@ import (
"io/ioutil"
"path/filepath"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/go-git/go-git/v5"
@@ -12,15 +14,16 @@ import (
// ParentScanner is a parent directory scanner
type ParentScanner struct {
BaseScanner
cfg config.Config
opts options.Options
}
// NewParentScanner creates and returns a directory scanner
func NewParentScanner(base BaseScanner) *ParentScanner {
func NewParentScanner(opts options.Options, cfg config.Config) *ParentScanner {
ds := &ParentScanner{
BaseScanner: base,
opts: opts,
cfg: cfg,
}
ds.scannerType = typeDirScanner
return ds
}
@@ -55,11 +58,11 @@ func (ds *ParentScanner) Scan() (Report, error) {
if err != nil {
log.Warn(err)
} else {
ds.BaseScanner.cfg = cfg
ds.cfg = cfg
}
}
rs := NewRepoScanner(ds.BaseScanner, repo)
rs := NewRepoScanner(ds.opts, ds.cfg, repo)
rs.repoName = f.Name()
repoReport, err := rs.Scan()
if err != nil {
+68 -82
View File
@@ -1,50 +1,48 @@
package scan
import (
"fmt"
"sync"
"context"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
log "github.com/sirupsen/logrus"
)
// RepoScanner is a repo scanner
type RepoScanner struct {
BaseScanner
opts options.Options
cfg config.Config
repo *git.Repository
throttle *Throttle
repoName string
leakChan chan Leak
leakWG *sync.WaitGroup
leakCache map[string]bool
leaks []Leak
}
// NewRepoScanner returns a new repo scanner (go figure). This function also
// sets up the leak listener for multi-threaded awesomeness.
func NewRepoScanner(base BaseScanner, repo *git.Repository) *RepoScanner {
func NewRepoScanner(opts options.Options, cfg config.Config, repo *git.Repository) *RepoScanner {
rs := &RepoScanner{
BaseScanner: base,
repo: repo,
leakChan: make(chan Leak),
leakWG: &sync.WaitGroup{},
leakCache: make(map[string]bool),
repoName: getRepoName(base.opts),
opts: opts,
cfg: cfg,
repo: repo,
throttle: NewThrottle(opts),
repoName: getRepoName(opts),
}
rs.scannerType = typeRepoScanner
go rs.receiveLeaks()
return rs
}
// Scan kicks of a repo scan
func (rs *RepoScanner) Scan() (Report, error) {
var scannerReport Report
var (
scannerReport Report
commits chan *object.Commit
)
logOpts, err := logOptions(rs.repo, rs.opts)
if err != nil {
return scannerReport, err
@@ -53,80 +51,68 @@ func (rs *RepoScanner) Scan() (Report, error) {
if err != nil {
return scannerReport, err
}
semaphore := make(chan bool, howManyThreads(rs.opts.Threads))
wg := sync.WaitGroup{}
err = cIter.ForEach(func(c *object.Commit) error {
if c == nil || depthReached(scannerReport.Commits, rs.opts) {
return storer.ErrStop
}
g, _ := errgroup.WithContext(context.Background())
commits = make(chan *object.Commit)
leaks := make(chan Leak)
if rs.cfg.Allowlist.CommitAllowed(c.Hash.String()) {
return nil
}
commitNum := 0
g.Go(func() error {
defer close(commits)
err = cIter.ForEach(func(c *object.Commit) error {
if c == nil || depthReached(commitNum, rs.opts) {
return storer.ErrStop
}
// Check if at root
if len(c.ParentHashes) == 0 {
scannerReport.Commits++
facScanner := NewFilesAtCommitScanner(rs.BaseScanner, rs.repo, c)
facScanner.repoName = rs.repoName
facReport, err := facScanner.Scan()
if err != nil {
return err
if rs.cfg.Allowlist.CommitAllowed(c.Hash.String()) {
return nil
}
commitNum++
commits <- c
if c.Hash.String() == rs.opts.CommitTo {
return storer.ErrStop
}
scannerReport.Leaks = append(scannerReport.Leaks, facReport.Leaks...)
return nil
}
// inspect first parent only as all other parents will be eventually reached
// (they exist as the tip of other branches, etc)
// See https://github.com/zricethezav/gitleaks/issues/413 for details
parent, err := c.Parent(0)
if err != nil || parent == nil {
return err
}
patch, err := parent.Patch(c)
if err != nil {
return fmt.Errorf("could not generate Patch")
}
})
cIter.Close()
return nil
})
scannerReport.Commits++
wg.Add(1)
semaphore <- true
go func(c *object.Commit, patch *object.Patch) {
defer func() {
<-semaphore
wg.Done()
}()
commitScanner := NewCommitScanner(rs.BaseScanner, rs.repo, c)
for commit := range commits {
c := commit
rs.throttle.Limit()
g.Go(func() error {
commitScanner := NewCommitScanner(rs.opts, rs.cfg, rs.repo, c)
commitScanner.SetRepoName(rs.repoName)
commitScanner.SetPatch(patch)
report, err := commitScanner.Scan()
rs.throttle.Release()
if err != nil {
log.Error(err)
}
for _, leak := range report.Leaks {
rs.leakWG.Add(1)
rs.leakChan <- leak
leaks <- leak
}
}(c, patch)
if c.Hash.String() == rs.opts.CommitTo {
return storer.ErrStop
}
return nil
})
wg.Wait()
rs.leakWG.Wait()
scannerReport.Leaks = append(scannerReport.Leaks, rs.leaks...)
return scannerReport, nil
}
func (rs *RepoScanner) receiveLeaks() {
for leak := range rs.leakChan {
rs.leaks = append(rs.leaks, leak)
rs.leakWG.Done()
return nil
})
}
go func() {
if err := g.Wait(); err != nil {
log.Error(err)
}
close(leaks)
}()
for leak := range leaks {
scannerReport.Leaks = append(scannerReport.Leaks, leak)
}
scannerReport.Commits = commitNum
return scannerReport, g.Wait()
}
// SetRepoName sets the repo name
func (rs *RepoScanner) SetRepoName(repoName string) {
rs.repoName = repoName
}
+9 -3
View File
@@ -46,7 +46,7 @@ func WriteReport(report Report, opts options.Options, cfg config.Config) error {
if err != nil {
return err
}
defer file.Close()
defer rable(file.Close)
if opts.Report != "" {
switch opts.ReportFormat {
@@ -59,9 +59,15 @@ func WriteReport(report Report, opts options.Options, cfg config.Config) error {
}
case "csv":
w := csv.NewWriter(file)
_ = w.Write([]string{"repo", "line", "commit", "offender", "leakURL", "rule", "tags", "commitMsg", "author", "email", "file", "date"})
err = w.Write([]string{"repo", "line", "commit", "offender", "leakURL", "rule", "tags", "commitMsg", "author", "email", "file", "date"})
if err != nil {
return err
}
for _, leak := range report.Leaks {
w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.LeakURL, leak.Rule, leak.Tags, leak.Message, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
err := w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.LeakURL, leak.Rule, leak.Tags, leak.Message, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
if err != nil {
return err
}
}
w.Flush()
case "sarif":
+10 -26
View File
@@ -16,14 +16,6 @@ type Scanner interface {
Scan() (Report, error)
}
// BaseScanner is a container for common data each scanner needs.
type BaseScanner struct {
opts options.Options
cfg config.Config
stopChan chan os.Signal
scannerType ScannerType
}
// ScannerType is the scanner type which is determined based on program arguments
type ScannerType int
@@ -46,11 +38,6 @@ func NewScanner(opts options.Options, cfg config.Config) (Scanner, error) {
err error
)
base := BaseScanner{
opts: opts,
cfg: cfg,
}
// We want to return a dir scanner immediately since if the scan type is a directory scan
// we don't want to clone/open a repo until inside ParentScanner.Scan
st, err := scanType(opts)
@@ -58,12 +45,12 @@ func NewScanner(opts options.Options, cfg config.Config) (Scanner, error) {
return nil, err
}
if st == typeDirScanner {
return NewParentScanner(base), nil
return NewParentScanner(opts, cfg), nil
}
// Clone or open a repo if we need it
if needsRepo(st) {
repo, err = getRepo(base.opts)
repo, err = getRepo(opts)
if err != nil {
return nil, err
}
@@ -71,7 +58,7 @@ func NewScanner(opts options.Options, cfg config.Config) (Scanner, error) {
// load up alternative config if possible, if not use manager's config
if opts.RepoConfigPath != "" && !opts.NoGit {
base.cfg, err = config.LoadRepoConfig(repo, opts.RepoConfigPath)
cfg, err = config.LoadRepoConfig(repo, opts.RepoConfigPath)
if err != nil {
return nil, err
}
@@ -83,34 +70,31 @@ func NewScanner(opts options.Options, cfg config.Config) (Scanner, error) {
if err != nil {
return nil, err
}
return NewCommitScanner(base, repo, c), nil
return NewCommitScanner(opts, cfg, repo, c), nil
case typeCommitsScanner:
commits, err := optsToCommits(opts)
if err != nil {
return nil, err
}
return NewCommitsScanner(base, repo, commits), nil
return NewCommitsScanner(opts, cfg, repo, commits), nil
case typeFilesAtCommitScanner:
c, err := obtainCommit(repo, opts.FilesAtCommit)
if err != nil {
return nil, err
}
return NewFilesAtCommitScanner(base, repo, c), nil
return NewFilesAtCommitScanner(opts, cfg, repo, c), nil
case typeUnstagedScanner:
return NewUnstagedScanner(base, repo), nil
return NewUnstagedScanner(opts, cfg, repo), nil
case typeDirScanner:
return NewParentScanner(base), nil
return NewParentScanner(opts, cfg), nil
case typeNoGitScanner:
return NewNoGitScanner(base), nil
return NewNoGitScanner(opts, cfg), nil
default:
return NewRepoScanner(base, repo), nil
return NewRepoScanner(opts, cfg, repo), nil
}
}
func scanType(opts options.Options) (ScannerType, error) {
//if opts.OwnerPath != "" {
// return typeDirScanner
//}
if opts.Commit != "" {
return typeCommitScanner, nil
}
+128 -16
View File
@@ -5,21 +5,20 @@ import (
"fmt"
"io/ioutil"
"os"
"reflect"
"runtime"
"sort"
"testing"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/sergi/go-diff/diffmatchpatch"
)
const testRepoBase = "../test_data/test_repos/"
func TestScan(t *testing.T) {
moveDotGit("dotGit", ".git")
err := moveDotGit("dotGit", ".git")
if err != nil {
t.Fatal(err)
}
defer moveDotGit(".git", "dotGit")
tests := []struct {
description string
@@ -36,6 +35,7 @@ func TestScan(t *testing.T) {
Path: "../test_data/test_repos/test_repo_1",
Report: "../test_data/test_local_repo_one_aws_leak.json.got",
ReportFormat: "json",
Threads: runtime.GOMAXPROCS(0),
},
wantPath: "../test_data/test_local_repo_one_aws_leak.json",
},
@@ -124,6 +124,7 @@ func TestScan(t *testing.T) {
Report: "../test_data/test_local_repo_two_leaks_file_commit_range.json.got",
ReportFormat: "json",
CommitsFile: "../test_data/test_options/test_local_repo_commits.txt",
Threads: runtime.GOMAXPROCS(0),
},
wantPath: "../test_data/test_local_repo_two_leaks_file_commit_range.json",
},
@@ -202,6 +203,7 @@ func TestScan(t *testing.T) {
Path: "../test_data/test_repos/",
Report: "../test_data/test_local_owner_aws_leak.json.got",
ReportFormat: "json",
Threads: runtime.GOMAXPROCS(0),
},
wantPath: "../test_data/test_local_owner_aws_leak.json",
},
@@ -222,6 +224,7 @@ func TestScan(t *testing.T) {
Report: "../test_data/test_regex_entropy.json.got",
ConfigPath: "../test_data/test_configs/regex_entropy.toml",
ReportFormat: "json",
Threads: runtime.GOMAXPROCS(0),
},
wantPath: "../test_data/test_regex_entropy.json",
},
@@ -428,6 +431,62 @@ func TestScan(t *testing.T) {
},
wantPath: "../test_data/test_only_files_no_git.json",
},
{
description: "test allowlist files",
opts: options.Options{
Path: "../test_data/test_repos/test_repo_10",
Report: "../test_data/test_allow_list_file.json.got",
ReportFormat: "json",
ConfigPath: "../test_data/test_configs/allowlist_files.toml",
},
wantPath: "../test_data/test_allow_list_file.json",
},
{
description: "test allowlist files no-git",
opts: options.Options{
Path: "../test_data/test_repos/test_repo_10",
Report: "../test_data/test_allow_list_file_no_git.json.got",
ReportFormat: "json",
ConfigPath: "../test_data/test_configs/allowlist_files.toml",
NoGit: true,
},
wantPath: "../test_data/test_allow_list_file_no_git.json",
},
{
description: "test allowlist docx no-git",
opts: options.Options{
Path: "../test_data/test_repos/test_repo_10",
Report: "../test_data/test_allow_list_docx_no_git.json.got",
ReportFormat: "json",
ConfigPath: "../test_data/test_configs/allowlist_docx.toml",
NoGit: true,
},
wantPath: "../test_data/test_allow_list_docx_no_git.json",
},
{
description: "test local repo two allowlist Commit config",
opts: options.Options{
Path: "../test_data/test_repos/test_repo_2",
Report: "../test_data/test_local_repo_two_allowlist_commits_files_at_commit.json.got",
ConfigPath: "../test_data/test_configs/allowlist_commit.toml",
ReportFormat: "json",
FilesAtCommit: "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
},
wantPath: "../test_data/test_local_repo_two_allowlist_commits_files_at_commit.json",
wantEmpty: true,
},
{
description: "test local repo two global allowlist commit config",
opts: options.Options{
Path: "../test_data/test_repos/test_repo_2",
Report: "../test_data/test_local_repo_two_global_allowlist_files_at_commit.json.got",
ConfigPath: "../test_data/test_configs/allowlist_global_files.toml",
ReportFormat: "json",
FilesAtCommit: "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
},
wantPath: "../test_data/test_local_repo_two_global_allowlist_files_at_commit.json",
wantEmpty: true,
},
}
for _, test := range tests {
@@ -643,30 +702,82 @@ func fileCheck(wantPath, gotPath string) error {
return err
}
sort.Slice(gotLeaks, func(i, j int) bool {
return (gotLeaks)[i].Offender+(gotLeaks)[i].File < (gotLeaks)[j].Offender+(gotLeaks)[j].File
})
sort.Slice(wantLeaks, func(i, j int) bool {
return (wantLeaks)[i].Offender+(wantLeaks)[i].File < (wantLeaks)[j].Offender+(wantLeaks)[j].File
})
if !reflect.DeepEqual(gotLeaks, wantLeaks) {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(want), string(got), false)
return fmt.Errorf("%s does not equal %s: %s", wantPath, gotPath, dmp.DiffPrettyText(diffs))
if len(wantLeaks) != len(gotLeaks) {
return fmt.Errorf("got %d leaks, want %d leaks", len(gotLeaks), len(wantLeaks))
}
for _, wantLeak := range wantLeaks {
found := false
for _, gotLeak := range gotLeaks {
if same(gotLeak, wantLeak) {
found = true
}
}
if !found {
return fmt.Errorf("unable to find %+v in got leaks", wantLeak)
}
}
if err := os.Remove(gotPath); err != nil {
return err
}
return nil
}
func same(l1, l2 Leak) bool {
if l1.Commit != l2.Commit {
return false
}
if l1.Offender != l2.Offender {
return false
}
if l1.Line != l2.Line {
return false
}
if l1.Tags != l2.Tags {
return false
}
if l1.LineNumber != l2.LineNumber {
return false
}
if l1.Author != l2.Author {
return false
}
if l1.LeakURL != l2.LeakURL {
return false
}
if l1.RepoURL != l2.RepoURL {
return false
}
if l1.Repo != l2.Repo {
return false
}
return true
}
func moveDotGit(from, to string) error {
repoDirs, err := ioutil.ReadDir("../test_data/test_repos")
if err != nil {
return err
}
for _, dir := range repoDirs {
if to == ".git" {
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), "dotGit"))
if os.IsNotExist(err) {
// dont want to delete the only copy of .git accidentally
continue
}
os.RemoveAll(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), ".git"))
}
if !dir.IsDir() {
continue
}
@@ -680,6 +791,7 @@ func moveDotGit(from, to string) error {
if err != nil {
return err
}
// fmt.Println("RENAMED")
}
return nil
}
+43
View File
@@ -0,0 +1,43 @@
package scan
import (
"runtime"
"github.com/zricethezav/gitleaks/v7/options"
)
const (
singleThreadCommitBuffer = 1
multiThreadCommitBufferMultiplier = 10
)
// Throttle is a struct that limits the number of concurrent goroutines and sets the
// number of threads available for gitleaks to use via GOMAXPROCS.
type Throttle struct {
throttle chan bool
}
// NewThrottle accepts some options and returns a throttle for scanners to use
func NewThrottle(opts options.Options) *Throttle {
t := Throttle{}
if opts.Threads <= 1 {
runtime.GOMAXPROCS(1)
t.throttle = make(chan bool, singleThreadCommitBuffer)
return &t
}
runtime.GOMAXPROCS(opts.Threads)
t.throttle = make(chan bool, multiThreadCommitBufferMultiplier*opts.Threads)
return &t
}
// Limit blocks new goroutines from spinning up if throttle is at capacity
func (t *Throttle) Limit() {
t.throttle <- true
}
// Release releases the hold on the throttle, allowing more goroutines to be spun up
func (t *Throttle) Release() {
<-t.throttle
}
+14 -10
View File
@@ -9,6 +9,9 @@ import (
"strings"
"time"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/sergi/go-diff/diffmatchpatch"
@@ -17,19 +20,20 @@ import (
// UnstagedScanner is an unstaged scanner. This is the scanner used when you don't provide program arguments
// which will then scan your PWD. This scans unstaged changes in your repo.
type UnstagedScanner struct {
BaseScanner
opts options.Options
cfg config.Config
repo *git.Repository
repoName string
}
// NewUnstagedScanner returns an unstaged scanner
func NewUnstagedScanner(base BaseScanner, repo *git.Repository) *UnstagedScanner {
func NewUnstagedScanner(opts options.Options, cfg config.Config, repo *git.Repository) *UnstagedScanner {
us := &UnstagedScanner{
BaseScanner: base,
repo: repo,
repoName: getRepoName(base.opts),
opts: opts,
cfg: cfg,
repo: repo,
repoName: getRepoName(opts),
}
us.scannerType = typeUnstagedScanner
return us
}
@@ -82,7 +86,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if us.opts.Verbose {
leak.Log(us.opts.Redact)
leak.Log(us.opts)
}
scannerReport.Leaks = append(scannerReport.Leaks, leak)
}
@@ -194,9 +198,9 @@ func (us *UnstagedScanner) Scan() (Report, error) {
leak.Repo = us.repoName
leak.Rule = rule.Description
leak.Tags = strings.Join(rule.Tags, ", ")
if us.opts.Verbose {
leak.Log(us.opts.Redact)
}
leak.Log(us.opts)
scannerReport.Leaks = append(scannerReport.Leaks, leak)
}
}
+8 -1
View File
@@ -178,7 +178,7 @@ func optsToCommits(opts options.Options) ([]string, error) {
if err != nil {
return []string{}, err
}
defer file.Close()
defer rable(file.Close)
scanner := bufio.NewScanner(file)
var commits []string
@@ -218,3 +218,10 @@ func extractLine(patchContent string, leak Leak, lineLookup map[string]bool) int
}
return defaultLineNumber
}
// rable is the second half of deferrable... mainly used for defer file.Close()
func rable(f func() error) {
if err := f(); err != nil {
log.Error(err)
}
}
@@ -0,0 +1,50 @@
[
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/.gitignore",
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "Block dangerous filetypes",
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_10/.gitignore",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/bad.zip",
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "Block dangerous filetypes",
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_10/bad.zip",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/gitfile.txt",
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "Block dangerous filetypes",
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_10/gitfile.txt",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
}
]
+18
View File
@@ -0,0 +1,18 @@
[
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: tmp/bad.docx",
"commit": "b0f9b62dfe12e4e10de180359c6b9276472494f8",
"repo": "test_repo_10",
"repoURL": "",
"leakURL": "",
"rule": "Block dangerous filetypes",
"commitMessage": "Create bad.docx",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "tmp/bad.docx",
"date": "2020-12-09T11:02:10-05:00",
"tags": "key, extensions"
}
]
@@ -0,0 +1,18 @@
[
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/tmp/bad.docx",
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "Block dangerous filetypes",
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_10/tmp/bad.docx",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
}
]
@@ -0,0 +1,11 @@
[[rules]]
description = "Block dangerous filetypes"
file = '''(.*?)(gitfile.txt|gitignore|pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$'''
tags = ["key", "extensions"]
[rules.allowlist]
paths = ['''.docx''']
description = "ignore known locations and files"
#[allowlist]
# description = "Allowlisted files"
# paths = ['''.zip''']
@@ -0,0 +1,11 @@
[[rules]]
description = "Block dangerous filetypes"
file = '''(.*?)(pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$'''
tags = ["key", "extensions"]
[rules.allowlist]
paths = ['''.zip''']
description = "ignore known locations and files"
#
#[allowlist]
# description = "Allowlisted files"
# paths = ['''.zip''']
@@ -0,0 +1,9 @@
[[rules]]
description = "AWS Access Key"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"]
[allowlist]
description = "Allowlisted files"
paths = ['''.py''']
files = ['''.md$''']
+103 -103
View File
@@ -4,7 +4,7 @@
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_1",
"repo": "test_repos",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
@@ -15,22 +15,6 @@
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
"lineNumber": 4,
"offender": "AKIALALEMEL33243OLIB",
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
"repo": "test_repo_2",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "adding another one\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 3,
@@ -47,6 +31,22 @@
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
"lineNumber": 4,
"offender": "AKIALALEMEL33243OLIB",
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
"repo": "test_repo_2",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "adding another one\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
"lineNumber": 3,
@@ -63,22 +63,6 @@
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 3,
"offender": "AKIALALEMEL33243OLIA",
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
"repo": "test_repo_3",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "more secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:08-04:00",
"tags": "key, AWS"
},
{
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 5,
@@ -96,19 +80,19 @@
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
"lineNumber": 4,
"offender": "AKIALALEMEL33243OLIB",
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 3,
"offender": "AKIALALEMEL33243OLIA",
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
"repo": "test_repo_3",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "adding another one\n",
"commitMessage": "more secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"date": "2019-10-25T13:54:08-04:00",
"tags": "key, AWS"
},
{
@@ -144,19 +128,19 @@
"tags": "key, AWS"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 3,
"offender": "AKIALALEMEL33243OLIA",
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
"repo": "test_repo_4",
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
"lineNumber": 4,
"offender": "AKIALALEMEL33243OLIB",
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
"repo": "test_repo_3",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "more secrets\n",
"commitMessage": "adding another one\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:08-04:00",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS"
},
{
@@ -175,6 +159,38 @@
"date": "2019-10-25T13:35:03-04:00",
"tags": "key, AWS"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 3,
"offender": "AKIALALEMEL33243OLIA",
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
"repo": "test_repo_4",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "more secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:08-04:00",
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
"lineNumber": 3,
"offender": "AKIALALEMEL33243OLIA",
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
"repo": "test_repo_4",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "adding aws key\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
"lineNumber": 4,
@@ -207,38 +223,6 @@
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
"lineNumber": 3,
"offender": "AKIALALEMEL33243OLIA",
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
"repo": "test_repo_4",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "adding aws key\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPL2'",
"lineNumber": 4,
"offender": "AKIAIO5FODNN7EXAMPL2",
"commit": "ca71fcdeda15f25f0cc661d90e8785c255925c27",
"repo": "test_repo_5",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "introduce more secrets\n",
"author": "Zach Rice",
"email": "zrice@gitlab.com",
"file": "secrets.py",
"date": "2020-02-01T10:08:04-05:00",
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE'",
"lineNumber": 1,
@@ -255,12 +239,28 @@
"date": "2020-02-01T10:07:34-05:00",
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPL2'",
"lineNumber": 4,
"offender": "AKIAIO5FODNN7EXAMPL2",
"commit": "ca71fcdeda15f25f0cc661d90e8785c255925c27",
"repo": "test_repo_5",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "introduce more secrets\n",
"author": "Zach Rice",
"email": "zrice@gitlab.com",
"file": "secrets.py",
"date": "2020-02-01T10:08:04-05:00",
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_6",
"repo": "test_repos",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
@@ -287,22 +287,6 @@
"date": "2020-02-24T14:13:15-05:00",
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
"repo": "test_repo_8",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:44:48-04:00",
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 2,
@@ -336,19 +320,19 @@
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_9",
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
"repo": "test_repo_8",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"file": "dummy.txt",
"date": "2020-07-25T14:44:48-04:00",
"tags": "key, AWS"
},
{
@@ -366,5 +350,21 @@
"file": "server.test.py",
"date": "2020-08-12T13:36:20-04:00",
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repos",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS"
}
]
@@ -239,22 +239,6 @@
"date": "2020-02-01T10:07:34-05:00",
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_6",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS"
},
{
"line": "aws_access_key_id=AKIAIO5FODNN7EXAMPLE",
"lineNumber": 3,
@@ -271,6 +255,22 @@
"date": "2020-02-24T14:13:15-05:00",
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repos",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
@@ -319,22 +319,6 @@
"date": "2020-07-25T14:41:11-04:00",
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_9",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE', #gitleaks:allow",
"lineNumber": 5,
@@ -350,5 +334,21 @@
"file": "server.test.py",
"date": "2020-08-12T13:36:20-04:00",
"tags": "key, AWS"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repos",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS"
}
]
@@ -4,7 +4,7 @@
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_1",
"repo": "test_repos",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
+9 -6
View File
@@ -5,14 +5,15 @@
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
"repo": "test_repo_8",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:44:48-04:00",
"tags": "key, AWS",
"operation": "addition"
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
@@ -20,14 +21,15 @@
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "ce7e8177bbf8a172c06b6a1e370a374d5c19f660",
"repo": "test_repo_8",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "dummy.txt w/ text",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:39:11-04:00",
"tags": "key, AWS",
"operation": "addition"
"tags": "key, AWS"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
@@ -35,13 +37,14 @@
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "9267bc86ec1497471cbc6f3308f3527f7ef34b9d",
"repo": "test_repo_8",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "Update dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:41:11-04:00",
"tags": "key, AWS",
"operation": "addition"
"tags": "key, AWS"
}
]
+3 -2
View File
@@ -5,13 +5,14 @@
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_1",
"repoURL": "",
"leakURL": "",
"rule": "AWS Access Key",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS",
"operation": "addition"
"tags": "key, AWS"
}
]
+34 -18
View File
@@ -2,7 +2,7 @@
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_2/no_secrets.md",
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/README.md",
"commit": "",
"repo": "",
"repoURL": "",
@@ -11,7 +11,7 @@
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_2/no_secrets.md",
"file": "../test_data/test_repos/test_repo_10/README.md",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
@@ -31,6 +31,22 @@
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_2/no_secrets.md",
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "flag go",
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_2/no_secrets.md",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
@@ -63,22 +79,6 @@
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_4/no_secrets.md",
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "flag go",
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_4/no_secrets.md",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
@@ -95,6 +95,22 @@
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_4/no_secrets.md",
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "flag go",
"commitMessage": "",
"author": "",
"email": "",
"file": "../test_data/test_repos/test_repo_4/no_secrets.md",
"date": "0001-01-01T00:00:00Z",
"tags": "key, extensions"
},
{
"line": "",
"lineNumber": 1,
File renamed without changes.
@@ -0,0 +1 @@
a dot git ignore file
@@ -0,0 +1,11 @@
[[rules]]
description = "Block dangerous filetypes"
file = '''(.*?)(pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$'''
tags = ["key", "extensions"]
[rules.allowlist]
paths = ['''.git''', '''.zip''']
description = "ignore known locations and files"
[allowlist]
description = "Allowlisted files"
paths = ['''.zip''']
@@ -0,0 +1 @@
# test_repo_paths
@@ -0,0 +1 @@
this is a bad .zip
@@ -0,0 +1 @@
ref: refs/heads/main
Whitespace-only changes.
@@ -0,0 +1,13 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@github.com:zricethezav/test_repo_paths.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 5cd9652a24771400b4ce76beadbb2496a73341b8 Zach Rice <zrice@gitlab.com> 1607529853 -0500 clone: from github.com:zricethezav/test_repo_paths.git
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 5cd9652a24771400b4ce76beadbb2496a73341b8 Zach Rice <zrice@gitlab.com> 1607529853 -0500 clone: from github.com:zricethezav/test_repo_paths.git
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 5cd9652a24771400b4ce76beadbb2496a73341b8 Zach Rice <zrice@gitlab.com> 1607529853 -0500 clone: from github.com:zricethezav/test_repo_paths.git
@@ -0,0 +1,2 @@
# pack-refs with: peeled fully-peeled sorted
5cd9652a24771400b4ce76beadbb2496a73341b8 refs/remotes/origin/main
@@ -0,0 +1 @@
5cd9652a24771400b4ce76beadbb2496a73341b8
@@ -0,0 +1 @@
ref: refs/remotes/origin/main
@@ -0,0 +1 @@
a git file
@@ -0,0 +1 @@
bad .docx