Compare commits

..
17 Commits
Author SHA1 Message Date
Daniel Paul SearlesandDaniel Paul Searles 2acc34dfdf Add support for reportGroup (#456)
Why:

* There are times where it would be nice to have a group from the regex
  reported rather than the complete match.

This change addresses the need by:

* Add the reportGroup configuration option for a rule.
* Update scan.CheckRules to return the reportGroup if set.

Co-authored-by: Daniel Paul Searles <dsearles@gitlab.com>
2020-11-03 15:15:48 -05:00
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
123 changed files with 1341 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`
PKG=github.com/zricethezav/gitleaks
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v5/version.Version=$(VERSION)"
_LDFLAGS="github.com/zricethezav/gitleaks/v5/version.Version=$(VERSION)"
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v6/version.Version=$(VERSION)"
_LDFLAGS="github.com/zricethezav/gitleaks/v6/version.Version=$(VERSION)"
COVER=--cover --coverprofile=cover.out
test-cover:
+2 -2
View File
@@ -31,8 +31,8 @@ Gamma proactively detects and remediates data leaks across cloud apps. Scan your
#### Individual Sponsors
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
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>.
+96 -73
View File
@@ -6,18 +6,21 @@ import (
"regexp"
"strconv"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v6/options"
"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.
type Allowlist struct {
type AllowList struct {
Description string
Regex *regexp.Regexp
File *regexp.Regexp
Path *regexp.Regexp
Regexes []*regexp.Regexp
Commits []string
Files []*regexp.Regexp
Paths []*regexp.Regexp
Repos []*regexp.Regexp
}
// Entropy represents an entropy range
@@ -33,56 +36,52 @@ type Entropy struct {
// that match is not allowlisted (globally or locally), then a leak will be appended
// to the final scan report.
type Rule struct {
Description string
Regex *regexp.Regexp
FileNameRegex *regexp.Regexp
FilePathRegex *regexp.Regexp
Tags []string
Allowlist []Allowlist
Entropies []Entropy
Description string
Regex *regexp.Regexp
File *regexp.Regexp
Path *regexp.Regexp
ReportGroup int
Tags []string
AllowList AllowList
Entropies []Entropy
}
// Config is a composite struct of Rules and Allowlists
// Each Rule contains a description, regular expression, tags, and allowlists if available
type Config struct {
Rules []Rule
Allowlist struct {
Description string
Commits []string
Files []*regexp.Regexp
Paths []*regexp.Regexp
Repos []*regexp.Regexp
}
Allowlist AllowList
}
// TomlAllowList is a struct used in the TomlLoader that loads in allowlists from
// specific rules or globally at the top level config
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
// see the config in config/defaults.go for an example. TomlLoader is used
// to generate Config values (compiling regexes, etc).
type TomlLoader struct {
Allowlist struct {
AllowList TomlAllowList
Rules []struct {
Description string
Commits []string
Files []string
Paths []string
Repos []string
}
Rules []struct {
Description string
Regex string
FileNameRegex string
FilePathRegex string
Tags []string
Entropies []struct {
Regex string
File string
Path string
ReportGroup int
Tags []string
Entropies []struct {
Min string
Max string
Group string
}
Allowlist []struct {
Description string
Regex string
File string
Path string
}
AllowList TomlAllowList
}
}
@@ -98,7 +97,7 @@ func NewConfig(options options.Options) (Config, error) {
if options.Config != "" {
_, err = toml.DecodeFile(options.Config, &tomlLoader)
// 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 {
_, err = toml.Decode(DefaultConfig, &tomlLoader)
}
@@ -119,40 +118,52 @@ func NewConfig(options options.Options) (Config, error) {
func (tomlLoader TomlLoader) Parse() (Config, error) {
var cfg Config
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)
if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
fileNameRe, err := regexp.Compile(rule.FileNameRegex)
fileNameRe, err := regexp.Compile(rule.File)
if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
filePathRe, err := regexp.Compile(rule.FilePathRegex)
filePathRe, err := regexp.Compile(rule.Path)
if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
// rule specific allowlists
var allowlists []Allowlist
for _, wl := range rule.Allowlist {
wlRe, err := regexp.Compile(wl.Regex)
var allowList AllowList
// rule specific regexes
for _, re := range rule.AllowList.Regexes {
allowListedRegex, err := regexp.Compile(re)
if err != nil {
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 {
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 {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
allowlists = append(allowlists, Allowlist{
Description: wl.Description,
File: wlFileNameRe,
Path: wlFilePathRe,
Regex: wlRe,
})
allowList.Paths = append(allowList.Paths, allowListedRegex)
}
var entropies []Entropy
@@ -184,46 +195,58 @@ func (tomlLoader TomlLoader) Parse() (Config, error) {
entropies = append(entropies, Entropy{Min: min, Max: max, Group: int(group)})
}
cfg.Rules = append(cfg.Rules, Rule{
Description: rule.Description,
Regex: re,
FileNameRegex: fileNameRe,
FilePathRegex: filePathRe,
Tags: rule.Tags,
Allowlist: allowlists,
Entropies: entropies,
})
r := Rule{
Description: rule.Description,
Regex: re,
File: fileNameRe,
Path: filePathRe,
ReportGroup: rule.ReportGroup,
Tags: rule.Tags,
AllowList: allowList,
Entropies: entropies,
}
cfg.Rules = append(cfg.Rules, r)
}
// global file name allowlists
for _, wlFileName := range tomlLoader.Allowlist.Files {
re, err := regexp.Compile(wlFileName)
// global regex allowLists
for _, allowListRegex := range tomlLoader.AllowList.Regexes {
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 {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
cfg.Allowlist.Files = append(cfg.Allowlist.Files, re)
}
// global file path allowlists
for _, wlFilePath := range tomlLoader.Allowlist.Paths {
re, err := regexp.Compile(wlFilePath)
// global file path allowLists
for _, allowListFilePath := range tomlLoader.AllowList.Paths {
re, err := regexp.Compile(allowListFilePath)
if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
cfg.Allowlist.Paths = append(cfg.Allowlist.Paths, re)
}
// global repo allowlists
for _, wlRepo := range tomlLoader.Allowlist.Repos {
re, err := regexp.Compile(wlRepo)
// global repo allowLists
for _, allowListRepo := range tomlLoader.AllowList.Repos {
re, err := regexp.Compile(allowListRepo)
if err != nil {
return cfg, fmt.Errorf("problem loading config: %v", err)
}
cfg.Allowlist.Repos = append(cfg.Allowlist.Repos, re)
}
cfg.Allowlist.Commits = tomlLoader.Allowlist.Commits
cfg.Allowlist.Description = tomlLoader.Allowlist.Description
cfg.Allowlist.Commits = tomlLoader.AllowList.Commits
cfg.Allowlist.Description = tomlLoader.AllowList.Description
return cfg, nil
}
+85 -3
View File
@@ -2,10 +2,12 @@ package config
import (
"fmt"
"io/ioutil"
"os"
"regexp"
"testing"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v6/options"
)
func TestParse(t *testing.T) {
@@ -15,7 +17,7 @@ func TestParse(t *testing.T) {
wantErr error
wantFileRegex *regexp.Regexp
wantMessages *regexp.Regexp
wantAllowlist Allowlist
wantAllowlist AllowList
}{
{
description: "default config",
@@ -122,10 +124,90 @@ func TestParse(t *testing.T) {
_, err := NewConfig(test.opts)
if err != nil {
if test.wantErr == nil {
t.Error(err)
t.Error(test.description, err)
} else if test.wantErr.Error() != err.Error() {
t.Errorf("expected err: %s, got %s", test.wantErr, err)
}
}
}
}
// TestParseFields will test that fields are properly parsed from a config. As fields are added, then please
// add tests here.
func TestParseFields(t *testing.T) {
tomlConfig := `
[[rules]]
description = "Some Groups without a reportGroup"
regex = '(.)(.)'
[[rules]]
description = "Some Groups"
regex = '(.)(.)'
reportGroup = 1
`
configPath, err := writeTestConfig(tomlConfig)
defer os.Remove(configPath)
if err != nil {
t.Fatal(err)
}
config, err := NewConfig(options.Options{Config: configPath})
if err != nil {
t.Fatalf("Couldn't parse config: %v", err)
}
expectedRuleFields := []struct {
Description string
ReportGroup int
}{
{
Description: "Some Groups without a reportGroup",
ReportGroup: 0,
},
{
Description: "Some Groups",
ReportGroup: 1,
},
}
if len(config.Rules) != len(expectedRuleFields) {
t.Fatalf("expected %v rules", len(expectedRuleFields))
}
for _, expected := range expectedRuleFields {
rule, err := findRuleByDescription(config.Rules, expected.Description)
if err != nil {
t.Fatal(err)
}
if rule.ReportGroup != expected.ReportGroup {
t.Errorf("expected the rule with description '%v' to have a ReportGroup of %v", expected.Description, expected.ReportGroup)
}
}
}
func findRuleByDescription(rules []Rule, description string) (*Rule, error) {
for _, rule := range rules {
if rule.Description == description {
return &rule, nil
}
}
return nil, fmt.Errorf("Couldn't find rule with the description: %s", description)
}
func writeTestConfig(toml string) (string, error) {
tmpfile, err := ioutil.TempFile("", "testConfig")
if err != nil {
return "", fmt.Errorf("Couldn't create test config got: %w", err)
}
if _, err := tmpfile.Write([]byte(toml)); err != nil {
return "", fmt.Errorf("Couldn't create test config got: %w", err)
}
if err := tmpfile.Close(); err != nil {
return "", fmt.Errorf("Couldn't create test config got: %w", err)
}
return tmpfile.Name(), nil
}
+21 -29
View File
@@ -129,8 +129,8 @@ title = "gitleaks config"
[[rules]]
description = "Port"
regex = '''(?i)port(.{0,4})?[0-9]{1,10}'''
[[rules.allowlist]]
regex = '''(?i)port '''
[rules.allowlist]
regexes = ['''(?i)port ''']
description = "ignore export "
@@ -139,8 +139,8 @@ title = "gitleaks config"
description = "Email"
regex = '''[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}'''
tags = ["email"]
[[rules.allowlist]]
file = '''(?i)bashrc'''
[rules.allowlist]
files = ['''(?i)bashrc''']
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})['|"]'''
tags = ["key", "API", "generic"]
# ignore leaks with specific identifiers like slack and aws
[[rules.allowlist]]
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})'''
description = "ignore slack"
[[rules.allowlist]]
description = "MailChimp API key"
regex = '''(?i)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
[[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.allowlist]
description = "ignore slack, mailchimp, aws"
regexes = [
'''xox[baprs]-([0-9a-zA-Z]{10,48})''',
'''(?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]]
description = "High Entropy"
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"]
[[rules.Entropies]]
Min = "4.3"
Max = "7.0"
[[rules.allowlist]]
description = "ignore ssh key and pems"
file = '''(pem|ppk|env)$'''
path = '''(.*)?ssh'''
[[rules.Entropies]]
Min = "4.3"
Max = "7.0"
[rules.allowlist]
description = "ignore ssh key and pems"
files = ['''(pem|ppk|env)$''']
paths = ['''(.*)?ssh''']
[[rules]]
description = "Potential bash var"
@@ -195,8 +186,9 @@ title = "gitleaks config"
[[rules]]
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]
description = "image allowlists"
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"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
tags = ["key", "AWS"]
[[rules.allowlist]]
regex = '''AKIAIO5FODNN7EXAMPLE.*'''
description = "ignore example aws key"
[rules.allowlist]
regexes = ['''AKIAIO5FODNN7EXAMPLE.*''']
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
-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-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/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/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
+5 -5
View File
@@ -6,9 +6,9 @@ import (
"strings"
"sync"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v5/scan"
"github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v6/options"
"github.com/zricethezav/gitleaks/v6/scan"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
@@ -176,9 +176,9 @@ func (g *Github) ScanPR() {
continue
}
repo.CheckRules(&scan.Bundle{
Content: *f.Patch,
Content: *f.Patch,
FilePath: *f.Filename,
Commit: &commitObj,
Commit: &commitObj,
})
}
}
+7 -3
View File
@@ -4,9 +4,9 @@ import (
"context"
"sync"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v5/scan"
"github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v6/options"
"github.com/zricethezav/gitleaks/v6/scan"
log "github.com/sirupsen/logrus"
"github.com/xanzy/go-gitlab"
@@ -93,6 +93,10 @@ func (g *Gitlab) Scan() {
cloneOpts := g.manager.CloneOptions
cloneOpts.URL = p.HTTPURLToRepo
err := r.Clone(cloneOpts)
if err != nil {
log.Error(err)
continue
}
// TODO handle clone retry with ssh like github host
r.Name = p.Name
+1 -1
View File
@@ -3,7 +3,7 @@ package hosts
import (
"strings"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v6/manager"
)
const (
+3 -3
View File
@@ -6,9 +6,9 @@ import (
"os"
"testing"
"github.com/zricethezav/gitleaks/v5/config"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v6/options"
)
var (
+5 -5
View File
@@ -5,11 +5,11 @@ import (
"os"
"time"
"github.com/zricethezav/gitleaks/v5/config"
"github.com/zricethezav/gitleaks/v5/hosts"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v5/scan"
"github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v6/hosts"
"github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v6/options"
"github.com/zricethezav/gitleaks/v6/scan"
"github.com/hako/durafmt"
log "github.com/sirupsen/logrus"
+4 -45
View File
@@ -2,7 +2,6 @@ package manager
import (
"crypto/sha1"
"encoding/csv"
"encoding/hex"
"encoding/json"
"fmt"
@@ -14,8 +13,8 @@ import (
"text/tabwriter"
"time"
"github.com/zricethezav/gitleaks/v5/config"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v6/options"
"github.com/go-git/go-git/v5"
"github.com/hako/durafmt"
@@ -89,7 +88,7 @@ type Metadata struct {
RegexTime map[string]int64
Commits int
ScanTime int64
ScanTime int64
patchTime int64
cloneTime int64
}
@@ -252,7 +251,7 @@ func (manager *Manager) DebugOutput() {
w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, '.', 0)
log.Debugf("--------------------------\n")
log.Debugf("| Individual Regex Times |\n")
log.Debugf("| Individual Regexes Times |\n")
log.Debugf("--------------------------\n")
for k, v := range manager.metadata.RegexTime {
_, _ = 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() {
<-manager.stopChan
+4 -4
View File
@@ -3,8 +3,8 @@ package manager
import (
"crypto/rand"
"fmt"
"github.com/zricethezav/gitleaks/v5/config"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v6/options"
"io"
"testing"
)
@@ -45,14 +45,14 @@ func TestSendReceiveLeaks(t *testing.T) {
func TestSendReceiveMeta(t *testing.T) {
tests := []struct {
scanTime int64
scanTime int64
patchTime int64
cloneTime int64
regexTime int64
iterations int
}{
{
scanTime: 1000,
scanTime: 1000,
patchTime: 1000,
cloneTime: 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"
"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/plumbing/transport/http"
@@ -28,35 +28,40 @@ const (
// Options stores values of command line options
type Options struct {
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from scan"`
Repo string `short:"r" long:"repo" description:"Target repository"`
Config string `long:"config" description:"config path"`
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
Version bool `long:"version" description:"version number"`
Username string `long:"username" description:"Username for git repo"`
Password string `long:"password" description:"Password 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"`
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
SSH string `long:"ssh-key" description:"path to ssh key used for auth"`
Uncommited bool `long:"uncommitted" description:"run gitleaks on uncommitted code"`
RepoPath string `long:"repo-path" description:"Path to repo"`
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
Branch string `long:"branch" description:"Branch to scan"`
Report string `long:"report" description:"path to write json leaks file"`
ReportFormat string `long:"report-format" default:"json" description:"json or csv"`
Redact bool `long:"redact" description:"redact secrets from log messages and leaks"`
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\""`
PrettyPrint bool `long:"pretty" description:"Pretty print json if leaks are present"`
CommitFrom string `long:"commit-from" description:"Commit to start scan from"`
CommitTo string `long:"commit-to" description:"Commit to stop scan"`
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"`
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from scan"`
Repo string `short:"r" long:"repo" description:"Target repository"`
Config string `long:"config" description:"config path"`
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
Version bool `long:"version" description:"version number"`
Username string `long:"username" description:"Username for git repo"`
Password string `long:"password" description:"Password for git repo"`
AccessToken string `long:"access-token" description:"Access token for git repo"`
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"`
SSH string `long:"ssh-key" description:"path to ssh key used for auth"`
Uncommited bool `long:"uncommitted" description:"run gitleaks on uncommitted code"`
RepoPath string `long:"repo-path" description:"Path to repo"`
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
Branch string `long:"branch" description:"Branch to scan"`
Report string `long:"report" description:"path to write json leaks file"`
ReportFormat string `long:"report-format" default:"json" description:"json, csv, sarif"`
Redact bool `long:"redact" description:"redact secrets from log messages and leaks"`
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\""`
PrettyPrint bool `long:"pretty" description:"Pretty print json if leaks are present"`
// Commit Options
Commit string `long:"commit" description:"sha of commit to scan or \"latest\" to scan the last commit of the repository"`
Commits string `long:"commits" description:"comma separated list of a commits to scan"`
CommitsFile string `long:"commits-file" description:"file of new line separated list of a commits to scan"`
CommitFrom string `long:"commit-from" description:"Commit to start scan from"`
CommitTo string `long:"commit-to" description:"Commit to stop scan"`
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
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"
"time"
"github.com/zricethezav/gitleaks/v5/config"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v6/manager"
"github.com/BurntSushi/toml"
"github.com/go-git/go-billy/v5"
@@ -77,11 +77,11 @@ func Run(m *manager.Manager) error {
func runHelper(r *Repo) error {
// Ignore allowlisted repos
for _, wlRepo := range r.Manager.Config.Allowlist.Repos {
if RegexMatched(r.Manager.Opts.RepoPath, wlRepo) {
for _, allowListedRepo := range r.Manager.Config.Allowlist.Repos {
if RegexMatched(r.Manager.Opts.RepoPath, allowListedRepo) {
return nil
}
if RegexMatched(r.Manager.Opts.Repo, wlRepo) {
if RegexMatched(r.Manager.Opts.Repo, allowListedRepo) {
return nil
}
}
@@ -201,6 +201,10 @@ func getLogOptions(repo *Repo) (*git.LogOptions, error) {
}
return nil
})
if err != nil {
return nil, err
}
if logOpts.From.IsZero() {
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()
var tomlLoader config.TomlLoader
_, err = toml.DecodeReader(f, &tomlLoader)
if err != nil {
return config.Config{}, err
}
return tomlLoader.Parse()
}
+61 -57
View File
@@ -11,8 +11,8 @@ import (
"strings"
"time"
"github.com/zricethezav/gitleaks/v5/config"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v6/manager"
fdiff "github.com/go-git/go-git/v5/plumbing/format/diff"
"github.com/go-git/go-git/v5/plumbing/object"
@@ -20,11 +20,12 @@ import (
)
const (
diffAddPrefix = "+"
diffAddFilePrefix = "+++ b"
diffAddFilePrefixSlash = "+++ b/"
diffLineSignature = " @@"
defaultLineNumber = -1
diffAddPrefix = "+"
diffAddFilePrefix = "+++ b"
diffAddFilePrefixSlash = "+++ b/"
diffLineSignature = " @@"
diffLineSignaturePrefix = "@@ "
defaultLineNumber = -1
)
// 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()
// 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
}
// 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
}
// 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
}
@@ -76,18 +77,18 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
if !ruleContainRegex(rule) {
repo.Manager.SendLeaks(manager.Leak{
LineNumber: defaultLineNumber,
Line: "N/A",
Offender: "Filename/path offender: " + filename,
Commit: bundle.Commit.Hash.String(),
Repo: repo.Name,
Message: bundle.Commit.Message,
Rule: rule.Description,
Author: bundle.Commit.Author.Name,
Email: bundle.Commit.Author.Email,
Date: bundle.Commit.Author.When,
Tags: strings.Join(rule.Tags, ", "),
File: filename,
Operation: diffOpToString(bundle.Operation),
Line: "N/A",
Offender: "Filename/path offender: " + filename,
Commit: bundle.Commit.Hash.String(),
Repo: repo.Name,
Message: bundle.Commit.Message,
Rule: rule.Description,
Author: bundle.Commit.Author.Name,
Email: bundle.Commit.Author.Email,
Date: bundle.Commit.Author.When,
Tags: strings.Join(rule.Tags, ", "),
File: filename,
Operation: diffOpToString(bundle.Operation),
})
} else {
//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]]
groups := rule.Regex.FindStringSubmatch(offender)
if isOffenderWhiteListed(offender, rule.Allowlist) {
if isAllowListed(line, append(rule.AllowList.Regexes, repo.config.Allowlist.Regexes...)) {
continue
}
@@ -120,6 +121,11 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
continue
}
// 0 is a match for the full regex pattern
if 0 < rule.ReportGroup && rule.ReportGroup < len(groups) {
offender = groups[rule.ReportGroup]
}
leak := manager.Leak{
LineNumber: defaultLineNumber,
Line: line,
@@ -146,7 +152,6 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
}
}
// TODO should return filenameRegex if only file rule
repo.Manager.RecordTime(manager.RegexTime{
Time: howLong(start),
Regex: rule.Regex.String(),
@@ -200,7 +205,15 @@ func extractAndInjectLineNumber(leak *manager.Leak, bundle *Bundle, repo *Repo)
if bundle.Patch == "" {
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.Buffer(buf, len(bundle.Patch))
scanner.Split(bufio.ScanLines)
currFile := ""
currLine := 0
currStartDiffLine := 0
@@ -231,6 +244,19 @@ func extractAndInjectLineNumber(leak *manager.Leak, bundle *Bundle, repo *Repo)
leak.LineNumber = potentialLine
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++
}
@@ -331,28 +357,28 @@ func ruleContainRegex(rule config.Rule) bool {
}
// Checks if the given rule has a file name regex
func ruleContainFileNameRegex(rule config.Rule) bool {
if rule.FileNameRegex == nil {
func ruleContainFileRegex(rule config.Rule) bool {
if rule.File == nil {
return false
}
if rule.FileNameRegex.String() == "" {
if rule.File.String() == "" {
return false
}
return true
}
// Checks if the given rule has a file path regex
func ruleContainFilePathRegex(rule config.Rule) bool {
if rule.FilePathRegex == nil {
func ruleContainPathRegex(rule config.Rule) bool {
if rule.Path == nil {
return false
}
if rule.FilePathRegex.String() == "" {
if rule.Path.String() == "" {
return false
}
return true
}
func isCommitWhiteListed(commitHash string, allowlistedCommits []string) bool {
func isCommitAllowListed(commitHash string, allowlistedCommits []string) bool {
for _, hash := range allowlistedCommits {
if commitHash == hash {
return true
@@ -361,36 +387,14 @@ func isCommitWhiteListed(commitHash string, allowlistedCommits []string) bool {
return false
}
func isOffenderWhiteListed(offender string, allowlist []config.Allowlist) bool {
if len(allowlist) != 0 {
for _, wl := range allowlist {
if wl.Regex.FindString(offender) != "" {
func isAllowListed(target string, allowList []*regexp.Regexp) bool {
if len(allowList) != 0 {
for _, re := range allowList {
if re.FindString(target) != "" {
return true
}
}
}
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
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
"strings"
"sync"
"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/plumbing"
@@ -71,11 +74,36 @@ func (repo *Repo) Scan() error {
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 != "" {
return scanCommit(repo.Manager.Opts.Commit, repo, scanCommitPatches)
} else if repo.Manager.Opts.FilesAtCommit != "" {
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)
@@ -96,7 +124,7 @@ func (repo *Repo) Scan() error {
}
// 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
}
@@ -113,41 +141,47 @@ func (repo *Repo) Scan() error {
// increase Commit counter
cc++
err = c.Parents().ForEach(func(parent *object.Commit) error {
defer func() {
if err := recover(); err != nil {
// sometimes the Patch generation will fail due to a known bug in
// sergi's go-diff: https://github.com/sergi/go-diff/issues/89.
// Once a fix has been merged I will remove this recover.
return
}
}()
if repo.timeoutReached() {
return nil
}
if parent == nil {
// shouldn't reach this point but just in case
return nil
}
// inspect first parent only as all other parents will be eventually reached
// (they exist as the tip of other branches, etc)
// See https://github.com/zricethezav/gitleaks/issues/413 for details
parent, err := c.Parent(0)
if err != nil {
return err
}
start := time.Now()
patch, err := parent.Patch(c)
if err != nil {
return fmt.Errorf("could not generate Patch")
defer func() {
if err := recover(); err != nil {
// sometimes the Patch generation will fail due to a known bug in
// 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)
semaphore <- true
go func(c *object.Commit, patch *object.Patch) {
defer func() {
<-semaphore
wg.Done()
}()
scanPatch(patch, c, repo)
}(c, patch)
}()
if repo.timeoutReached() {
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 {
return storer.ErrStop
}
@@ -169,6 +203,9 @@ func (repo *Repo) scanEmpty() error {
}
status, err := wt.Status()
if err != nil {
return err
}
for fn := range status {
workTreeBuf := bytes.NewBuffer(nil)
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
for _, d := range diffs {
if d.Type == diffmatchpatch.DiffInsert {
+58 -5
View File
@@ -10,9 +10,9 @@ import (
"sort"
"testing"
"github.com/zricethezav/gitleaks/v5/config"
"github.com/zricethezav/gitleaks/v5/manager"
"github.com/zricethezav/gitleaks/v5/options"
"github.com/zricethezav/gitleaks/v6/config"
"github.com/zricethezav/gitleaks/v6/manager"
"github.com/zricethezav/gitleaks/v6/options"
"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",
},
{
description: "test local repo two leaks range Commit",
description: "test local repo two leaks to from Commit",
opts: options.Options{
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",
CommitFrom: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a",
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",
},
{
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",
opts: options.Options{
@@ -124,6 +144,17 @@ func TestScan(t *testing.T) {
},
wantEmpty: true,
},
{
description: "test local repo three leaks dev branch with reportGroup set",
opts: options.Options{
RepoPath: "../test_data/test_repos/test_repo_3",
Report: "../test_data/test_local_repo_three_leaks_with_report_groups.json.got",
Config: "../test_data/test_configs/aws_key_with_report_groups.toml",
Branch: "dev",
ReportFormat: "json",
},
wantPath: "../test_data/test_local_repo_three_leaks_with_report_groups.json",
},
{
description: "test local repo three leaks dev branch",
opts: options.Options{
@@ -376,6 +407,25 @@ func TestScan(t *testing.T) {
},
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 {
@@ -403,6 +453,9 @@ func TestScan(t *testing.T) {
}
err = m.Report()
if err != nil {
t.Error(err)
}
if test.wantEmpty {
if len(m.GetLeaks()) != 0 {
@@ -2,13 +2,7 @@
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 md files"
file = '''(.*)?md$'''
[[rules.allowlist]]
description = "ignore this regex"
regex = '''ignore$'''
[[rules.allowlist]]
description = "ignore regex and md files"
regex = '''ignore$'''
file = '''(.*)?md$'''
[rules.allowlist]
description = "ignore sample regex md files"
files = ['''(.*)?md$''']
regexes = ['''ignore$''']
@@ -2,6 +2,6 @@
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]]
[rules.allowlist]
description = "ignore python files"
file = '''(.*)?py$'''
files = ['''(.*)?py$''']
@@ -2,6 +2,6 @@
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]]
regex = '''AKIAIO5FODNN7EXAMPLE.*'''
[rules.allowlist]
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}'''
tags = ["key", "AWS"]
## this is an example of a rule that won't work
[[rules]]
description = "Python files"
fileRegex = '''(.*)?py$'''
fileRegex = "(?i)*.py"
@@ -0,0 +1,10 @@
[[rules]]
description = "AWS Secret Key"
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
tags = ["key", "AWS"]
[[rules]]
description = "AWS Manager ID"
regex = '''AWS secret: ("?)((A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16})("?)'''
tags = ["key", "AWS"]
reportGroup = 2
+8 -8
View File
@@ -125,19 +125,19 @@ title = "gitleaks config"
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]]
[rules.allowlist]
description = "ignore common jenkins functions"
regex = '''allowlistme'''
file = '''(.*)?Jenkinsfile$'''
[[rules.allowlist]]
description = "ignore common jenkins functions2"
regex = '''allowlistme'''
file = '''(.*)?Jenkinsfile$'''
regexes = [
'''allowlistme'''
]
files = [
'''(.*)?Jenkinsfile$'''
]
# Global rules. This instructs gitleaks to ignore all .pem files or if a message with
[[rules]]
description = "Files with keys and credentials"
fileRegex = '''(.*?)(pem)'''
file = '''(.*?)(pem)'''
[allowlist]
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]]
description = "Generic password"
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"]
+1 -1
View File
@@ -2,5 +2,5 @@
[[rules]]
description = "AWS Manager ID"
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"]
@@ -2,6 +2,6 @@
[[rules]]
description = "Generic password"
regex = '''(?i)(password|token).{0,20}?\s*[:|=]\s*?(?-i)([0-9a-zA-Z\/+]{4,40})'''
fileNameRegex = '''.*\.properties'''
filePathRegex = '''config(guration)?'''
file = '''.*\.properties'''
path = '''config(guration)?'''
tags = ["key", "Yml", "Yaml"]
+60
View File
@@ -133,5 +133,65 @@
"date": "2020-02-24T14:13:15-05:00",
"tags": "key, AWS",
"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",
"tags": "key, AWS",
"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",
"tags": "key, AWS",
"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',",
"lineNumber": 5,
@@ -28,20 +13,5 @@
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS",
"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"
}
]
@@ -0,0 +1,47 @@
[
{
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 6,
"offender": "AKIALALEMEL33243OLIA",
"commit": "deea550dd6c7acaf0e59432600593533984a2125",
"repo": "test_repo_3",
"rule": "AWS Manager ID",
"commitMessage": "dev branch\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:35:03-04:00",
"tags": "key, AWS",
"operation": "addition"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
"lineNumber": 5,
"offender": "AKIALALEMEL33243OLIA",
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
"repo": "test_repo_3",
"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_3",
"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"
}
]
@@ -13,5 +13,20 @@
"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,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 123 files, more files were not shown because too many files have changed in this diff. Show more