Compare commits

...
14 Commits
Author SHA1 Message Date
Zachary Rice ef38b69c39 Merge pull request #302 from petegallagher/whitelist-gitleaks.toml
Update default whitelist to include gitleaks.toml
2019-11-30 09:44:23 -06:00
Zachary Rice ac6bde9996 Merge pull request #296 from petegallagher/private-key
Update asymmetric private key regex
2019-11-30 09:41:35 -06:00
Zachary Rice 23568cc0ba Merge pull request #295 from petegallagher/sendgrid
Adding regex for SendGrid API keys
2019-11-30 09:41:10 -06:00
Zachary Rice e61c2cfae7 Merge pull request #301 from petegallagher/AuditUncommitted
Fix repo-config and file whitelist for AuditUncommitted function
2019-11-30 09:40:24 -06:00
Peter Gallagher 38e0b11995 Fix test data for AuditUncommitted 2019-11-29 10:22:02 +00:00
Peter Gallagher 31903d1a80 Update default whitelist to include gitleaks.toml 2019-11-29 10:14:03 +00:00
Peter Gallagher 3655284b57 Fix test data for AuditUncommitted 2019-11-29 10:07:56 +00:00
Peter Gallagher db79a96118 Use Unix Epoch time for staged commit time 2019-11-29 10:07:27 +00:00
Peter Gallagher999 5152e1fc63 Reset commit values when auditing uncommitted changes 2019-11-28 23:13:59 +00:00
Peter Gallagher c04e137b28 Adding global file regex to AuditUncommitted 2019-11-28 22:53:08 +00:00
Peter Gallagher 9b3342fbff Allow use of --repo-config for AuditUncommitted function 2019-11-28 13:53:52 +00:00
Peter Gallagher d9a060a12d Honour file whitelist for AuditUncommitted function 2019-11-28 13:53:18 +00:00
Peter Gallagher 77f2fdd09a Update asymmetric private key regex 2019-11-25 15:59:40 +00:00
Peter Gallagher dba1ef6104 Adding regex for SendGrid API keys 2019-11-25 15:49:47 +00:00
3 changed files with 57 additions and 20 deletions

No files matched your search

+42 -10
View File
@@ -84,6 +84,15 @@ func (repo *Repo) Clone(cloneOption *git.CloneOptions) error {
// AuditUncommitted will do a `git diff` and scan changed files that are being tracked. This is useful functionality
// for a pre-commit hook so you can make sure your code does not have any leaks before committing.
func (repo *Repo) AuditUncommitted() error {
// load up alternative config if possible, if not use manager's config
if repo.Manager.Opts.RepoConfig {
cfg, err := repo.loadRepoConfig()
if err != nil {
return err
}
repo.config = cfg
}
auditTimeStart := time.Now()
r, err := repo.Head()
@@ -95,6 +104,12 @@ func (repo *Repo) AuditUncommitted() error {
if err != nil {
return err
}
// Staged change so the commit details do not yet exist. Insert empty defaults.
c.Hash = plumbing.Hash{}
c.Message = "***STAGED CHANGES***"
c.Author.Name = ""
c.Author.Email = ""
c.Author.When = time.Unix(0, 0).UTC()
prevTree, err := c.Tree()
if err != nil {
@@ -146,18 +161,35 @@ func (repo *Repo) AuditUncommitted() error {
}
}
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(prevFileContents, currFileContents, false)
var diffContents string
for _, d := range diffs {
switch d.Type {
case diffmatchpatch.DiffInsert:
diffContents += fmt.Sprintf("%s\n", d.Text)
case diffmatchpatch.DiffDelete:
diffContents += fmt.Sprintf("%s\n", d.Text)
if fileMatched(filename, repo.config.Whitelist.File) {
log.Debugf("whitelisted file found, skipping audit of file: %s", filename)
} else if fileMatched(filename, repo.config.FileRegex) {
repo.Manager.SendLeaks(manager.Leak{
Line: "N/A",
Offender: filename,
Commit: c.Hash.String(),
Repo: repo.Name,
Rule: "file regex matched" + repo.config.FileRegex.String(),
Message: c.Message,
Author: c.Author.Name,
Email: c.Author.Email,
Date: c.Author.When,
File: filename,
})
} else {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(prevFileContents, currFileContents, false)
var diffContents string
for _, d := range diffs {
switch d.Type {
case diffmatchpatch.DiffInsert:
diffContents += fmt.Sprintf("%s\n", d.Text)
case diffmatchpatch.DiffDelete:
diffContents += fmt.Sprintf("%s\n", d.Text)
}
}
InspectString(diffContents, c, repo, filename)
}
InspectString(diffContents, c, repo, filename)
}
}
+10 -5
View File
@@ -62,9 +62,9 @@ title = "gitleaks config"
tags = ["key", "Slack"]
[[rules]]
description = "EC"
regex = '''-----BEGIN EC PRIVATE KEY-----'''
tags = ["key", "EC"]
description = "Asymmetric Private Key"
regex = '''-----BEGIN (EC|PGP|DSA|RSA|OPENSSH) PRIVATE KEY( BLOCK)?-----'''
tags = ["key", "AsymmetricPrivateKey"]
[[rules]]
description = "Generic Credential"
@@ -102,6 +102,11 @@ title = "gitleaks config"
regex = '''sk_live_[0-9a-z]{32}'''
tags = ["key", "Picatic"]
[[rules]]
description = "SendGrid API Key"
regex = '''SG\.[\w_]{16,32}\.[\w_]{16,64}'''
tags = ["key", "SendGrid"]
[[rules]]
description = "Slack Webhook"
regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}'''
@@ -128,6 +133,6 @@ title = "gitleaks config"
tags = ["key", "twilio"]
[whitelist]
description = "image whitelists"
file = '''(.*?)(jpg|gif|doc|pdf|bin)$'''
description = "Whitelisted files"
file = '''(^\.?gitleaks.toml$|(.*?)(jpg|gif|doc|pdf|bin)$)'''
`
@@ -2,14 +2,14 @@
{
"line": " aws_access_key_id='AKIAIO5FODNN7DXAMPLE'",
"offender": "AKIAIO5FODNN7DXAMPLE",
"commit": "d274003914c707212cbe84e3e466a00013ccb639",
"commit": "0000000000000000000000000000000000000000",
"repo": "test_repo_1",
"rule": "AWS Manager ID",
"commitMessage": "comment\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"commitMessage": "***STAGED CHANGES***",
"author": "",
"email": "",
"file": "server.test.py",
"date": "2019-10-24T10:03:38-04:00",
"date": "1970-01-01T00:00:00Z",
"tags": "key, AWS"
}
]