mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-26 19:30:55 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef38b69c39 | ||
|
|
ac6bde9996 | ||
|
|
23568cc0ba | ||
|
|
e61c2cfae7 | ||
|
|
38e0b11995 | ||
|
|
31903d1a80 | ||
|
|
3655284b57 | ||
|
|
db79a96118 | ||
|
|
5152e1fc63 | ||
|
|
c04e137b28 | ||
|
|
9b3342fbff | ||
|
|
d9a060a12d | ||
|
|
77f2fdd09a | ||
|
|
dba1ef6104 |
No files matched your search
+42
-10
@@ -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
@@ -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"
|
||||
}
|
||||
]
|
||||
Reference in new issue
Block a user