mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3932ed6baf | ||
|
|
981b636920 | ||
|
|
c8e15c731a | ||
|
|
901f932a89 | ||
|
|
c0a9580a65 | ||
|
|
8be91eea5d | ||
|
|
1c6f2252b8 | ||
|
|
58d130c5f3 | ||
|
|
091ea81e68 | ||
|
|
f036dce6ab | ||
|
|
2d58f1f94e |
No files matched your search
@@ -2,6 +2,7 @@
|
|||||||
<img alt="gitleaks" src="https://raw.githubusercontent.com/zricethezav/gifs/master/gitleakslogo.png" height="70" />
|
<img alt="gitleaks" src="https://raw.githubusercontent.com/zricethezav/gifs/master/gitleakslogo.png" height="70" />
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://travis-ci.org/zricethezav/gitleaks"><img alt="Travis" src="https://img.shields.io/travis/zricethezav/gitleaks/master.svg?style=flat-square"></a>
|
<a href="https://travis-ci.org/zricethezav/gitleaks"><img alt="Travis" src="https://img.shields.io/travis/zricethezav/gitleaks/master.svg?style=flat-square"></a>
|
||||||
|
<a href="https://gitter.im/gitleaks/gitleaks"><img alt="Travis" src="https://badges.gitter.im/gitleaks/gitleaks.svg?style=flat-square"></a>
|
||||||
</p>
|
</p>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ Gitleaks is a SAST tool for detecting hardcoded secrets like passwords, api keys
|
|||||||
|
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
Written in Go, gitleaks is available in binary form for many popular platforms and OS types from the [releases page](https://github.com/zricethezav/gitleaks/releases). Alternatively, executed via Docker or it can be installed using Go directly.
|
Gitleaks can be installed with Homebrew, Docker, and Go. Gitleaks is also available in binary form for many popular platforms and OS types from the [releases page](https://github.com/zricethezav/gitleaks/releases).
|
||||||
|
|
||||||
##### MacOS
|
##### MacOS
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ Usage:
|
|||||||
|
|
||||||
Application Options:
|
Application Options:
|
||||||
-v, --verbose Show verbose output from scan
|
-v, --verbose Show verbose output from scan
|
||||||
|
-q, --quiet Sets log level to error and only output leaks, one json object per line
|
||||||
-r, --repo-url= Repository URL
|
-r, --repo-url= Repository URL
|
||||||
-p, --path= Path to directory (repo if contains .git) or file
|
-p, --path= Path to directory (repo if contains .git) or file
|
||||||
-c, --config-path= Path to config
|
-c, --config-path= Path to config
|
||||||
|
|||||||
+6
-2
@@ -4,6 +4,10 @@ import (
|
|||||||
"regexp"
|
"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
|
// AllowList is struct containing items that if encountered will allowlist
|
||||||
// a commit/line of code that would be considered a leak.
|
// a commit/line of code that would be considered a leak.
|
||||||
type AllowList struct {
|
type AllowList struct {
|
||||||
@@ -45,9 +49,9 @@ func (a *AllowList) RepoAllowed(repo string) bool {
|
|||||||
return anyRegexMatch(repo, a.Repos)
|
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 {
|
func (a *AllowList) IgnoreDotGit() error {
|
||||||
re, err := regexp.Compile(".git")
|
re, err := regexp.Compile(dotGit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -21,6 +21,7 @@ import (
|
|||||||
// Options stores values of command line options
|
// Options stores values of command line options
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from scan"`
|
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"`
|
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"`
|
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"`
|
ConfigPath string `short:"c" long:"config-path" description:"Path to config"`
|
||||||
@@ -68,7 +69,7 @@ func ParseOptions() (Options, error) {
|
|||||||
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
|
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
|
||||||
parser.WriteHelp(os.Stdout)
|
parser.WriteHelp(os.Stdout)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Version {
|
if opts.Version {
|
||||||
@@ -83,6 +84,9 @@ func ParseOptions() (Options, error) {
|
|||||||
if opts.Debug {
|
if opts.Debug {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
if opts.Quiet {
|
||||||
|
log.SetLevel(log.ErrorLevel)
|
||||||
|
}
|
||||||
|
|
||||||
return opts, nil
|
return opts, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-6
@@ -42,6 +42,11 @@ func (cs *CommitScanner) SetRepoName(repoName string) {
|
|||||||
// Scan kicks off a CommitScanner Scan
|
// Scan kicks off a CommitScanner Scan
|
||||||
func (cs *CommitScanner) Scan() (Report, error) {
|
func (cs *CommitScanner) Scan() (Report, error) {
|
||||||
var scannerReport Report
|
var scannerReport Report
|
||||||
|
|
||||||
|
if cs.cfg.Allowlist.CommitAllowed(cs.commit.Hash.String()) {
|
||||||
|
return scannerReport, nil
|
||||||
|
}
|
||||||
|
|
||||||
if len(cs.commit.ParentHashes) == 0 {
|
if len(cs.commit.ParentHashes) == 0 {
|
||||||
facScanner := NewFilesAtCommitScanner(cs.opts, cs.cfg, cs.repo, cs.commit)
|
facScanner := NewFilesAtCommitScanner(cs.opts, cs.cfg, cs.repo, cs.commit)
|
||||||
return facScanner.Scan()
|
return facScanner.Scan()
|
||||||
@@ -90,9 +95,8 @@ func (cs *CommitScanner) Scan() (Report, error) {
|
|||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
|
|
||||||
if cs.opts.Verbose {
|
leak.Log(cs.opts)
|
||||||
leak.Log(cs.opts.Redact)
|
|
||||||
}
|
|
||||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -132,9 +136,9 @@ func (cs *CommitScanner) Scan() (Report, error) {
|
|||||||
leak.LeakURL = leak.URL()
|
leak.LeakURL = leak.URL()
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
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)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-6
@@ -38,6 +38,11 @@ func NewFilesAtCommitScanner(opts options.Options, cfg config.Config, repo *git.
|
|||||||
// Scan kicks off a FilesAtCommitScanner Scan
|
// Scan kicks off a FilesAtCommitScanner Scan
|
||||||
func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
||||||
var scannerReport Report
|
var scannerReport Report
|
||||||
|
|
||||||
|
if fs.cfg.Allowlist.CommitAllowed(fs.commit.Hash.String()) {
|
||||||
|
return scannerReport, nil
|
||||||
|
}
|
||||||
|
|
||||||
fIter, err := fs.commit.Files()
|
fIter, err := fs.commit.Files()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return scannerReport, err
|
return scannerReport, err
|
||||||
@@ -51,6 +56,11 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fs.cfg.Allowlist.FileAllowed(filepath.Base(f.Name)) ||
|
||||||
|
fs.cfg.Allowlist.PathAllowed(f.Name) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
content, err := f.Contents()
|
content, err := f.Contents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -71,9 +81,8 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
|||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
|
|
||||||
if fs.opts.Verbose {
|
leak.Log(fs.opts)
|
||||||
leak.Log(fs.opts.Redact)
|
|
||||||
}
|
|
||||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -112,9 +121,9 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
|||||||
leak.LeakURL = leak.URL()
|
leak.LeakURL = leak.URL()
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
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)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-5
@@ -6,6 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/zricethezav/gitleaks/v7/options"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"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
|
// Log logs a leak and redacts if necessary
|
||||||
func (leak Leak) Log(redact bool) {
|
func (leak Leak) Log(opts options.Options) {
|
||||||
if redact {
|
if !opts.Quiet && !opts.Verbose {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if opts.Redact {
|
||||||
leak = RedactLeak(leak)
|
leak = RedactLeak(leak)
|
||||||
}
|
}
|
||||||
var b []byte
|
if opts.Quiet {
|
||||||
b, _ = json.MarshalIndent(leak, "", " ")
|
var b []byte
|
||||||
fmt.Println(string(b))
|
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
|
// URL generates a url to the leak if leak.RepoURL is set
|
||||||
|
|||||||
+21
-10
@@ -73,18 +73,22 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
|
|||||||
for _, rule := range ngs.cfg.Rules {
|
for _, rule := range ngs.cfg.Rules {
|
||||||
if rule.HasFileOrPathLeakOnly(p) {
|
if rule.HasFileOrPathLeakOnly(p) {
|
||||||
leak := NewLeak("", "Filename or path offender: "+p, defaultLineNumber)
|
leak := NewLeak("", "Filename or path offender: "+p, defaultLineNumber)
|
||||||
leak.File = p
|
relPath, err := filepath.Rel(ngs.opts.Path, p)
|
||||||
|
if err != nil {
|
||||||
|
leak.File = p
|
||||||
|
} else {
|
||||||
|
leak.File = relPath
|
||||||
|
}
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
|
|
||||||
if ngs.opts.Verbose {
|
leak.Log(ngs.opts)
|
||||||
leak.Log(ngs.opts.Redact)
|
|
||||||
}
|
|
||||||
leaks <- leak
|
leaks <- leak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(p)
|
f, err := os.Open(p) // #nosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -116,13 +120,18 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
leak := NewLeak(line, offender, defaultLineNumber)
|
leak := NewLeak(line, offender, defaultLineNumber)
|
||||||
leak.File = p
|
relPath, err := filepath.Rel(ngs.opts.Path, p)
|
||||||
|
if err != nil {
|
||||||
|
leak.File = p
|
||||||
|
} else {
|
||||||
|
leak.File = relPath
|
||||||
|
}
|
||||||
leak.LineNumber = lineNumber
|
leak.LineNumber = lineNumber
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
if ngs.opts.Verbose {
|
|
||||||
leak.Log(ngs.opts.Redact)
|
leak.Log(ngs.opts)
|
||||||
}
|
|
||||||
leaks <- leak
|
leaks <- leak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +140,9 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
g.Wait()
|
if err := g.Wait(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
close(leaks)
|
close(leaks)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -98,7 +98,9 @@ func (rs *RepoScanner) Scan() (Report, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
g.Wait()
|
if err := g.Wait(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
close(leaks)
|
close(leaks)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
+9
-4
@@ -27,7 +27,6 @@ func WriteReport(report Report, opts options.Options, cfg config.Config) error {
|
|||||||
logrus.Warn("leaks found: ", len(report.Leaks))
|
logrus.Warn("leaks found: ", len(report.Leaks))
|
||||||
} else {
|
} else {
|
||||||
logrus.Info("No leaks found")
|
logrus.Info("No leaks found")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Report == "" {
|
if opts.Report == "" {
|
||||||
@@ -46,7 +45,7 @@ func WriteReport(report Report, opts options.Options, cfg config.Config) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer rable(file.Close)
|
||||||
|
|
||||||
if opts.Report != "" {
|
if opts.Report != "" {
|
||||||
switch opts.ReportFormat {
|
switch opts.ReportFormat {
|
||||||
@@ -59,9 +58,15 @@ func WriteReport(report Report, opts options.Options, cfg config.Config) error {
|
|||||||
}
|
}
|
||||||
case "csv":
|
case "csv":
|
||||||
w := csv.NewWriter(file)
|
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 {
|
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()
|
w.Flush()
|
||||||
case "sarif":
|
case "sarif":
|
||||||
|
|||||||
@@ -463,6 +463,30 @@ func TestScan(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantPath: "../test_data/test_allow_list_docx_no_git.json",
|
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 {
|
for _, test := range tests {
|
||||||
|
|||||||
+26
-4
@@ -57,6 +57,28 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if file is allow listed
|
||||||
|
if us.cfg.Allowlist.FileAllowed(filepath.Base(fn)) ||
|
||||||
|
us.cfg.Allowlist.PathAllowed(fn) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Check individual file path ONLY rules
|
||||||
|
for _, rule := range us.cfg.Rules {
|
||||||
|
if rule.HasFileOrPathLeakOnly(fn) {
|
||||||
|
leak := NewLeak("", "Filename or path offender: "+ fn, defaultLineNumber)
|
||||||
|
leak.Repo = us.repoName
|
||||||
|
leak.File = fn
|
||||||
|
leak.RepoURL = us.opts.RepoURL
|
||||||
|
leak.LeakURL = leak.URL()
|
||||||
|
leak.Rule = rule.Description
|
||||||
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
|
leak.Log(us.opts)
|
||||||
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := io.Copy(workTreeBuf, workTreeFile); err != nil {
|
if _, err := io.Copy(workTreeBuf, workTreeFile); err != nil {
|
||||||
return scannerReport, err
|
return scannerReport, err
|
||||||
}
|
}
|
||||||
@@ -86,7 +108,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
|||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
if us.opts.Verbose {
|
if us.opts.Verbose {
|
||||||
leak.Log(us.opts.Redact)
|
leak.Log(us.opts)
|
||||||
}
|
}
|
||||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
@@ -198,9 +220,9 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
|||||||
leak.Repo = us.repoName
|
leak.Repo = us.repoName
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
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)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -178,7 +178,7 @@ func optsToCommits(opts options.Options) ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}, err
|
return []string{}, err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer rable(file.Close)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
var commits []string
|
var commits []string
|
||||||
@@ -218,3 +218,10 @@ func extractLine(patchContent string, leak Leak, lineLookup map[string]bool) int
|
|||||||
}
|
}
|
||||||
return defaultLineNumber
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,20 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"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": "",
|
"line": "",
|
||||||
"lineNumber": 1,
|
"lineNumber": 1,
|
||||||
@@ -14,5 +30,53 @@
|
|||||||
"file": "../test_data/test_repos/test_repo_10/bad.zip",
|
"file": "../test_data/test_repos/test_repo_10/bad.zip",
|
||||||
"date": "0001-01-01T00:00:00Z",
|
"date": "0001-01-01T00:00:00Z",
|
||||||
"tags": "key, extensions"
|
"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"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"line": "",
|
||||||
|
"lineNumber": 1,
|
||||||
|
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/creds.git",
|
||||||
|
"commit": "",
|
||||||
|
"repo": "",
|
||||||
|
"repoURL": "",
|
||||||
|
"leakURL": "",
|
||||||
|
"rule": "Block dangerous filetypes",
|
||||||
|
"commitMessage": "",
|
||||||
|
"author": "",
|
||||||
|
"email": "",
|
||||||
|
"file": "../test_data/test_repos/test_repo_10/creds.git",
|
||||||
|
"date": "0001-01-01T00:00:00Z",
|
||||||
|
"tags": "key, extensions"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"line": "",
|
||||||
|
"lineNumber": 1,
|
||||||
|
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||||
|
"commit": "",
|
||||||
|
"repo": "",
|
||||||
|
"repoURL": "",
|
||||||
|
"leakURL": "",
|
||||||
|
"rule": "Block dangerous filetypes",
|
||||||
|
"commitMessage": "",
|
||||||
|
"author": "",
|
||||||
|
"email": "",
|
||||||
|
"file": "../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||||
|
"date": "0001-01-01T00:00:00Z",
|
||||||
|
"tags": "key, extensions"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,4 +1,20 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"line": "",
|
||||||
|
"lineNumber": 1,
|
||||||
|
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||||
|
"commit": "",
|
||||||
|
"repo": "",
|
||||||
|
"repoURL": "",
|
||||||
|
"leakURL": "",
|
||||||
|
"rule": "Block dangerous filetypes",
|
||||||
|
"commitMessage": "",
|
||||||
|
"author": "",
|
||||||
|
"email": "",
|
||||||
|
"file": "../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||||
|
"date": "0001-01-01T00:00:00Z",
|
||||||
|
"tags": "key, extensions"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"line": "",
|
"line": "",
|
||||||
"lineNumber": 1,
|
"lineNumber": 1,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[[rules]]
|
[[rules]]
|
||||||
description = "Block dangerous filetypes"
|
description = "Block dangerous filetypes"
|
||||||
file = '''(.*?)(pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$'''
|
file = '''(.*?)(creds.git|gitfile.txt|gitignore|pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$'''
|
||||||
tags = ["key", "extensions"]
|
tags = ["key", "extensions"]
|
||||||
[rules.allowlist]
|
[rules.allowlist]
|
||||||
paths = ['''.docx''']
|
paths = ['''.docx''']
|
||||||
|
|||||||
@@ -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$''']
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
a dot git ignore file
|
||||||
Whitespace-only changes.
@@ -0,0 +1 @@
|
|||||||
|
a git file
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
hah
|
||||||
Reference in new issue
Block a user