Compare commits

...
16 Commits
Author SHA1 Message Date
zricethezav ede68fd95d fix off by one 2020-09-02 08:36:19 -04:00
Zachary Rice 6c60c3dde3 Adding some logic to fix line number extractor when there are multipl… (#436)
* Adding some logic to fix line number extractor when there are multiple secrets of the same offender within the same patch

* formatting some consts
2020-09-01 20:48:43 -04:00
Zachary Rice ad505754fc Add commits and commits-file option (#433) 2020-08-31 10:29:04 -04:00
Zachary Rice 21d81879e2 Update README.md 2020-08-27 14:11:11 -04:00
Lars Lehtonen b5ca2ba614 scan: fix dropped errors (#424) 2020-08-20 15:42:42 -04:00
Zachary Rice ef4655fcf1 Sarif (#421)
* init

* more work

* more sarif work

* mergin
2020-08-12 18:07:24 -04:00
Zachary Rice 01b553a75d Update Makefile 2020-08-12 17:51:56 -04:00
Zachary Rice fae366a404 Global allowlist regex (#422)
* work in progress

* Update test configs

* adding test

* golint and change to allowlist

* fix race condition, this mistakenly got committed

* Updating tests and examples

* bump to v6 as this is a breaking change to the config

* More consistent variables
2020-08-12 17:18:25 -04:00
Lars Lehtonen 6129b1a15d hosts: dropped error (#417) 2020-07-31 08:45:47 -04:00
Manuel Jeckelmann 31d03a1146 Clean up 'uncommitted' diff. (#416) 2020-07-28 08:55:33 -04:00
Zachary Rice eabc7b5c12 Fixing merge commit scans and large patch rule checking (#414)
* Fixing merge commit scans and large patch rule checking

* Adding tests for merge request scans
2020-07-25 14:55:59 -04:00
zricethezav 1dc7569f95 removing extra log import... 2020-07-24 14:42:54 -04:00
zricethezav 1797e9c966 Merge branch 'master' of github.com:zricethezav/gitleaks 2020-07-24 14:07:25 -04:00
zricethezav e2eaceb4cd rm bad example config 2020-07-24 14:07:00 -04:00
Zachary Rice c637b129ec Validate config (#412)
* validate config

* fix import fmt

* cleaning
2020-07-24 14:02:48 -04:00
zricethezav 8470e43d7f validate config 2020-07-24 13:54:01 -04:00
121 changed files with 1183 additions and 383 deletions

No files matched your search

+2 -2
View File
@@ -2,8 +2,8 @@
VERSION := `git fetch --tags && git tag | sort -V | tail -1` VERSION := `git fetch --tags && git tag | sort -V | tail -1`
PKG=github.com/zricethezav/gitleaks PKG=github.com/zricethezav/gitleaks
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v5/version.Version=$(VERSION)" LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v6/version.Version=$(VERSION)"
_LDFLAGS="github.com/zricethezav/gitleaks/v5/version.Version=$(VERSION)" _LDFLAGS="github.com/zricethezav/gitleaks/v6/version.Version=$(VERSION)"
COVER=--cover --coverprofile=cover.out COVER=--cover --coverprofile=cover.out
test-cover: test-cover:
+2 -2
View File
@@ -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:
[![Adam Shannon](https://github.com/adamdecaf.png?size=50)](https://github.com/adamdecaf) | [![Granville Schmidt](https://github.com/gramidt.png?size=50)](https://github.com/gramidt) | [![Adam Shannon](https://github.com/adamdecaf.png?size=50)](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>.
+93 -73
View File
@@ -6,18 +6,21 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
log "github.com/sirupsen/logrus"
) )
// 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 {
Description string Description string
Regex *regexp.Regexp Regexes []*regexp.Regexp
File *regexp.Regexp Commits []string
Path *regexp.Regexp Files []*regexp.Regexp
Paths []*regexp.Regexp
Repos []*regexp.Regexp
} }
// Entropy represents an entropy range // Entropy represents an entropy range
@@ -33,56 +36,50 @@ type Entropy struct {
// that match is not allowlisted (globally or locally), then a leak will be appended // that match is not allowlisted (globally or locally), then a leak will be appended
// to the final scan report. // to the final scan report.
type Rule struct { type Rule struct {
Description string Description string
Regex *regexp.Regexp Regex *regexp.Regexp
FileNameRegex *regexp.Regexp File *regexp.Regexp
FilePathRegex *regexp.Regexp Path *regexp.Regexp
Tags []string Tags []string
Allowlist []Allowlist AllowList AllowList
Entropies []Entropy Entropies []Entropy
} }
// Config is a composite struct of Rules and Allowlists // Config is a composite struct of Rules and Allowlists
// Each Rule contains a description, regular expression, tags, and allowlists if available // Each Rule contains a description, regular expression, tags, and allowlists if available
type Config struct { type Config struct {
Rules []Rule Rules []Rule
Allowlist struct { Allowlist AllowList
Description string }
Commits []string
Files []*regexp.Regexp // TomlAllowList is a struct used in the TomlLoader that loads in allowlists from
Paths []*regexp.Regexp // specific rules or globally at the top level config
Repos []*regexp.Regexp type TomlAllowList struct {
} Description string
Regexes []string
Commits []string
Files []string
Paths []string
Repos []string
} }
// TomlLoader gets loaded with the values from a gitleaks toml config // TomlLoader gets loaded with the values from a gitleaks toml config
// see the config in config/defaults.go for an example. TomlLoader is used // see the config in config/defaults.go for an example. TomlLoader is used
// to generate Config values (compiling regexes, etc). // to generate Config values (compiling regexes, etc).
type TomlLoader struct { type TomlLoader struct {
Allowlist struct { AllowList TomlAllowList
Rules []struct {
Description string Description string
Commits []string Regex string
Files []string File string
Paths []string Path string
Repos []string Tags []string
} Entropies []struct {
Rules []struct {
Description string
Regex string
FileNameRegex string
FilePathRegex string
Tags []string
Entropies []struct {
Min string Min string
Max string Max string
Group string Group string
} }
Allowlist []struct { AllowList TomlAllowList
Description string
Regex string
File string
Path string
}
} }
} }
@@ -98,7 +95,7 @@ func NewConfig(options options.Options) (Config, error) {
if options.Config != "" { if options.Config != "" {
_, err = toml.DecodeFile(options.Config, &tomlLoader) _, err = toml.DecodeFile(options.Config, &tomlLoader)
// append a allowlist rule for allowlisting the config // append a allowlist rule for allowlisting the config
tomlLoader.Allowlist.Files = append(tomlLoader.Allowlist.Files, path.Base(options.Config)) tomlLoader.AllowList.Files = append(tomlLoader.AllowList.Files, path.Base(options.Config))
} else { } else {
_, err = toml.Decode(DefaultConfig, &tomlLoader) _, err = toml.Decode(DefaultConfig, &tomlLoader)
} }
@@ -119,40 +116,52 @@ func NewConfig(options options.Options) (Config, error) {
func (tomlLoader TomlLoader) Parse() (Config, error) { func (tomlLoader TomlLoader) Parse() (Config, error) {
var cfg Config var cfg Config
for _, rule := range tomlLoader.Rules { for _, rule := range tomlLoader.Rules {
// check and make sure the rule is valid
if rule.Regex == "" && rule.Path == "" && rule.File == "" && len(rule.Entropies) == 0 {
log.Warnf("Rule %s does not define any actionable data", rule.Description)
continue
}
re, err := regexp.Compile(rule.Regex) re, err := regexp.Compile(rule.Regex)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
fileNameRe, err := regexp.Compile(rule.FileNameRegex) fileNameRe, err := regexp.Compile(rule.File)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
filePathRe, err := regexp.Compile(rule.FilePathRegex) filePathRe, err := regexp.Compile(rule.Path)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
// rule specific allowlists // rule specific allowlists
var allowlists []Allowlist var allowList AllowList
for _, wl := range rule.Allowlist {
wlRe, err := regexp.Compile(wl.Regex) // rule specific regexes
for _, re := range rule.AllowList.Regexes {
allowListedRegex, err := regexp.Compile(re)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
wlFileNameRe, err := regexp.Compile(wl.File) allowList.Regexes = append(allowList.Regexes, allowListedRegex)
}
// rule specific filenames
for _, re := range rule.AllowList.Files {
allowListedRegex, err := regexp.Compile(re)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
wlFilePathRe, err := regexp.Compile(wl.Path) allowList.Files = append(allowList.Files, allowListedRegex)
}
// rule specific paths
for _, re := range rule.AllowList.Paths {
allowListedRegex, err := regexp.Compile(re)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
allowlists = append(allowlists, Allowlist{ allowList.Paths = append(allowList.Paths, allowListedRegex)
Description: wl.Description,
File: wlFileNameRe,
Path: wlFilePathRe,
Regex: wlRe,
})
} }
var entropies []Entropy var entropies []Entropy
@@ -184,46 +193,57 @@ func (tomlLoader TomlLoader) Parse() (Config, error) {
entropies = append(entropies, Entropy{Min: min, Max: max, Group: int(group)}) entropies = append(entropies, Entropy{Min: min, Max: max, Group: int(group)})
} }
cfg.Rules = append(cfg.Rules, Rule{ r := Rule{
Description: rule.Description, Description: rule.Description,
Regex: re, Regex: re,
FileNameRegex: fileNameRe, File: fileNameRe,
FilePathRegex: filePathRe, Path: filePathRe,
Tags: rule.Tags, Tags: rule.Tags,
Allowlist: allowlists, AllowList: allowList,
Entropies: entropies, Entropies: entropies,
}) }
cfg.Rules = append(cfg.Rules, r)
} }
// global file name allowlists // global regex allowLists
for _, wlFileName := range tomlLoader.Allowlist.Files { for _, allowListRegex := range tomlLoader.AllowList.Regexes {
re, err := regexp.Compile(wlFileName) re, err := regexp.Compile(allowListRegex)
if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
cfg.Allowlist.Regexes = append(cfg.Allowlist.Regexes, re)
}
// global file name allowLists
for _, allowListFileName := range tomlLoader.AllowList.Files {
re, err := regexp.Compile(allowListFileName)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
cfg.Allowlist.Files = append(cfg.Allowlist.Files, re) cfg.Allowlist.Files = append(cfg.Allowlist.Files, re)
} }
// global file path allowlists // global file path allowLists
for _, wlFilePath := range tomlLoader.Allowlist.Paths { for _, allowListFilePath := range tomlLoader.AllowList.Paths {
re, err := regexp.Compile(wlFilePath) re, err := regexp.Compile(allowListFilePath)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
cfg.Allowlist.Paths = append(cfg.Allowlist.Paths, re) cfg.Allowlist.Paths = append(cfg.Allowlist.Paths, re)
} }
// global repo allowlists // global repo allowLists
for _, wlRepo := range tomlLoader.Allowlist.Repos { for _, allowListRepo := range tomlLoader.AllowList.Repos {
re, err := regexp.Compile(wlRepo) re, err := regexp.Compile(allowListRepo)
if err != nil { if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err) return cfg, fmt.Errorf("problem loading config: %v", err)
} }
cfg.Allowlist.Repos = append(cfg.Allowlist.Repos, re) cfg.Allowlist.Repos = append(cfg.Allowlist.Repos, re)
} }
cfg.Allowlist.Commits = tomlLoader.Allowlist.Commits cfg.Allowlist.Commits = tomlLoader.AllowList.Commits
cfg.Allowlist.Description = tomlLoader.Allowlist.Description cfg.Allowlist.Description = tomlLoader.AllowList.Description
return cfg, nil return cfg, nil
} }
+3 -3
View File
@@ -5,7 +5,7 @@ import (
"regexp" "regexp"
"testing" "testing"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
) )
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
@@ -15,7 +15,7 @@ func TestParse(t *testing.T) {
wantErr error wantErr error
wantFileRegex *regexp.Regexp wantFileRegex *regexp.Regexp
wantMessages *regexp.Regexp wantMessages *regexp.Regexp
wantAllowlist Allowlist wantAllowlist AllowList
}{ }{
{ {
description: "default config", description: "default config",
@@ -122,7 +122,7 @@ func TestParse(t *testing.T) {
_, err := NewConfig(test.opts) _, err := NewConfig(test.opts)
if err != nil { if err != nil {
if test.wantErr == nil { if test.wantErr == nil {
t.Error(err) t.Error(test.description, err)
} else if test.wantErr.Error() != err.Error() { } else if test.wantErr.Error() != err.Error() {
t.Errorf("expected err: %s, got %s", test.wantErr, err) t.Errorf("expected err: %s, got %s", test.wantErr, err)
} }
+21 -29
View File
@@ -129,8 +129,8 @@ title = "gitleaks config"
[[rules]] [[rules]]
description = "Port" description = "Port"
regex = '''(?i)port(.{0,4})?[0-9]{1,10}''' regex = '''(?i)port(.{0,4})?[0-9]{1,10}'''
[[rules.allowlist]] [rules.allowlist]
regex = '''(?i)port ''' regexes = ['''(?i)port ''']
description = "ignore export " description = "ignore export "
@@ -139,8 +139,8 @@ title = "gitleaks config"
description = "Email" description = "Email"
regex = '''[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}''' regex = '''[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}'''
tags = ["email"] tags = ["email"]
[[rules.allowlist]] [rules.allowlist]
file = '''(?i)bashrc''' files = ['''(?i)bashrc''']
description = "ignore bashrc emails" description = "ignore bashrc emails"
@@ -149,35 +149,26 @@ title = "gitleaks config"
regex = '''(?i)(dbpasswd|dbuser|dbname|dbhost|api_key|apikey|secret|key|api|password|user|guid|hostname|pw|auth)(.{0,20})?['|"]([0-9a-zA-Z-_\/+!{}/=]{4,120})['|"]''' regex = '''(?i)(dbpasswd|dbuser|dbname|dbhost|api_key|apikey|secret|key|api|password|user|guid|hostname|pw|auth)(.{0,20})?['|"]([0-9a-zA-Z-_\/+!{}/=]{4,120})['|"]'''
tags = ["key", "API", "generic"] tags = ["key", "API", "generic"]
# ignore leaks with specific identifiers like slack and aws # ignore leaks with specific identifiers like slack and aws
[[rules.allowlist]] [rules.allowlist]
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})''' description = "ignore slack, mailchimp, aws"
description = "ignore slack" regexes = [
[[rules.allowlist]] '''xox[baprs]-([0-9a-zA-Z]{10,48})''',
description = "MailChimp API key" '''(?i)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]''',
regex = '''(?i)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]''' '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
[[rules.allowlist]] ]
description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
#[[rules]]
# description = "s3config"
# regex = '''(?i)(dbpasswd|dbuser|dbname|dbhost|api_key|apikey|key|api|password|user|guid|hostname|pw|auth)(.{0,3})?([0-9a-zA-Z-_\/+!{}=]{4,120})'''
# fileNameRegex = '''(?i)s3cfg$'''
[[rules]] [[rules]]
description = "High Entropy" description = "High Entropy"
regex = '''[0-9a-zA-Z-_!{}/=]{4,120}''' regex = '''[0-9a-zA-Z-_!{}/=]{4,120}'''
fileNameRegex = '''(?i)(dump.sql|high-entropy-misc.txt)$''' file = '''(?i)(dump.sql|high-entropy-misc.txt)$'''
tags = ["entropy"] tags = ["entropy"]
[[rules.Entropies]] [[rules.Entropies]]
Min = "4.3" Min = "4.3"
Max = "7.0" Max = "7.0"
[[rules.allowlist]] [rules.allowlist]
description = "ignore ssh key and pems" description = "ignore ssh key and pems"
file = '''(pem|ppk|env)$''' files = ['''(pem|ppk|env)$''']
path = '''(.*)?ssh''' paths = ['''(.*)?ssh''']
[[rules]] [[rules]]
description = "Potential bash var" description = "Potential bash var"
@@ -195,8 +186,9 @@ title = "gitleaks config"
[[rules]] [[rules]]
description = "Files with keys and credentials" description = "Files with keys and credentials"
fileNameRegex = '''(?i)(id_rsa|passwd|id_rsa.pub|pgpass|pem|key|shadow)''' file = '''(?i)(id_rsa|passwd|id_rsa.pub|pgpass|pem|key|shadow)'''
# Global allowlist
[allowlist] [allowlist]
description = "image allowlists" description = "image allowlists"
files = ['''(.*?)(jpg|gif|doc|pdf|bin)$'''] files = ['''(.*?)(jpg|gif|doc|pdf|bin)$''']
-12
View File
@@ -1,12 +0,0 @@
# This is a simple gitleaks config that contains one rule which checks for AWS keys and a file check that will trigger
# a leak if a .pem file is found
[[rules]]
description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"]
[[rules]]
description = "PEM Files"
file = '''(.*)?pem$'''
tags = ["key", "PEM"]
@@ -8,6 +8,6 @@
description = "AWS Manager ID" description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"] tags = ["key", "AWS"]
[[rules.allowlist]] [rules.allowlist]
regex = '''AKIAIO5FODNN7EXAMPLE.*''' regexes = ['''AKIAIO5FODNN7EXAMPLE.*''']
description = "ignore example aws key" description = "ignore example aws key"
+1 -1
View File
@@ -1,4 +1,4 @@
module github.com/zricethezav/gitleaks/v5 module github.com/zricethezav/gitleaks/v6
go 1.14 go 1.14
-2
View File
@@ -23,8 +23,6 @@ github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agR
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-git-fixtures/v4 v4.0.1 h1:q+IFMfLx200Q3scvt2hN79JsEzy4AmBTp/pqnefH+Bc= github.com/go-git/go-git-fixtures/v4 v4.0.1 h1:q+IFMfLx200Q3scvt2hN79JsEzy4AmBTp/pqnefH+Bc=
github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw= github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
github.com/go-git/go-git/v5 v5.0.0 h1:k5RWPm4iJwYtfWoxIJy4wJX9ON7ihPeZZYC1fLYDnpg=
github.com/go-git/go-git/v5 v5.0.0/go.mod h1:oYD8y9kWsGINPFJoLdaScGCN6dlKg23blmClfZwtUVA=
github.com/go-git/go-git/v5 v5.1.0 h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk= github.com/go-git/go-git/v5 v5.1.0 h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk=
github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM= github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
+5 -5
View File
@@ -6,9 +6,9 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
"github.com/zricethezav/gitleaks/v5/scan" "github.com/zricethezav/gitleaks/v6/scan"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
@@ -176,9 +176,9 @@ func (g *Github) ScanPR() {
continue continue
} }
repo.CheckRules(&scan.Bundle{ repo.CheckRules(&scan.Bundle{
Content: *f.Patch, Content: *f.Patch,
FilePath: *f.Filename, FilePath: *f.Filename,
Commit: &commitObj, Commit: &commitObj,
}) })
} }
} }
+7 -3
View File
@@ -4,9 +4,9 @@ import (
"context" "context"
"sync" "sync"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
"github.com/zricethezav/gitleaks/v5/scan" "github.com/zricethezav/gitleaks/v6/scan"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
@@ -93,6 +93,10 @@ func (g *Gitlab) Scan() {
cloneOpts := g.manager.CloneOptions cloneOpts := g.manager.CloneOptions
cloneOpts.URL = p.HTTPURLToRepo cloneOpts.URL = p.HTTPURLToRepo
err := r.Clone(cloneOpts) err := r.Clone(cloneOpts)
if err != nil {
log.Error(err)
continue
}
// TODO handle clone retry with ssh like github host // TODO handle clone retry with ssh like github host
r.Name = p.Name r.Name = p.Name
+1 -1
View File
@@ -3,7 +3,7 @@ package hosts
import ( import (
"strings" "strings"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
) )
const ( const (
+3 -3
View File
@@ -6,9 +6,9 @@ import (
"os" "os"
"testing" "testing"
"github.com/zricethezav/gitleaks/v5/config" "github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
) )
var ( var (
+5 -5
View File
@@ -5,11 +5,11 @@ import (
"os" "os"
"time" "time"
"github.com/zricethezav/gitleaks/v5/config" "github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v5/hosts" "github.com/zricethezav/gitleaks/v6/hosts"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
"github.com/zricethezav/gitleaks/v5/scan" "github.com/zricethezav/gitleaks/v6/scan"
"github.com/hako/durafmt" "github.com/hako/durafmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
+4 -45
View File
@@ -2,7 +2,6 @@ package manager
import ( import (
"crypto/sha1" "crypto/sha1"
"encoding/csv"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
@@ -14,8 +13,8 @@ import (
"text/tabwriter" "text/tabwriter"
"time" "time"
"github.com/zricethezav/gitleaks/v5/config" "github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/hako/durafmt" "github.com/hako/durafmt"
@@ -89,7 +88,7 @@ type Metadata struct {
RegexTime map[string]int64 RegexTime map[string]int64
Commits int Commits int
ScanTime int64 ScanTime int64
patchTime int64 patchTime int64
cloneTime int64 cloneTime int64
} }
@@ -252,7 +251,7 @@ func (manager *Manager) DebugOutput() {
w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, '.', 0) w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, '.', 0)
log.Debugf("--------------------------\n") log.Debugf("--------------------------\n")
log.Debugf("| Individual Regex Times |\n") log.Debugf("| Individual Regexes Times |\n")
log.Debugf("--------------------------\n") log.Debugf("--------------------------\n")
for k, v := range manager.metadata.RegexTime { for k, v := range manager.metadata.RegexTime {
_, _ = fmt.Fprintf(w, "%s\t%s\n", k, durafmt.Parse(time.Duration(v)*time.Nanosecond)) _, _ = fmt.Fprintf(w, "%s\t%s\n", k, durafmt.Parse(time.Duration(v)*time.Nanosecond))
@@ -261,46 +260,6 @@ func (manager *Manager) DebugOutput() {
} }
// Report saves gitleaks leaks to a json specified by --report={report.json}
func (manager *Manager) Report() error {
close(manager.leakChan)
close(manager.metadata.timings)
if log.IsLevelEnabled(log.DebugLevel) {
manager.DebugOutput()
}
if manager.Opts.Report != "" {
if len(manager.GetLeaks()) == 0 {
log.Infof("no leaks found, skipping writing report")
return nil
}
file, err := os.Create(manager.Opts.Report)
if err != nil {
return err
}
if manager.Opts.ReportFormat == "json" {
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
err = encoder.Encode(manager.leaks)
if err != nil {
return err
}
} else {
w := csv.NewWriter(file)
_ = w.Write([]string{"repo", "line", "commit", "offender", "rule", "tags", "commitMsg", "author", "email", "file", "date"})
for _, leak := range manager.GetLeaks() {
w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.Rule, leak.Tags, leak.Message, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
}
w.Flush()
}
_ = file.Close()
log.Infof("report written to %s", manager.Opts.Report)
}
return nil
}
func (manager *Manager) receiveInterrupt() { func (manager *Manager) receiveInterrupt() {
<-manager.stopChan <-manager.stopChan
+4 -4
View File
@@ -3,8 +3,8 @@ package manager
import ( import (
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v5/config" "github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
"io" "io"
"testing" "testing"
) )
@@ -45,14 +45,14 @@ func TestSendReceiveLeaks(t *testing.T) {
func TestSendReceiveMeta(t *testing.T) { func TestSendReceiveMeta(t *testing.T) {
tests := []struct { tests := []struct {
scanTime int64 scanTime int64
patchTime int64 patchTime int64
cloneTime int64 cloneTime int64
regexTime int64 regexTime int64
iterations int iterations int
}{ }{
{ {
scanTime: 1000, scanTime: 1000,
patchTime: 1000, patchTime: 1000,
cloneTime: 1000, cloneTime: 1000,
regexTime: 1000, regexTime: 1000,
+78
View File
@@ -0,0 +1,78 @@
package manager
import (
"encoding/csv"
"encoding/json"
"os"
"time"
"github.com/zricethezav/gitleaks/v6/version"
log "github.com/sirupsen/logrus"
)
// Report saves gitleaks leaks to a json specified by --report={report.json}
func (manager *Manager) Report() error {
close(manager.leakChan)
close(manager.metadata.timings)
if log.IsLevelEnabled(log.DebugLevel) {
manager.DebugOutput()
}
if manager.Opts.Report != "" {
if len(manager.GetLeaks()) == 0 {
log.Infof("no leaks found, skipping writing report")
return nil
}
file, err := os.Create(manager.Opts.Report)
if err != nil {
return err
}
switch manager.Opts.ReportFormat {
case "json":
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
err = encoder.Encode(manager.leaks)
if err != nil {
return err
}
case "csv":
w := csv.NewWriter(file)
_ = w.Write([]string{"repo", "line", "commit", "offender", "rule", "tags", "commitMsg", "author", "email", "file", "date"})
for _, leak := range manager.GetLeaks() {
w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.Rule, leak.Tags, leak.Message, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
}
w.Flush()
case "sarif":
s := Sarif{
Schema: "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
Version: "2.1.0",
Runs: []Runs{
{
Tool: Tool{
Driver: Driver{
Name: "Gitleaks",
SemanticVersion: version.Version,
Rules: manager.configToRules(),
},
},
Results: manager.leaksToResults(),
},
},
}
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
err = encoder.Encode(s)
if err != nil {
return err
}
}
_ = file.Close()
log.Infof("report written to %s", manager.Opts.Report)
}
return nil
}
+153
View File
@@ -0,0 +1,153 @@
package manager
import (
"fmt"
"time"
)
//Sarif ...
type Sarif struct {
Schema string `json:"$schema"`
Version string `json:"version"`
Runs []Runs `json:"runs"`
}
//ShortDescription ...
type ShortDescription struct {
Text string `json:"text"`
}
//FullDescription ...
type FullDescription struct {
Text string `json:"text"`
}
//Rules ...
type Rules struct {
ID string `json:"id"`
Name string `json:"name"`
}
//Driver ...
type Driver struct {
Name string `json:"name"`
SemanticVersion string `json:"semanticVersion"`
Rules []Rules `json:"rules"`
}
//Tool ...
type Tool struct {
Driver Driver `json:"driver"`
}
//Message ...
type Message struct {
Text string `json:"text"`
}
//ArtifactLocation ...
type ArtifactLocation struct {
URI string `json:"uri"`
}
//Region ...
type Region struct {
StartLine int `json:"startLine"`
Snippet Snippet `json:"snippet"`
}
//Snippet ...
type Snippet struct {
Text string `json:"text"`
}
//PhysicalLocation ...
type PhysicalLocation struct {
ArtifactLocation ArtifactLocation `json:"artifactLocation"`
Region Region `json:"region"`
}
//Locations ...
type Locations struct {
PhysicalLocation PhysicalLocation `json:"physicalLocation"`
}
//Results ...
type Results struct {
Message Message `json:"message"`
Properties ResultProperties `json:"properties"`
Locations []Locations `json:"locations"`
}
//ResultProperties ...
type ResultProperties struct {
Commit string `json:"commit"`
Offender string `json:"offender"`
Date time.Time `json:"date"`
Author string `json:"author"`
Email string `json:"email"`
CommitMessage string `json:"commitMessage"`
Operation string `json:"gitOperation"`
Repo string `json:"repo"`
}
//Runs ...
type Runs struct {
Tool Tool `json:"tool"`
Results []Results `json:"results"`
}
func (manager *Manager) configToRules() []Rules {
var rules []Rules
for _, rule := range manager.Config.Rules {
rules = append(rules, Rules{
ID: rule.Description,
Name: rule.Description,
})
}
return rules
}
func (manager *Manager) leaksToResults() []Results {
var results []Results
for _, leak := range manager.leaks {
results = append(results, Results{
Message: Message{
Text: fmt.Sprintf("%s secret detected", leak.Rule),
},
Properties: ResultProperties{
Commit: leak.Commit,
Offender: leak.Offender,
Date: leak.Date,
Author: leak.Author,
Email: leak.Email,
CommitMessage: leak.Message,
Operation: leak.Operation,
Repo: leak.Repo,
},
Locations: leakToLocation(leak),
})
}
return results
}
func leakToLocation(leak Leak) []Locations {
return []Locations{
{
PhysicalLocation:
PhysicalLocation{
ArtifactLocation: ArtifactLocation{
URI: leak.File,
},
Region: Region{
StartLine: leak.LineNumber,
Snippet: Snippet{
Text: leak.Line,
},
},
},
},
}
}
+35 -30
View File
@@ -7,7 +7,7 @@ import (
"os/user" "os/user"
"strings" "strings"
"github.com/zricethezav/gitleaks/v5/version" "github.com/zricethezav/gitleaks/v6/version"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/http"
@@ -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 or csv"` 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"`
+13 -5
View File
@@ -11,8 +11,8 @@ import (
"runtime" "runtime"
"time" "time"
"github.com/zricethezav/gitleaks/v5/config" "github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5"
@@ -77,11 +77,11 @@ func Run(m *manager.Manager) error {
func runHelper(r *Repo) error { func runHelper(r *Repo) error {
// Ignore allowlisted repos // Ignore allowlisted repos
for _, wlRepo := range r.Manager.Config.Allowlist.Repos { for _, allowListedRepo := range r.Manager.Config.Allowlist.Repos {
if RegexMatched(r.Manager.Opts.RepoPath, wlRepo) { if RegexMatched(r.Manager.Opts.RepoPath, allowListedRepo) {
return nil return nil
} }
if RegexMatched(r.Manager.Opts.Repo, wlRepo) { if RegexMatched(r.Manager.Opts.Repo, allowListedRepo) {
return nil return nil
} }
} }
@@ -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()
} }
+56 -57
View File
@@ -11,8 +11,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/zricethezav/gitleaks/v5/config" "github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
fdiff "github.com/go-git/go-git/v5/plumbing/format/diff" fdiff "github.com/go-git/go-git/v5/plumbing/format/diff"
"github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/object"
@@ -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.
@@ -58,17 +59,17 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
start := time.Now() start := time.Now()
// For each rule we want to check filename allowlists // For each rule we want to check filename allowlists
if isFileNameWhiteListed(filename, rule.Allowlist) || isFilePathWhiteListed(path, rule.Allowlist) { if isAllowListed(filename, rule.AllowList.Files) || isAllowListed(path, rule.AllowList.Paths) {
continue continue
} }
// If it has fileNameRegex and it doesnt match we continue to next rule // If it has fileNameRegex and it doesnt match we continue to next rule
if ruleContainFileNameRegex(rule) && !RegexMatched(filename, rule.FileNameRegex) { if ruleContainFileRegex(rule) && !RegexMatched(filename, rule.File) {
continue continue
} }
// If it has filePathRegex and it doesnt match we continue to next rule // If it has filePathRegex and it doesnt match we continue to next rule
if ruleContainFilePathRegex(rule) && !RegexMatched(path, rule.FilePathRegex) { if ruleContainPathRegex(rule) && !RegexMatched(path, rule.Path) {
continue continue
} }
@@ -76,18 +77,18 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
if !ruleContainRegex(rule) { if !ruleContainRegex(rule) {
repo.Manager.SendLeaks(manager.Leak{ repo.Manager.SendLeaks(manager.Leak{
LineNumber: defaultLineNumber, LineNumber: defaultLineNumber,
Line: "N/A", Line: "N/A",
Offender: "Filename/path offender: " + filename, Offender: "Filename/path offender: " + filename,
Commit: bundle.Commit.Hash.String(), Commit: bundle.Commit.Hash.String(),
Repo: repo.Name, Repo: repo.Name,
Message: bundle.Commit.Message, Message: bundle.Commit.Message,
Rule: rule.Description, Rule: rule.Description,
Author: bundle.Commit.Author.Name, Author: bundle.Commit.Author.Name,
Email: bundle.Commit.Author.Email, Email: bundle.Commit.Author.Email,
Date: bundle.Commit.Author.When, Date: bundle.Commit.Author.When,
Tags: strings.Join(rule.Tags, ", "), Tags: strings.Join(rule.Tags, ", "),
File: filename, File: filename,
Operation: diffOpToString(bundle.Operation), Operation: diffOpToString(bundle.Operation),
}) })
} else { } else {
//otherwise we check if it matches Content regex //otherwise we check if it matches Content regex
@@ -112,7 +113,7 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
offender := bundle.Content[loc[0]:loc[1]] offender := bundle.Content[loc[0]:loc[1]]
groups := rule.Regex.FindStringSubmatch(offender) groups := rule.Regex.FindStringSubmatch(offender)
if isOffenderWhiteListed(offender, rule.Allowlist) { if isAllowListed(line, append(rule.AllowList.Regexes, repo.config.Allowlist.Regexes...)) {
continue continue
} }
@@ -146,7 +147,6 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
} }
} }
// TODO should return filenameRegex if only file rule
repo.Manager.RecordTime(manager.RegexTime{ repo.Manager.RecordTime(manager.RegexTime{
Time: howLong(start), Time: howLong(start),
Regex: rule.Regex.String(), Regex: rule.Regex.String(),
@@ -200,7 +200,15 @@ func extractAndInjectLineNumber(leak *manager.Leak, bundle *Bundle, repo *Repo)
if bundle.Patch == "" { if bundle.Patch == "" {
return return
} }
// This is needed as some patches generate strings that are larger than
// scanners max size (MaxScanTokenSize = 64 * 1024)
// https://github.com/zricethezav/gitleaks/issues/413
buf := make([]byte, len(bundle.Patch))
scanner := bufio.NewScanner(strings.NewReader(bundle.Patch)) scanner := bufio.NewScanner(strings.NewReader(bundle.Patch))
scanner.Buffer(buf, len(bundle.Patch))
scanner.Split(bufio.ScanLines)
currFile := "" currFile := ""
currLine := 0 currLine := 0
currStartDiffLine := 0 currStartDiffLine := 0
@@ -231,6 +239,19 @@ 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
if !strings.HasSuffix(txt, diffLineSignature) {
currLine = -1
}
} }
currLine++ currLine++
} }
@@ -331,28 +352,28 @@ func ruleContainRegex(rule config.Rule) bool {
} }
// Checks if the given rule has a file name regex // Checks if the given rule has a file name regex
func ruleContainFileNameRegex(rule config.Rule) bool { func ruleContainFileRegex(rule config.Rule) bool {
if rule.FileNameRegex == nil { if rule.File == nil {
return false return false
} }
if rule.FileNameRegex.String() == "" { if rule.File.String() == "" {
return false return false
} }
return true return true
} }
// Checks if the given rule has a file path regex // Checks if the given rule has a file path regex
func ruleContainFilePathRegex(rule config.Rule) bool { func ruleContainPathRegex(rule config.Rule) bool {
if rule.FilePathRegex == nil { if rule.Path == nil {
return false return false
} }
if rule.FilePathRegex.String() == "" { if rule.Path.String() == "" {
return false return false
} }
return true return true
} }
func isCommitWhiteListed(commitHash string, allowlistedCommits []string) bool { func isCommitAllowListed(commitHash string, allowlistedCommits []string) bool {
for _, hash := range allowlistedCommits { for _, hash := range allowlistedCommits {
if commitHash == hash { if commitHash == hash {
return true return true
@@ -361,36 +382,14 @@ func isCommitWhiteListed(commitHash string, allowlistedCommits []string) bool {
return false return false
} }
func isOffenderWhiteListed(offender string, allowlist []config.Allowlist) bool { func isAllowListed(target string, allowList []*regexp.Regexp) bool {
if len(allowlist) != 0 { if len(allowList) != 0 {
for _, wl := range allowlist { for _, re := range allowList {
if wl.Regex.FindString(offender) != "" { if re.FindString(target) != "" {
return true return true
} }
} }
} }
return false return false
}
func isFileNameWhiteListed(filename string, allowlist []config.Allowlist) bool {
if len(allowlist) != 0 {
for _, wl := range allowlist {
if RegexMatched(filename, wl.File) {
return true
}
}
}
return false
} }
func isFilePathWhiteListed(filepath string, allowlist []config.Allowlist) bool {
if len(allowlist) != 0 {
for _, wl := range allowlist {
if RegexMatched(filepath, wl.Path) {
return true
}
}
}
return false
}
+74 -36
View File
@@ -1,13 +1,16 @@
package scan package scan
import ( import (
"bufio"
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"os"
"strings"
"sync" "sync"
"time" "time"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
@@ -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)
@@ -96,7 +124,7 @@ func (repo *Repo) Scan() error {
} }
// Check if Commit is allowlisted // Check if Commit is allowlisted
if isCommitWhiteListed(c.Hash.String(), repo.config.Allowlist.Commits) { if isCommitAllowListed(c.Hash.String(), repo.config.Allowlist.Commits) {
return nil return nil
} }
@@ -113,41 +141,47 @@ func (repo *Repo) Scan() error {
// increase Commit counter // increase Commit counter
cc++ cc++
err = c.Parents().ForEach(func(parent *object.Commit) error { // inspect first parent only as all other parents will be eventually reached
defer func() { // (they exist as the tip of other branches, etc)
if err := recover(); err != nil { // See https://github.com/zricethezav/gitleaks/issues/413 for details
// sometimes the Patch generation will fail due to a known bug in parent, err := c.Parent(0)
// sergi's go-diff: https://github.com/sergi/go-diff/issues/89. if err != nil {
// Once a fix has been merged I will remove this recover. return err
return }
}
}()
if repo.timeoutReached() {
return nil
}
if parent == nil {
// shouldn't reach this point but just in case
return nil
}
start := time.Now() defer func() {
patch, err := parent.Patch(c) if err := recover(); err != nil {
if err != nil { // sometimes the Patch generation will fail due to a known bug in
return fmt.Errorf("could not generate Patch") // sergi's go-diff: https://github.com/sergi/go-diff/issues/89.
// Once a fix has been merged I will remove this recover.
return
} }
repo.Manager.RecordTime(manager.PatchTime(howLong(start))) }()
wg.Add(1) if repo.timeoutReached() {
semaphore <- true
go func(c *object.Commit, patch *object.Patch) {
defer func() {
<-semaphore
wg.Done()
}()
scanPatch(patch, c, repo)
}(c, patch)
return nil return nil
}) }
if parent == nil {
// shouldn't reach this point but just in case
return nil
}
start := time.Now()
patch, err := parent.Patch(c)
if err != nil {
log.Errorf("could not generate Patch")
}
repo.Manager.RecordTime(manager.PatchTime(howLong(start)))
wg.Add(1)
semaphore <- true
go func(c *object.Commit, patch *object.Patch) {
defer func() {
<-semaphore
wg.Done()
}()
scanPatch(patch, c, repo)
}(c, patch)
if c.Hash.String() == repo.Manager.Opts.CommitTo { if c.Hash.String() == repo.Manager.Opts.CommitTo {
return storer.ErrStop return storer.ErrStop
} }
@@ -169,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)
@@ -276,7 +313,8 @@ func (repo *Repo) scanUncommitted() error {
} }
} }
diffs := diffmatchpatch.New().DiffMain(prevFileContents, currFileContents, false) dmp := diffmatchpatch.New()
diffs := dmp.DiffCleanupSemantic(dmp.DiffMain(prevFileContents, currFileContents, false))
var diffContents string var diffContents string
for _, d := range diffs { for _, d := range diffs {
if d.Type == diffmatchpatch.DiffInsert { if d.Type == diffmatchpatch.DiffInsert {
+47 -5
View File
@@ -10,9 +10,9 @@ import (
"sort" "sort"
"testing" "testing"
"github.com/zricethezav/gitleaks/v5/config" "github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v5/manager" "github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v5/options" "github.com/zricethezav/gitleaks/v6/options"
"github.com/sergi/go-diff/diffmatchpatch" "github.com/sergi/go-diff/diffmatchpatch"
) )
@@ -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{
@@ -376,6 +396,25 @@ func TestScan(t *testing.T) {
}, },
wantPath: "../test_data/test_local_repo_two_leaks_deletion.json", wantPath: "../test_data/test_local_repo_two_leaks_deletion.json",
}, },
{
description: "test local repo eight (merges)",
opts: options.Options{
RepoPath: "../test_data/test_repos/test_repo_8",
Report: "../test_data/test_local_repo_eight.json.got",
ReportFormat: "json",
},
wantPath: "../test_data/test_local_repo_eight.json",
},
{
description: "test local repo nine",
opts: options.Options{
RepoPath: "../test_data/test_repos/test_repo_9",
Report: "../test_data/test_local_repo_nine_aws_leak.json.got",
Config: "../test_data/test_configs/large_with_global_allowlist_regex.toml",
ReportFormat: "json",
},
wantPath: "../test_data/test_local_repo_nine_aws_leak.json",
},
} }
for _, test := range tests { for _, test := range tests {
@@ -403,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 {
@@ -2,13 +2,7 @@
description = "AWS Manager ID" description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"] tags = ["key", "AWS"]
[[rules.allowlist]] [rules.allowlist]
description = "ignore md files" description = "ignore sample regex md files"
file = '''(.*)?md$''' files = ['''(.*)?md$''']
[[rules.allowlist]] regexes = ['''ignore$''']
description = "ignore this regex"
regex = '''ignore$'''
[[rules.allowlist]]
description = "ignore regex and md files"
regex = '''ignore$'''
file = '''(.*)?md$'''
@@ -2,6 +2,6 @@
description = "AWS Manager ID" description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"] tags = ["key", "AWS"]
[[rules.allowlist]] [rules.allowlist]
description = "ignore python files" description = "ignore python files"
file = '''(.*)?py$''' files = ['''(.*)?py$''']
@@ -2,6 +2,6 @@
description = "AWS Manager ID" description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"] tags = ["key", "AWS"]
[[rules.allowlist]] [rules.allowlist]
regex = '''AKIAIO5FODNN7EXAMPLE.*'''
description = "ignore aws key" description = "ignore aws key"
regexes = ['''AKIAIO5FODNN7EXAMPLE.*''']
@@ -8,6 +8,7 @@
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"] tags = ["key", "AWS"]
## this is an example of a rule that won't work
[[rules]] [[rules]]
description = "Python files" description = "Python files"
fileRegex = '''(.*)?py$''' fileRegex = "(?i)*.py"
+8 -8
View File
@@ -125,19 +125,19 @@ title = "gitleaks config"
description = "AWS Manager ID" description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"] tags = ["key", "AWS"]
[[rules.allowlist]] [rules.allowlist]
description = "ignore common jenkins functions" description = "ignore common jenkins functions"
regex = '''allowlistme''' regexes = [
file = '''(.*)?Jenkinsfile$''' '''allowlistme'''
[[rules.allowlist]] ]
description = "ignore common jenkins functions2" files = [
regex = '''allowlistme''' '''(.*)?Jenkinsfile$'''
file = '''(.*)?Jenkinsfile$''' ]
# Global rules. This instructs gitleaks to ignore all .pem files or if a message with # Global rules. This instructs gitleaks to ignore all .pem files or if a message with
[[rules]] [[rules]]
description = "Files with keys and credentials" description = "Files with keys and credentials"
fileRegex = '''(.*?)(pem)''' file = '''(.*?)(pem)'''
[allowlist] [allowlist]
description = "File allowlists" description = "File allowlists"
@@ -0,0 +1,151 @@
title = "gitleaks config"
[[rules]]
description = "AWS Secret Key"
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
tags = ["key", "AWS"]
[[rules]]
description = "AWS MWS key"
regex = '''amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
tags = ["key", "AWS", "MWS"]
[[rules]]
description = "Facebook Secret Key"
regex = '''(?i)(facebook|fb)(.{0,20})?(?-i)['\"][0-9a-f]{32}['\"]'''
tags = ["key", "Facebook"]
[[rules]]
description = "Facebook Client ID"
regex = '''(?i)(facebook|fb)(.{0,20})?['\"][0-9]{13,17}['\"]'''
tags = ["key", "Facebook"]
[[rules]]
description = "Twitter Secret Key"
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{35,44}['\"]'''
tags = ["key", "Twitter"]
[[rules]]
description = "Twitter Client ID"
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{18,25}['\"]'''
tags = ["client", "Twitter"]
[[rules]]
description = "Github"
regex = '''(?i)github(.{0,20})?(?-i)['\"][0-9a-zA-Z]{35,40}['\"]'''
tags = ["key", "Github"]
[[rules]]
description = "LinkedIn Client ID"
regex = '''(?i)linkedin(.{0,20})?(?-i)['\"][0-9a-z]{12}['\"]'''
tags = ["client", "LinkedIn"]
[[rules]]
description = "LinkedIn Secret Key"
regex = '''(?i)linkedin(.{0,20})?['\"][0-9a-z]{16}['\"]'''
tags = ["secret", "LinkedIn"]
[[rules]]
description = "Slack"
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
tags = ["key", "Slack"]
[[rules]]
description = "EC"
regex = '''-----BEGIN EC PRIVATE KEY-----'''
tags = ["key", "EC"]
[[rules]]
description = "Generic API key"
regex = '''(?i)(api_key|apikey)(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
tags = ["key", "API", "generic"]
[[rules]]
description = "Generic Secret"
regex = '''(?i)secret(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
tags = ["key", "Secret", "generic"]
[[rules]]
description = "Google API key"
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
tags = ["key", "Google"]
[[rules]]
description = "Heroku API key"
regex = '''(?i)heroku(.{0,20})?['"][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}['"]'''
tags = ["key", "Heroku"]
[[rules]]
description = "MailChimp API key"
regex = '''(?i)(mailchimp|mc)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
tags = ["key", "Mailchimp"]
[[rules]]
description = "Mailgun API key"
regex = '''(?i)(mailgun|mg)(.{0,20})?['"][0-9a-z]{32}['"]'''
tags = ["key", "Mailgun"]
[[rules]]
description = "PayPal Braintree access token"
regex = '''access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}'''
tags = ["key", "Paypal"]
[[rules]]
description = "Picatic API key"
regex = '''sk_live_[0-9a-z]{32}'''
tags = ["key", "Picatic"]
[[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}'''
tags = ["key", "slack"]
[[rules]]
description = "Stripe API key"
regex = '''(?i)stripe(.{0,20})?['\"][sk|rk]_live_[0-9a-zA-Z]{24}'''
tags = ["key", "Stripe"]
[[rules]]
description = "Square access token"
regex = '''sq0atp-[0-9A-Za-z\-_]{22}'''
tags = ["key", "square"]
[[rules]]
description = "Square OAuth secret"
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
tags = ["key", "square"]
[[rules]]
description = "Twilio API key"
regex = '''(?i)twilio(.{0,20})?['\"][0-9a-f]{32}['\"]'''
tags = ["key", "twilio"]
[[rules]]
description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"]
[rules.allowlist]
description = "ignore common jenkins functions"
regexes = [
'''allowlistme'''
]
files = [
'''(.*)?Jenkinsfile$'''
]
[[rules]]
description = "Files with keys and credentials"
file = '''(.*?)(pem)'''
# Global allowlist
[allowlist]
description = "global allowlists"
files = [
'''(.*?)(jpg|gif)$''',
'''(.*?)(doc|pdf|bin)$'''
]
regexes = [
'''(.*?)gitleaks:allow'''
]
+1 -1
View File
@@ -2,5 +2,5 @@
[[rules]] [[rules]]
description = "Generic password" description = "Generic password"
regex = '''(?i)(password|token).{0,20}?\s*[:|=]\s*?(?-i)([0-9a-zA-Z\/+]{4,40})''' regex = '''(?i)(password|token).{0,20}?\s*[:|=]\s*?(?-i)([0-9a-zA-Z\/+]{4,40})'''
fileNameRegex = '''.*\.ya?ml''' file = '''.*\.ya?ml'''
tags = ["key", "Yml", "Yaml"] tags = ["key", "Yml", "Yaml"]
+1 -1
View File
@@ -2,5 +2,5 @@
[[rules]] [[rules]]
description = "AWS Manager ID" description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
filePathRegex = '''config(guration)?''' path = '''config(guration)?'''
tags = ["key", "AWS"] tags = ["key", "AWS"]
@@ -2,6 +2,6 @@
[[rules]] [[rules]]
description = "Generic password" description = "Generic password"
regex = '''(?i)(password|token).{0,20}?\s*[:|=]\s*?(?-i)([0-9a-zA-Z\/+]{4,40})''' regex = '''(?i)(password|token).{0,20}?\s*[:|=]\s*?(?-i)([0-9a-zA-Z\/+]{4,40})'''
fileNameRegex = '''.*\.properties''' file = '''.*\.properties'''
filePathRegex = '''config(guration)?''' path = '''config(guration)?'''
tags = ["key", "Yml", "Yaml"] tags = ["key", "Yml", "Yaml"]
+60
View File
@@ -133,5 +133,65 @@
"date": "2020-02-24T14:13:15-05:00", "date": "2020-02-24T14:13:15-05:00",
"tags": "key, AWS", "tags": "key, AWS",
"operation": "addition" "operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:44:48-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 2,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "ce7e8177bbf8a172c06b6a1e370a374d5c19f660",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "dummy.txt w/ text",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:39:11-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "9267bc86ec1497471cbc6f3308f3527f7ef34b9d",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "Update dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:41:11-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE', #gitleaks:allow",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "8d1fb60d2d80f0590f191ed5ace1e45ef780909a",
"repo": "test_repo_9",
"rule": "AWS Manager ID",
"commitMessage": "gitleaks allow secret\n",
"author": "Zach Rice",
"email": "zrice@gitlab.com",
"file": "server.test.py",
"date": "2020-08-12T13:36:20-04:00",
"tags": "key, AWS",
"operation": "addition"
} }
] ]
@@ -133,5 +133,65 @@
"date": "2019-10-24T09:29:27-04:00", "date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS", "tags": "key, AWS",
"operation": "addition" "operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:44:48-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 2,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "ce7e8177bbf8a172c06b6a1e370a374d5c19f660",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "dummy.txt w/ text",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:39:11-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "9267bc86ec1497471cbc6f3308f3527f7ef34b9d",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "Update dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:41:11-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE', #gitleaks:allow",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "8d1fb60d2d80f0590f191ed5ace1e45ef780909a",
"repo": "test_repo_9",
"rule": "AWS Manager ID",
"commitMessage": "gitleaks allow secret\n",
"author": "Zach Rice",
"email": "zrice@gitlab.com",
"file": "server.test.py",
"date": "2020-08-12T13:36:20-04:00",
"tags": "key, AWS",
"operation": "addition"
} }
] ]
@@ -73,5 +73,35 @@
"date": "2020-02-24T14:13:15-05:00", "date": "2020-02-24T14:13:15-05:00",
"tags": "key, AWS", "tags": "key, AWS",
"operation": "addition" "operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:44:48-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE', #gitleaks:allow",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "8d1fb60d2d80f0590f191ed5ace1e45ef780909a",
"repo": "test_repo_9",
"rule": "AWS Manager ID",
"commitMessage": "gitleaks allow secret\n",
"author": "Zach Rice",
"email": "zrice@gitlab.com",
"file": "server.test.py",
"date": "2020-08-12T13:36:20-04:00",
"tags": "key, AWS",
"operation": "addition"
} }
] ]
+47
View File
@@ -0,0 +1,47 @@
[
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:44:48-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 2,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "ce7e8177bbf8a172c06b6a1e370a374d5c19f660",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "dummy.txt w/ text",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:39:11-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 6,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "9267bc86ec1497471cbc6f3308f3527f7ef34b9d",
"repo": "test_repo_8",
"rule": "AWS Manager ID",
"commitMessage": "Update dummy.txt",
"author": "Zachary Rice",
"email": "zricer@protonmail.com",
"file": "dummy.txt",
"date": "2020-07-25T14:41:11-04:00",
"tags": "key, AWS",
"operation": "addition"
}
]
@@ -0,0 +1,17 @@
[
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5,
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_9",
"rule": "AWS Manager ID",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS",
"operation": "addition"
}
]
@@ -1,19 +1,4 @@
[ [
{
"line": "N/A",
"lineNumber": -1,
"offender": "Filename/path offender: server.test.py",
"commit": "d274003914c707212cbe84e3e466a00013ccb639",
"repo": "test_repo_1",
"rule": "Python files",
"commitMessage": "comment\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T10:03:38-04:00",
"tags": "",
"operation": "addition"
},
{ {
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',", "line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"lineNumber": 5, "lineNumber": 5,
@@ -28,20 +13,5 @@
"date": "2019-10-24T09:29:27-04:00", "date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS", "tags": "key, AWS",
"operation": "addition" "operation": "addition"
},
{
"line": "N/A",
"lineNumber": -1,
"offender": "Filename/path offender: server.test.py",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_1",
"rule": "Python files",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "",
"operation": "addition"
} }
] ]
@@ -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
@@ -0,0 +1,2 @@
# test_repo_8
test repo for 413
@@ -0,0 +1 @@
ref: refs/heads/master
@@ -0,0 +1,13 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/zricethezav/test_repo_8.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 748f11eaf2c38c3cf0ac6a22e44208777e79fa6f Zach Rice <zrice@gitlab.com> 1595702825 -0400 clone: from https://github.com/zricethezav/test_repo_8.git
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 748f11eaf2c38c3cf0ac6a22e44208777e79fa6f Zach Rice <zrice@gitlab.com> 1595702825 -0400 clone: from https://github.com/zricethezav/test_repo_8.git
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 748f11eaf2c38c3cf0ac6a22e44208777e79fa6f Zach Rice <zrice@gitlab.com> 1595702825 -0400 clone: from https://github.com/zricethezav/test_repo_8.git
@@ -0,0 +1,4 @@
xuRÉnã8œ³¾‚@�ÄZ¨␍è„TdYqäEŠ×K@RÔb[–LQV¬¯O7èÃÌ»ÔC¡^…z¬®ªRG×þ’‚s 2èºÐ´lJufÛ”SmÇrRƒfZšêŽ�ê*4u¥!‚_$ åÌ6 �šaÚ :*µÓâªî:)· KÌŒgü­· …†ûpÊtj¸nFM]s8‡�e®ªiZjd6#.QH'‹Z€aw—Œƒïƒx€xiD-ëKEÊó3««¿�fº¦­ê–j�'ªªò`©$ (å´£àû¥¼9ß_òRýŸ³¼ÉÛ2Oÿöƒp–Á$a0GëØÿÉ+@}‹F{­ðê-›Nµ…ã™]áâfˆ°G(�†!òÄ~ð4áÒ‘úfLÔû—~9š>¶›Ó¹Û|xóþ€ ʰÃw␍iï«à–ònN‰#Í>¾ÎǘàÅy»vŠt¾Šö´‰fazñ�.CŠ¢‰w5o{ý}t�,'Fñ ¡Äóߨ–Å_ì ÓXÏB¯â÷­y<Ö¢e¥)¨lb3Q@\‡ñ¨1d†ü#´ÛÛr¶ÓG˜«�÷±WΤìó­iä§0y_ÌÔà.Û4êG:ZìÛ`2™( ›M§$zõÔè÷E8>ýk»,o²º-†
LJ'zÇîv¸.ñán 9m±ø¥En) ×‹ä}2ŽŽFP¿n/Á»7␍%J®î~—0'¯¨» ö;˜Ÿ®«‰9ЈR»ðf±ì“y'ò
øAOh­üêÌŸ¿þwcJÄEÎAÓ�Ï@ðkÇ[ ¾é u~þ”,ø@nã?ö§†HV<iвnR"9貺ý¬Ê¼�Ÿ”
NÎÏòKþ&¾
@@ -0,0 +1,4 @@
x5‘QJÄ@ †}î)r€RQ¼€.º
*‹�éLÚ§™Ì´êÓ^CÐËíÏæ¥Iþ|ÿŸ>Hçg›“�À�Ä‘p„‡ ½¬ÚÂ=ÅŒ£ÄãáSá©Ûvw<Eΰçà_d&ØrôG…ûÒvM³•²˜‚'‡žZÈÁk’1áÜB”rq/ämŸ²§ßòÝ0°#�v¸`€ë˜)):˜PÁ³º¢jcó»fJ,E�ÃÔ
îªòÀVïÓP™ºÆ¾«Äö\âÂæ # æ$¯Ó»²cͰN«¤
dk´ôNbNè²YÁè+ M�ýÕ2Æ ƒUª«ÿ”þús ÊÆ␍§›ÍE Š\%0·•Skh•Œ…Þp戙%VçUpÆj␍ƒšgoÍ0`²ÇÁè²X¢V¶™ßÐ8YCI¶¨BÖŽ‰çÚe .”šüñðµ·uR‚¯—̦o‡³+ÚœRXH»ãáÛRZeý ¤Mãy«›Êîù±ù�Ã6
@@ -0,0 +1,5 @@
xu▓I▐⌡@┘sФW╢■ё51п╛рL4мЮaЯ2╤1фЖ╜i╨ш,n/ЭЗL&й-y≈▓>╫*╘Тi╙╙юRЮ7а)┼иТлd√i╚z Ал0m≤й▄≤B  c╘␍ц░Zлi-─°b°1U╔жтК:я%░* mB ┐PbZЪУjPзи,╛и╡╔°)*╤≤Fl┐Й√LTU√┴"А^␍L
л`]
·Ч9Ьkкят.о?HSЩ┼nК╕╛√·До╚р'ЩЭJP╪RЬ}
·К├сЖЭxмKQТИжР6Ой<Щ√3Я┌XzKчmБУД▀K@╥н!BнB+g2ъW▀╥╣35▀ёЖq┘<╦!■ЫA─°╡█␍шe■мp┘╝с╫}╧█$`L°у)Qё≈╟╦дХ^р┘u8. А·Ts@Б8F├╚ьц⌡йг≈УUсЫ╤┴NLКnЕС│Шм=иX▐?|Вяi╔÷┬⌠DiбМn}Ю╫≈zrXo╨8!^ЁXmгm╘≈K e╣⌡╦╖B⌡ ╫╨Т╣ц║вs╕T≈+┼xnВСЯuВЭ≤Тс╙∙Е5W╫Р╗и╨≈─=╚╤║zЮGyё≈МЧ█ы▒ФN{\<NхЯТ▐5g▀²╤яv)┌L@}╦ g1GЭ╫╧≥0А²║hХн}
∙YS╟▒√лрCэшtyы╩О┐IН┤.оG║K╡▐Зh╩тr^т≥©3:КE/5щJ2⌡,э'&м)о)hШСpzИi'юw0чTЮ╚S╒═╬▌q√∙╒lj|~Й(АT<╔в╓░╓╦м╟═ К╚ЙЯCэе/ВT
@@ -0,0 +1,4 @@
# pack-refs with: peeled fully-peeled sorted
ce6e0398cd8a40085cad12a8f4c96e580c2200c1 refs/remotes/origin/additional-secret-branch
748f11eaf2c38c3cf0ac6a22e44208777e79fa6f refs/remotes/origin/master
64b4391ddf2b399fb5218ee44cf90111d3f7ca9a refs/remotes/origin/zricethezav-patch-1
@@ -0,0 +1 @@
748f11eaf2c38c3cf0ac6a22e44208777e79fa6f
@@ -0,0 +1 @@
ref: refs/remotes/origin/master
@@ -0,0 +1,8 @@
Adding a secret
aws_access_key_id='AKIAIO5FODNN7EXAMPLE',
Adding a secret on another branch!!!
aws_access_key_id='AKIAIO5FODNN7EXAMPLE',
Some more content
@@ -0,0 +1,19 @@
No Longer in Shadows, Pentagon’s U.F.O. Unit Will Make Some Findings Public
For over a decade, the program, now tucked inside the Office of Naval Intelligence, has discussed mysterious events in classified briefings.
Eric W. Davis, an astrophysicist who worked as a subcontractor and then a consultant for the Pentagon U.F.O. program since 2007, said that, in some cases, examination of the materials had so far failed to determine their source and led him to conclude, “We couldn’t make it ourselves.”
wowzers
credit to NYT
uhmmmmmmm
Some more stuff
@@ -0,0 +1 @@
gitleaks allow secret
@@ -0,0 +1 @@
ref: refs/heads/master
@@ -0,0 +1,7 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 6557c92612d3b35979bd426d429255b3bf9fab74 zach rice <zricer@protonmail.com> 1571923767 -0400 commit (initial): commit 1 with secrets
6557c92612d3b35979bd426d429255b3bf9fab74 d274003914c707212cbe84e3e466a00013ccb639 zach rice <zricer@protonmail.com> 1571925818 -0400 commit: comment
d274003914c707212cbe84e3e466a00013ccb639 8d1fb60d2d80f0590f191ed5ace1e45ef780909a Zach Rice <zrice@gitlab.com> 1597253780 -0400 commit: gitleaks allow secret
@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 6557c92612d3b35979bd426d429255b3bf9fab74 zach rice <zricer@protonmail.com> 1571923767 -0400 commit (initial): commit 1 with secrets
6557c92612d3b35979bd426d429255b3bf9fab74 d274003914c707212cbe84e3e466a00013ccb639 zach rice <zricer@protonmail.com> 1571925818 -0400 commit: comment
d274003914c707212cbe84e3e466a00013ccb639 8d1fb60d2d80f0590f191ed5ace1e45ef780909a Zach Rice <zrice@gitlab.com> 1597253780 -0400 commit: gitleaks allow secret
Loaded 100 of 121 files, more files were not shown because too many files have changed in this diff. Show more