mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2baa9e675 | ||
|
|
7fa9c802f5 | ||
|
|
8f1bc74e26 | ||
|
|
8de38be418 | ||
|
|
ec1ebd4686 | ||
|
|
81ddfbed88 | ||
|
|
63814f1eaf | ||
|
|
38a36add57 | ||
|
|
9e39927ac6 | ||
|
|
0ba9dda0f0 | ||
|
|
a24f9a2c92 | ||
|
|
f57158a893 | ||
|
|
1e3bf42464 | ||
|
|
9d6a75fbab | ||
|
|
6fa52ae7cc | ||
|
|
bb9c459a1a | ||
|
|
777601a0ea | ||
|
|
35d170018e | ||
|
|
af2e99ef45 | ||
|
|
734befb555 | ||
|
|
64c8d618a2 | ||
|
|
92bb4ea6fc | ||
|
|
98b025da72 | ||
|
|
af7717412f | ||
|
|
68c2a18f6f | ||
|
|
ea49078ffd | ||
|
|
b902d7310a | ||
|
|
3591560b34 | ||
|
|
949029ca89 | ||
|
|
cde0894711 | ||
|
|
342e9f80db | ||
|
|
96b0f4aab7 | ||
|
|
3af6a546ac | ||
|
|
6e086c4297 |
No files matched your search
@@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.22.0
|
||||||
|
----
|
||||||
|
- context inclusion for redactions
|
||||||
|
- noise reduction for entropy signals
|
||||||
|
|
||||||
1.21.0
|
1.21.0
|
||||||
----
|
----
|
||||||
- added support for cloning repositories using github api
|
- added support for cloning repositories using github api
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="gitleaks" src="https://raw.githubusercontent.com/zricethezav/gifs/master/gitleaks5.png" height="140" />
|
<img alt="gitleaks" src="https://raw.githubusercontent.com/zricethezav/gifs/master/gitleaksnew2.gif"/>
|
||||||
<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>
|
||||||
</p>
|
</p>
|
||||||
@@ -33,7 +33,7 @@ It has been sucessfully used in a number of different scenarios, including;
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
#### 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). Alternatively, executed via Docker or it can be installed using Go directly, as per the below;
|
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, as per the below;
|
||||||
|
|
||||||
##### Docker
|
##### Docker
|
||||||
|
|
||||||
@@ -63,30 +63,32 @@ Usage:
|
|||||||
gitleaks [OPTIONS]
|
gitleaks [OPTIONS]
|
||||||
|
|
||||||
Application Options:
|
Application Options:
|
||||||
-r, --repo= Repo url to audit
|
-r, --repo= Repo url to audit
|
||||||
--github-user= Github user to audit
|
--github-user= Github user to audit
|
||||||
--github-org= Github organization to audit
|
--github-org= Github organization to audit
|
||||||
--github-url= GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/ (default: https://api.github.com/)
|
--github-url= GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/ (default: https://api.github.com/)
|
||||||
--github-pr= Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set
|
--github-pr= Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set
|
||||||
--gitlab-user= GitLab user ID to audit
|
--gitlab-user= GitLab user ID to audit
|
||||||
--gitlab-org= GitLab group ID to audit
|
--gitlab-org= GitLab group ID to audit
|
||||||
-c, --commit= sha of commit to stop at
|
-c, --commit= sha of commit to stop at
|
||||||
--depth= maximum commit depth
|
--depth= maximum commit depth
|
||||||
--repo-path= Path to repo
|
--repo-path= Path to repo
|
||||||
--owner-path= Path to owner directory (repos discovered)
|
--owner-path= Path to owner directory (repos discovered)
|
||||||
--threads= Maximum number of threads gitleaks spawns
|
--threads= Maximum number of threads gitleaks spawns
|
||||||
--disk Clones repo(s) to disk
|
--disk Clones repo(s) to disk
|
||||||
--single-search= single regular expression to search for
|
--single-search= single regular expression to search for
|
||||||
--config= path to gitleaks config
|
--config= path to gitleaks config
|
||||||
--ssh-key= path to ssh key
|
--ssh-key= path to ssh key
|
||||||
--exclude-forks exclude forks for organization/user audits
|
--exclude-forks exclude forks for organization/user audits
|
||||||
-e, --entropy= Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)
|
-e, --entropy= Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)
|
||||||
-l, --log= log level
|
--noise-reduction Reduce the number of finds when entropy checks are enabled
|
||||||
-v, --verbose Show verbose output from gitleaks audit
|
--repo-config Load config from target repo. Config file must be ".gitleaks.toml"
|
||||||
--report= path to write report file
|
-l, --log= log level
|
||||||
--redact redact secrets from log messages and report
|
-v, --verbose Show verbose output from gitleaks audit
|
||||||
--version version number
|
--report= path to write report file
|
||||||
--sample-config prints a sample config file
|
--redact redact secrets from log messages and report
|
||||||
|
--version version number
|
||||||
|
--sample-config prints a sample config file
|
||||||
|
|
||||||
Help Options:
|
Help Options:
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
@@ -127,6 +129,8 @@ From C-U at Home:
|
|||||||
|
|
||||||
<b>Donate</b>: https://www.cuathome.us/give/
|
<b>Donate</b>: https://www.cuathome.us/give/
|
||||||
|
|
||||||
|
#### Speaking of Community
|
||||||
|
Please read this https://corruptcu.com/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -51,6 +51,21 @@ func auditGithubPR() ([]Leak, error) {
|
|||||||
}
|
}
|
||||||
files := commit.Files
|
files := commit.Files
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
|
skipFile := false
|
||||||
|
if f.Patch == nil || f.Filename == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, re := range whiteListFiles {
|
||||||
|
if re.FindString(f.GetFilename()) != "" {
|
||||||
|
log.Infof("skipping whitelisted file (matched regex '%s'): %s", re.String(), f.GetFilename())
|
||||||
|
skipFile = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if skipFile {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
diff := gitDiff{
|
diff := gitDiff{
|
||||||
sha: commit.GetSHA(),
|
sha: commit.GetSHA(),
|
||||||
content: *f.Patch,
|
content: *f.Patch,
|
||||||
@@ -59,6 +74,7 @@ func auditGithubPR() ([]Leak, error) {
|
|||||||
githubCommit: commit,
|
githubCommit: commit,
|
||||||
author: commit.GetCommitter().GetLogin(),
|
author: commit.GetCommitter().GetLogin(),
|
||||||
message: *commit.Commit.Message,
|
message: *commit.Commit.Message,
|
||||||
|
date: *commit.Commit.Committer.Date,
|
||||||
}
|
}
|
||||||
leaks = append(leaks, inspect(diff)...)
|
leaks = append(leaks, inspect(diff)...)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -21,19 +21,19 @@ regex = '''(?i)facebook.*['\"][0-9a-f]{32}['\"]'''
|
|||||||
description = "Twitter"
|
description = "Twitter"
|
||||||
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "Telegram"
|
|
||||||
regex = '''(?i)telegram.*['\"][0-9]{1,12}+:[0-9a-zA-Z-]{32,44}['\"]'''
|
|
||||||
[[regexes]]
|
|
||||||
description = "PGP"
|
description = "PGP"
|
||||||
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "Slack token"
|
description = "Slack token"
|
||||||
regex = '''xox[baprs]-.*'''
|
regex = '''xox[baprs]-.*'''
|
||||||
|
[[regexes]]
|
||||||
|
description = "Strip API Key"
|
||||||
|
regex = '''(?i)(sk|pk)_(test|live)_[0-9a-zA-Z]{10,32}'''
|
||||||
|
|
||||||
[whitelist]
|
[whitelist]
|
||||||
regexes = [
|
regexes = [
|
||||||
# "AKIA.*EXAMPLE",
|
# "AKIA.*EXAMPLE",
|
||||||
]
|
]
|
||||||
files = [
|
files = [
|
||||||
"(.*?)(jpg|gif|doc|pdf|bin|go)$"
|
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||||
]
|
]
|
||||||
@@ -311,6 +311,15 @@ func TestRun(t *testing.T) {
|
|||||||
regexp.MustCompile("main.go"),
|
regexp.MustCompile("main.go"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testOpts: Options{
|
||||||
|
GithubPR: "https://github.com/gitleakstest/gronit/pull/2",
|
||||||
|
},
|
||||||
|
description: "test github pr with commits without patch info",
|
||||||
|
numLeaks: 0,
|
||||||
|
expectedErrMsg: "",
|
||||||
|
commitPerPage: 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
g := goblin.Goblin(t)
|
g := goblin.Goblin(t)
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -480,6 +489,14 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
whiteListRegexes []*regexp.Regexp
|
whiteListRegexes []*regexp.Regexp
|
||||||
configPath string
|
configPath string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
repo: leaksRepo,
|
||||||
|
description: "pinned config",
|
||||||
|
numLeaks: 0,
|
||||||
|
testOpts: Options{
|
||||||
|
RepoConfig: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "commit depth = 1, one leak",
|
description: "commit depth = 1, one leak",
|
||||||
@@ -583,6 +600,15 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
},
|
},
|
||||||
numLeaks: 6,
|
numLeaks: 6,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
repo: leaksRepo,
|
||||||
|
description: "leaks present with entropy",
|
||||||
|
testOpts: Options{
|
||||||
|
Entropy: 4.7,
|
||||||
|
NoiseReduction: true,
|
||||||
|
},
|
||||||
|
numLeaks: 2,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "Audit until specific commit",
|
description: "Audit until specific commit",
|
||||||
@@ -605,6 +631,15 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
numLeaks: 298,
|
numLeaks: 298,
|
||||||
configPath: path.Join(configsDir, "entropy"),
|
configPath: path.Join(configsDir, "entropy"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
repo: leaksRepo,
|
||||||
|
testOpts: Options{
|
||||||
|
NoiseReduction: true,
|
||||||
|
},
|
||||||
|
description: "toml entropy range",
|
||||||
|
numLeaks: 58,
|
||||||
|
configPath: path.Join(configsDir, "entropy"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "toml bad entropy range",
|
description: "toml bad entropy range",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing"
|
"gopkg.in/src-d/go-git.v4/plumbing"
|
||||||
|
|
||||||
|
diffType "gopkg.in/src-d/go-git.v4/plumbing/format/diff"
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
|
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
|
||||||
"gopkg.in/src-d/go-git.v4/storage/memory"
|
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||||
@@ -30,9 +31,9 @@ import (
|
|||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
"github.com/hako/durafmt"
|
"github.com/hako/durafmt"
|
||||||
flags "github.com/jessevdk/go-flags"
|
"github.com/jessevdk/go-flags"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
git "gopkg.in/src-d/go-git.v4"
|
"gopkg.in/src-d/go-git.v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Leak represents a leaked secret or regex match.
|
// Leak represents a leaked secret or regex match.
|
||||||
@@ -77,13 +78,15 @@ type Options struct {
|
|||||||
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
|
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
|
||||||
|
|
||||||
// Process options
|
// Process options
|
||||||
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
|
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
|
||||||
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
||||||
SingleSearch string `long:"single-search" description:"single regular expression to search for"`
|
SingleSearch string `long:"single-search" description:"single regular expression to search for"`
|
||||||
ConfigPath string `long:"config" description:"path to gitleaks config"`
|
ConfigPath string `long:"config" description:"path to gitleaks config"`
|
||||||
SSHKey string `long:"ssh-key" description:"path to ssh key"`
|
SSHKey string `long:"ssh-key" description:"path to ssh key"`
|
||||||
ExcludeForks bool `long:"exclude-forks" description:"exclude forks for organization/user audits"`
|
ExcludeForks bool `long:"exclude-forks" description:"exclude forks for organization/user audits"`
|
||||||
Entropy float64 `long:"entropy" short:"e" description:"Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)"`
|
Entropy float64 `long:"entropy" short:"e" description:"Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)"`
|
||||||
|
NoiseReduction bool `long:"noise-reduction" description:"Reduce the number of finds when entropy checks are enabled"`
|
||||||
|
RepoConfig bool `long:"repo-config" description:"Load config from target repo. Config file must be \".gitleaks.toml\""`
|
||||||
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
||||||
|
|
||||||
// Output options
|
// Output options
|
||||||
@@ -101,6 +104,9 @@ type Config struct {
|
|||||||
Description string
|
Description string
|
||||||
Regex string
|
Regex string
|
||||||
}
|
}
|
||||||
|
Entropy struct {
|
||||||
|
LineRegexes []string
|
||||||
|
}
|
||||||
Whitelist struct {
|
Whitelist struct {
|
||||||
Files []string
|
Files []string
|
||||||
Regexes []string
|
Regexes []string
|
||||||
@@ -130,7 +136,7 @@ type entropyRange struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultGithubURL = "https://api.github.com/"
|
const defaultGithubURL = "https://api.github.com/"
|
||||||
const version = "1.21.0"
|
const version = "1.23.0"
|
||||||
const errExit = 2
|
const errExit = 2
|
||||||
const leakExit = 1
|
const leakExit = 1
|
||||||
const defaultConfig = `
|
const defaultConfig = `
|
||||||
@@ -169,6 +175,21 @@ regex = '''(?i)github(.{0,4})?['\"][0-9a-zA-Z]{35,40}['\"]'''
|
|||||||
description = "Slack"
|
description = "Slack"
|
||||||
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||||
|
|
||||||
|
[entropy]
|
||||||
|
lineregexes = [
|
||||||
|
"api",
|
||||||
|
"key",
|
||||||
|
"signature",
|
||||||
|
"secret",
|
||||||
|
"password",
|
||||||
|
"pass",
|
||||||
|
"pwd",
|
||||||
|
"token",
|
||||||
|
"curl",
|
||||||
|
"wget",
|
||||||
|
"https?",
|
||||||
|
]
|
||||||
|
|
||||||
[whitelist]
|
[whitelist]
|
||||||
files = [
|
files = [
|
||||||
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||||
@@ -196,6 +217,7 @@ var (
|
|||||||
whiteListCommits map[string]bool
|
whiteListCommits map[string]bool
|
||||||
whiteListRepos []*regexp.Regexp
|
whiteListRepos []*regexp.Regexp
|
||||||
entropyRanges []entropyRange
|
entropyRanges []entropyRange
|
||||||
|
entropyRegexes []*regexp.Regexp
|
||||||
fileDiffRegex *regexp.Regexp
|
fileDiffRegex *regexp.Regexp
|
||||||
sshAuth *ssh.PublicKeys
|
sshAuth *ssh.PublicKeys
|
||||||
dir string
|
dir string
|
||||||
@@ -325,6 +347,10 @@ func run() ([]Leak, error) {
|
|||||||
// writeReport writes a report to a file specified in the --report= option.
|
// writeReport writes a report to a file specified in the --report= option.
|
||||||
// Default format for report is JSON. You can use the --csv option to write the report as a csv
|
// Default format for report is JSON. You can use the --csv option to write the report as a csv
|
||||||
func writeReport(leaks []Leak) error {
|
func writeReport(leaks []Leak) error {
|
||||||
|
if len(leaks) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
log.Infof("writing report to %s", opts.Report)
|
log.Infof("writing report to %s", opts.Report)
|
||||||
if strings.HasSuffix(opts.Report, ".csv") {
|
if strings.HasSuffix(opts.Report, ".csv") {
|
||||||
@@ -340,8 +366,41 @@ func writeReport(leaks []Leak) error {
|
|||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
} else {
|
} else {
|
||||||
reportJSON, _ := json.MarshalIndent(leaks, "", "\t")
|
var (
|
||||||
err = ioutil.WriteFile(opts.Report, reportJSON, 0644)
|
f *os.File
|
||||||
|
encoder *json.Encoder
|
||||||
|
)
|
||||||
|
f, err := os.Create(opts.Report)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
encoder = json.NewEncoder(f)
|
||||||
|
encoder.SetIndent("", "\t")
|
||||||
|
if _, err := f.WriteString("[\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i := 0; i < len(leaks); i++ {
|
||||||
|
if err := encoder.Encode(leaks[i]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// for all but the last leak, seek back and overwrite the newline appended by Encode() with comma & newline
|
||||||
|
if i+1 < len(leaks) {
|
||||||
|
if _, err := f.Seek(-1, 1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := f.WriteString(",\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := f.WriteString("]"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := f.Sync(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -412,6 +471,14 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if target contains an external gitleaks toml
|
||||||
|
if opts.RepoConfig {
|
||||||
|
err := externalConfig(repo)
|
||||||
|
if err != nil {
|
||||||
|
return leaks, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// clear commit cache
|
// clear commit cache
|
||||||
commitMap = make(map[string]bool)
|
commitMap = make(map[string]bool)
|
||||||
|
|
||||||
@@ -432,6 +499,29 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
return leaks, err
|
return leaks, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// externalConfig will attempt to load a pinned ".gitleaks.toml" configuration file
|
||||||
|
// from a remote or local repo. Use the --repo-config option to trigger this.
|
||||||
|
func externalConfig(repo *RepoDescriptor) error {
|
||||||
|
var config Config
|
||||||
|
wt, err := repo.repository.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f, err := wt.Filesystem.Open(".gitleaks.toml")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := toml.DecodeReader(f, &config); err != nil {
|
||||||
|
return fmt.Errorf("problem loading config: %v", err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateConfig(config)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// auditGitReference beings the audit for a git reference. This function will
|
// auditGitReference beings the audit for a git reference. This function will
|
||||||
// traverse the git reference and audit each line of each diff.
|
// traverse the git reference and audit each line of each diff.
|
||||||
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
||||||
@@ -488,6 +578,12 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
if bin || err != nil {
|
if bin || err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
for _, re := range whiteListFiles {
|
||||||
|
if re.FindString(f.Name) != "" {
|
||||||
|
log.Debugf("skipping whitelisted file (matched regex '%s'): %s", re.String(), f.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
content, err := f.Contents()
|
content, err := f.Contents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -535,7 +631,7 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
commitWg.Done()
|
commitWg.Done()
|
||||||
<-semaphore
|
<-semaphore
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Warnf("recoverying from panic on commit %s, likely large diff causing panic", c.Hash.String())
|
log.Warnf("recovering from panic on commit %s, likely large diff causing panic", c.Hash.String())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
patch, err := c.Patch(parent)
|
patch, err := c.Patch(parent)
|
||||||
@@ -555,12 +651,19 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
} else if to != nil {
|
} else if to != nil {
|
||||||
filePath = to.Path()
|
filePath = to.Path()
|
||||||
}
|
}
|
||||||
|
for _, re := range whiteListFiles {
|
||||||
|
if re.FindString(filePath) != "" {
|
||||||
|
log.Debugf("skipping whitelisted file (matched regex '%s'): %s", re.String(), filePath)
|
||||||
|
skipFile = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if skipFile {
|
if skipFile {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
chunks := f.Chunks()
|
chunks := f.Chunks()
|
||||||
for _, chunk := range chunks {
|
for _, chunk := range chunks {
|
||||||
if chunk.Type() == 1 || chunk.Type() == 2 {
|
if chunk.Type() == diffType.Add || chunk.Type() == diffType.Delete {
|
||||||
diff := gitDiff{
|
diff := gitDiff{
|
||||||
repoName: repoName,
|
repoName: repoName,
|
||||||
filePath: filePath,
|
filePath: filePath,
|
||||||
@@ -598,12 +701,6 @@ func inspect(diff gitDiff) []Leak {
|
|||||||
skipLine bool
|
skipLine bool
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, re := range whiteListFiles {
|
|
||||||
if re.FindString(diff.filePath) != "" {
|
|
||||||
return leaks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lines := strings.Split(diff.content, "\n")
|
lines := strings.Split(diff.content, "\n")
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
@@ -613,47 +710,44 @@ func inspect(diff gitDiff) []Leak {
|
|||||||
if match == "" {
|
if match == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if skipLine = isLineWhitelisted(line); skipLine {
|
||||||
// if offender matches whitelist regex, ignore it
|
|
||||||
for _, wRe := range whiteListRegexes {
|
|
||||||
whitelistMatch := wRe.FindString(line)
|
|
||||||
if whitelistMatch != "" {
|
|
||||||
skipLine = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if skipLine {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
leaks = addLeak(leaks, line, match, leakType, diff)
|
leaks = addLeak(leaks, line, match, leakType, diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Entropy > 0 || len(entropyRanges) != 0 {
|
if !skipLine && (opts.Entropy > 0 || len(entropyRanges) != 0) {
|
||||||
entropyLeak := false
|
|
||||||
words := strings.Fields(line)
|
words := strings.Fields(line)
|
||||||
for _, word := range words {
|
for _, word := range words {
|
||||||
entropy := getShannonEntropy(word)
|
entropy := getShannonEntropy(word)
|
||||||
if entropy >= opts.Entropy && len(entropyRanges) == 0 {
|
// Only check entropyRegexes and whiteListRegexes once per line, and only if an entropy leak type
|
||||||
entropyLeak = true
|
// was found above, since regex checks are expensive.
|
||||||
|
if !entropyIsHighEnough(entropy) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if len(entropyRanges) != 0 {
|
// If either the line is whitelisted or the line fails the noiseReduction check (when enabled),
|
||||||
for _, eR := range entropyRanges {
|
// then we can skip checking the rest of the line for high entropy words.
|
||||||
if entropy > eR.v1 && entropy < eR.v2 {
|
if skipLine = !highEntropyLineIsALeak(line) || isLineWhitelisted(line); skipLine {
|
||||||
entropyLeak = true
|
break
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if entropyLeak {
|
|
||||||
leaks = addLeak(leaks, line, word, fmt.Sprintf("Entropy: %.2f", entropy), diff)
|
|
||||||
entropyLeak = false
|
|
||||||
}
|
}
|
||||||
|
leaks = addLeak(leaks, line, word, fmt.Sprintf("Entropy: %.2f", entropy), diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return leaks
|
return leaks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isLineWhitelisted returns true iff the line is matched by at least one of the whiteListRegexes.
|
||||||
|
func isLineWhitelisted(line string) bool {
|
||||||
|
for _, wRe := range whiteListRegexes {
|
||||||
|
whitelistMatch := wRe.FindString(line)
|
||||||
|
if whitelistMatch != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// addLeak is helper for func inspect() to append leaks if found during a diff check.
|
// addLeak is helper for func inspect() to append leaks if found during a diff check.
|
||||||
func addLeak(leaks []Leak, line string, offender string, leakType string, diff gitDiff) []Leak {
|
func addLeak(leaks []Leak, line string, offender string, leakType string, diff gitDiff) []Leak {
|
||||||
leak := Leak{
|
leak := Leak{
|
||||||
@@ -669,7 +763,7 @@ func addLeak(leaks []Leak, line string, offender string, leakType string, diff g
|
|||||||
}
|
}
|
||||||
if opts.Redact {
|
if opts.Redact {
|
||||||
leak.Offender = "REDACTED"
|
leak.Offender = "REDACTED"
|
||||||
leak.Line = "REDACTED"
|
leak.Line = strings.Replace(line, offender, "REDACTED", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Verbose {
|
if opts.Verbose {
|
||||||
@@ -700,6 +794,36 @@ func getShannonEntropy(data string) (entropy float64) {
|
|||||||
return entropy
|
return entropy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func entropyIsHighEnough(entropy float64) bool {
|
||||||
|
if entropy >= opts.Entropy && len(entropyRanges) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(entropyRanges) != 0 {
|
||||||
|
for _, eR := range entropyRanges {
|
||||||
|
if entropy > eR.v1 && entropy < eR.v2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func highEntropyLineIsALeak(line string) bool {
|
||||||
|
if !opts.NoiseReduction {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, re := range entropyRegexes {
|
||||||
|
if re.FindString(line) != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// discoverRepos walks all the children of `path`. If a child directory
|
// discoverRepos walks all the children of `path`. If a child directory
|
||||||
// contain a .git file then that repo will be added to the list of repos returned
|
// contain a .git file then that repo will be added to the list of repos returned
|
||||||
func discoverRepos(ownerPath string) ([]*RepoDescriptor, error) {
|
func discoverRepos(ownerPath string) ([]*RepoDescriptor, error) {
|
||||||
@@ -835,6 +959,11 @@ func loadToml() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return updateConfig(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateConfig will update a the global config values
|
||||||
|
func updateConfig(config Config) error {
|
||||||
if len(config.Misc.Entropy) != 0 {
|
if len(config.Misc.Entropy) != 0 {
|
||||||
err := entropyLimits(config.Misc.Entropy)
|
err := entropyLimits(config.Misc.Entropy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -842,6 +971,10 @@ func loadToml() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, regex := range config.Entropy.LineRegexes {
|
||||||
|
entropyRegexes = append(entropyRegexes, regexp.MustCompile(regex))
|
||||||
|
}
|
||||||
|
|
||||||
if singleSearchRegex != nil {
|
if singleSearchRegex != nil {
|
||||||
regexes["singleSearch"] = singleSearchRegex
|
regexes["singleSearch"] = singleSearchRegex
|
||||||
} else {
|
} else {
|
||||||
@@ -864,6 +997,7 @@ func loadToml() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// entropyLimits hydrates entropyRanges which allows for fine tuning entropy checking
|
// entropyLimits hydrates entropyRanges which allows for fine tuning entropy checking
|
||||||
|
|||||||
Reference in new issue
Block a user