mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c60c3dde3 | ||
|
|
ad505754fc | ||
|
|
21d81879e2 | ||
|
|
b5ca2ba614 |
No files matched your search
@@ -31,8 +31,8 @@ Gamma proactively detects and remediates data leaks across cloud apps. Scan your
|
|||||||
#### Individual Sponsors
|
#### Individual Sponsors
|
||||||
These users are [sponsors](https://github.com/sponsors/zricethezav) of gitleaks:
|
These users are [sponsors](https://github.com/sponsors/zricethezav) of gitleaks:
|
||||||
|
|
||||||
[](https://github.com/adamdecaf) | [](https://github.com/gramidt) |
|
[](https://github.com/adamdecaf) |
|
||||||
---|---|
|
---|
|
||||||
----
|
----
|
||||||
#### Logo Attribution
|
#### Logo Attribution
|
||||||
The Gitleaks logo uses the Git Logo created <a href="https://twitter.com/jasonlong">Jason Long</a> is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.
|
The Gitleaks logo uses the Git Logo created <a href="https://twitter.com/jasonlong">Jason Long</a> is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.
|
||||||
|
|||||||
+34
-29
@@ -28,35 +28,40 @@ const (
|
|||||||
|
|
||||||
// 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"`
|
||||||
Repo string `short:"r" long:"repo" description:"Target repository"`
|
Repo string `short:"r" long:"repo" description:"Target repository"`
|
||||||
Config string `long:"config" description:"config path"`
|
Config string `long:"config" description:"config path"`
|
||||||
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
||||||
Version bool `long:"version" description:"version number"`
|
Version bool `long:"version" description:"version number"`
|
||||||
Username string `long:"username" description:"Username for git repo"`
|
Username string `long:"username" description:"Username for git repo"`
|
||||||
Password string `long:"password" description:"Password for git repo"`
|
Password string `long:"password" description:"Password for git repo"`
|
||||||
AccessToken string `long:"access-token" description:"Access token for git repo"`
|
AccessToken string `long:"access-token" description:"Access token for git repo"`
|
||||||
Commit string `long:"commit" description:"sha of commit to scan or \"latest\" to scan the last commit of the repository"`
|
FilesAtCommit string `long:"files-at-commit" description:"sha of commit to scan all files at commit"`
|
||||||
FilesAtCommit string `long:"files-at-commit" description:"sha of commit to scan all files at commit"`
|
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
|
||||||
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
|
SSH string `long:"ssh-key" description:"path to ssh key used for auth"`
|
||||||
SSH string `long:"ssh-key" description:"path to ssh key used for auth"`
|
Uncommited bool `long:"uncommitted" description:"run gitleaks on uncommitted code"`
|
||||||
Uncommited bool `long:"uncommitted" description:"run gitleaks on uncommitted code"`
|
RepoPath string `long:"repo-path" description:"Path to repo"`
|
||||||
RepoPath string `long:"repo-path" description:"Path to repo"`
|
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
|
||||||
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
|
Branch string `long:"branch" description:"Branch to scan"`
|
||||||
Branch string `long:"branch" description:"Branch to scan"`
|
Report string `long:"report" description:"path to write json leaks file"`
|
||||||
Report string `long:"report" description:"path to write json leaks file"`
|
ReportFormat string `long:"report-format" default:"json" description:"json, csv, sarif"`
|
||||||
ReportFormat string `long:"report-format" default:"json" description:"json, csv, sarif"`
|
Redact bool `long:"redact" description:"redact secrets from log messages and leaks"`
|
||||||
Redact bool `long:"redact" description:"redact secrets from log messages and leaks"`
|
Debug bool `long:"debug" description:"log debug messages"`
|
||||||
Debug bool `long:"debug" description:"log debug messages"`
|
RepoConfig bool `long:"repo-config" description:"Load config from target repo. Config file must be \".gitleaks.toml\" or \"gitleaks.toml\""`
|
||||||
RepoConfig bool `long:"repo-config" description:"Load config from target repo. Config file must be \".gitleaks.toml\" or \"gitleaks.toml\""`
|
PrettyPrint bool `long:"pretty" description:"Pretty print json if leaks are present"`
|
||||||
PrettyPrint bool `long:"pretty" description:"Pretty print json if leaks are present"`
|
|
||||||
CommitFrom string `long:"commit-from" description:"Commit to start scan from"`
|
// Commit Options
|
||||||
CommitTo string `long:"commit-to" description:"Commit to stop scan"`
|
Commit string `long:"commit" description:"sha of commit to scan or \"latest\" to scan the last commit of the repository"`
|
||||||
CommitSince string `long:"commit-since" description:"Scan commits more recent than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format."`
|
Commits string `long:"commits" description:"comma separated list of a commits to scan"`
|
||||||
CommitUntil string `long:"commit-until" description:"Scan commits older than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format."`
|
CommitsFile string `long:"commits-file" description:"file of new line separated list of a commits to scan"`
|
||||||
Timeout string `long:"timeout" description:"Time allowed per scan. Ex: 10us, 30s, 1m, 1h10m1s"`
|
CommitFrom string `long:"commit-from" description:"Commit to start scan from"`
|
||||||
Depth int `long:"depth" description:"Number of commits to scan"`
|
CommitTo string `long:"commit-to" description:"Commit to stop scan"`
|
||||||
Deletion bool `long:"include-deletion" description:"Scan for patch deletions in addition to patch additions"`
|
CommitSince string `long:"commit-since" description:"Scan commits more recent than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format."`
|
||||||
|
CommitUntil string `long:"commit-until" description:"Scan commits older than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format."`
|
||||||
|
|
||||||
|
Timeout string `long:"timeout" description:"Time allowed per scan. Ex: 10us, 30s, 1m, 1h10m1s"`
|
||||||
|
Depth int `long:"depth" description:"Number of commits to scan"`
|
||||||
|
Deletion bool `long:"include-deletion" description:"Scan for patch deletions in addition to patch additions"`
|
||||||
|
|
||||||
// Hosts
|
// Hosts
|
||||||
Host string `long:"host" description:"git hosting service like gitlab or github. Supported hosts include: Github, Gitlab"`
|
Host string `long:"host" description:"git hosting service like gitlab or github. Supported hosts include: Github, Gitlab"`
|
||||||
|
|||||||
@@ -201,6 +201,10 @@ func getLogOptions(repo *Repo) (*git.LogOptions, error) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if logOpts.From.IsZero() {
|
if logOpts.From.IsZero() {
|
||||||
return nil, fmt.Errorf("could not find branch %s", repo.Manager.Opts.Branch)
|
return nil, fmt.Errorf("could not find branch %s", repo.Manager.Opts.Branch)
|
||||||
}
|
}
|
||||||
@@ -259,6 +263,10 @@ func (repo *Repo) loadRepoConfig() (config.Config, error) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
var tomlLoader config.TomlLoader
|
var tomlLoader config.TomlLoader
|
||||||
_, err = toml.DecodeReader(f, &tomlLoader)
|
_, err = toml.DecodeReader(f, &tomlLoader)
|
||||||
|
if err != nil {
|
||||||
|
return config.Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
return tomlLoader.Parse()
|
return tomlLoader.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-5
@@ -20,11 +20,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
diffAddPrefix = "+"
|
diffAddPrefix = "+"
|
||||||
diffAddFilePrefix = "+++ b"
|
diffAddFilePrefix = "+++ b"
|
||||||
diffAddFilePrefixSlash = "+++ b/"
|
diffAddFilePrefixSlash = "+++ b/"
|
||||||
diffLineSignature = " @@"
|
diffLineSignature = " @@"
|
||||||
defaultLineNumber = -1
|
diffLineSignaturePrefix = "@@ "
|
||||||
|
defaultLineNumber = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckRules accepts bundle and checks each rule defined in the config against the bundle's content.
|
// CheckRules accepts bundle and checks each rule defined in the config against the bundle's content.
|
||||||
@@ -238,6 +239,16 @@ func extractAndInjectLineNumber(leak *manager.Leak, bundle *Bundle, repo *Repo)
|
|||||||
leak.LineNumber = potentialLine
|
leak.LineNumber = potentialLine
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if strings.HasPrefix(txt, diffLineSignaturePrefix) && currStartDiffLine != 0 {
|
||||||
|
// This logic is used for when there are multiple leaks of the same offender within the same patch
|
||||||
|
i := strings.Index(txt, diffAddPrefix)
|
||||||
|
pairs := strings.Split(strings.Split(txt[i+1:], diffLineSignature)[0], ",")
|
||||||
|
currStartDiffLine, err = strconv.Atoi(pairs[0])
|
||||||
|
if err != nil {
|
||||||
|
log.Debug(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
currLine = 0
|
||||||
}
|
}
|
||||||
currLine++
|
currLine++
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-1
@@ -1,9 +1,12 @@
|
|||||||
package scan
|
package scan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -71,11 +74,36 @@ func (repo *Repo) Scan() error {
|
|||||||
|
|
||||||
scanTimeStart := time.Now()
|
scanTimeStart := time.Now()
|
||||||
|
|
||||||
// scan Commit patches OR all files at Commit. See https://github.com/zricethezav/gitleaks/issues/326
|
// See https://github.com/zricethezav/gitleaks/issues/326
|
||||||
|
// Scan commit patches, all files at a commit, or a range of commits
|
||||||
if repo.Manager.Opts.Commit != "" {
|
if repo.Manager.Opts.Commit != "" {
|
||||||
return scanCommit(repo.Manager.Opts.Commit, repo, scanCommitPatches)
|
return scanCommit(repo.Manager.Opts.Commit, repo, scanCommitPatches)
|
||||||
} else if repo.Manager.Opts.FilesAtCommit != "" {
|
} else if repo.Manager.Opts.FilesAtCommit != "" {
|
||||||
return scanCommit(repo.Manager.Opts.FilesAtCommit, repo, scanFilesAtCommit)
|
return scanCommit(repo.Manager.Opts.FilesAtCommit, repo, scanFilesAtCommit)
|
||||||
|
} else if repo.Manager.Opts.Commits != "" {
|
||||||
|
commits := strings.Split(repo.Manager.Opts.Commits, ",")
|
||||||
|
for _, c := range commits {
|
||||||
|
err := scanCommit(c, repo, scanCommitPatches)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else if repo.Manager.Opts.CommitsFile != "" {
|
||||||
|
file, err := os.Open(repo.Manager.Opts.CommitsFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
err := scanCommit(scanner.Text(), repo, scanCommitPatches)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
logOpts, err := getLogOptions(repo)
|
logOpts, err := getLogOptions(repo)
|
||||||
@@ -175,6 +203,9 @@ func (repo *Repo) scanEmpty() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status, err := wt.Status()
|
status, err := wt.Status()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for fn := range status {
|
for fn := range status {
|
||||||
workTreeBuf := bytes.NewBuffer(nil)
|
workTreeBuf := bytes.NewBuffer(nil)
|
||||||
workTreeFile, err := wt.Filesystem.Open(fn)
|
workTreeFile, err := wt.Filesystem.Open(fn)
|
||||||
|
|||||||
+25
-2
@@ -96,16 +96,36 @@ func TestScan(t *testing.T) {
|
|||||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_to.json",
|
wantPath: "../test_data/test_local_repo_two_leaks_commit_to.json",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "test local repo two leaks range Commit",
|
description: "test local repo two leaks to from Commit",
|
||||||
opts: options.Options{
|
opts: options.Options{
|
||||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||||
Report: "../test_data/test_local_repo_two_leaks_commit_range.json.got",
|
Report: "../test_data/test_local_repo_two_leaks_commit_to_from.json.got",
|
||||||
ReportFormat: "json",
|
ReportFormat: "json",
|
||||||
CommitFrom: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a",
|
CommitFrom: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a",
|
||||||
CommitTo: "51f6dcf6b89b93f4075ba92c400b075631a6cc93",
|
CommitTo: "51f6dcf6b89b93f4075ba92c400b075631a6cc93",
|
||||||
},
|
},
|
||||||
|
wantPath: "../test_data/test_local_repo_two_leaks_commit_to_from.json",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "test local repo two leaks list Commits",
|
||||||
|
opts: options.Options{
|
||||||
|
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||||
|
Report: "../test_data/test_local_repo_two_leaks_commit_range.json.got",
|
||||||
|
ReportFormat: "json",
|
||||||
|
Commits: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a,996865bb912f3bc45898a370a13aadb315014b55,17471a5fda722a9e423f1a0d3f0d267ea009d41c,51f6dcf6b89b93f4075ba92c400b075631a6cc93,b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||||
|
},
|
||||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_range.json",
|
wantPath: "../test_data/test_local_repo_two_leaks_commit_range.json",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "test local repo two leaks file list commits",
|
||||||
|
opts: options.Options{
|
||||||
|
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
wantPath: "../test_data/test_local_repo_two_leaks_file_commit_range.json",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "test local repo two leaks globally allowlisted",
|
description: "test local repo two leaks globally allowlisted",
|
||||||
opts: options.Options{
|
opts: options.Options{
|
||||||
@@ -422,6 +442,9 @@ func TestScan(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = m.Report()
|
err = m.Report()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
if test.wantEmpty {
|
if test.wantEmpty {
|
||||||
if len(m.GetLeaks()) != 0 {
|
if len(m.GetLeaks()) != 0 {
|
||||||
|
|||||||
@@ -13,5 +13,20 @@
|
|||||||
"date": "2019-10-25T13:01:27-04:00",
|
"date": "2019-10-25T13:01:27-04:00",
|
||||||
"tags": "key, AWS",
|
"tags": "key, AWS",
|
||||||
"operation": "addition"
|
"operation": "addition"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||||
|
"lineNumber": 3,
|
||||||
|
"offender": "AKIALALEMEL33243OLIA",
|
||||||
|
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||||
|
"repo": "test_repo_2",
|
||||||
|
"rule": "AWS Manager ID",
|
||||||
|
"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",
|
||||||
|
"operation": "addition"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||||
|
"lineNumber": 5,
|
||||||
|
"offender": "AKIALALEMEL33243OLIA",
|
||||||
|
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||||
|
"repo": "test_repo_2",
|
||||||
|
"rule": "AWS Manager ID",
|
||||||
|
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||||
|
"author": "zach rice",
|
||||||
|
"email": "zricer@protonmail.com",
|
||||||
|
"file": "secrets.md",
|
||||||
|
"date": "2019-10-25T13:01:27-04:00",
|
||||||
|
"tags": "key, AWS",
|
||||||
|
"operation": "addition"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||||
|
"lineNumber": 5,
|
||||||
|
"offender": "AKIALALEMEL33243OLIA",
|
||||||
|
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||||
|
"repo": "test_repo_2",
|
||||||
|
"rule": "AWS Manager ID",
|
||||||
|
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||||
|
"author": "zach rice",
|
||||||
|
"email": "zricer@protonmail.com",
|
||||||
|
"file": "secrets.md",
|
||||||
|
"date": "2019-10-25T13:01:27-04:00",
|
||||||
|
"tags": "key, AWS",
|
||||||
|
"operation": "addition"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||||
|
"lineNumber": 3,
|
||||||
|
"offender": "AKIALALEMEL33243OLIA",
|
||||||
|
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||||
|
"repo": "test_repo_2",
|
||||||
|
"rule": "AWS Manager ID",
|
||||||
|
"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",
|
||||||
|
"operation": "addition"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
d8ac0b73aeeb45843319cdc5ce506516eb49bf7a
|
||||||
|
996865bb912f3bc45898a370a13aadb315014b55
|
||||||
|
17471a5fda722a9e423f1a0d3f0d267ea009d41c
|
||||||
|
51f6dcf6b89b93f4075ba92c400b075631a6cc93
|
||||||
|
b10b3e2cb320a8c211fda94c4567299d37de7776
|
||||||
Reference in new issue
Block a user