mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b07625567 | ||
|
|
0cabbf8ca8 | ||
|
|
ba9e089e35 | ||
|
|
31ff8677dd | ||
|
|
3e5e63956e | ||
|
|
57f9bc83d1 | ||
|
|
6e72472b60 | ||
|
|
9326f35380 | ||
|
|
19555579c8 | ||
|
|
60dd607312 | ||
|
|
c3b799ec63 | ||
|
|
4b6f4d0de5 | ||
|
|
fbfb3f591e | ||
|
|
b91799aa18 | ||
|
|
db1b54bf9f | ||
|
|
e9529744f8 | ||
|
|
d1f642a9df | ||
|
|
9261f1c47f | ||
|
|
991223abab | ||
|
|
801d44a6e4 | ||
|
|
44d7d89e19 | ||
|
|
aae23acff3 | ||
|
|
705595aaf6 | ||
|
|
43ec22429f |
No files matched your search
@@ -11,8 +11,6 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
GO111MODULE: on
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
@@ -26,8 +24,6 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
GO111MODULE: on
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ FROM golang:1.17 AS build
|
|||||||
WORKDIR /go/src/github.com/zricethezav/gitleaks
|
WORKDIR /go/src/github.com/zricethezav/gitleaks
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN VERSION=$(git describe --tags --abbrev=0) && \
|
RUN VERSION=$(git describe --tags --abbrev=0) && \
|
||||||
GO111MODULE=on CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X="github.com/zricethezav/gitleaks/v8/cmd.Version=${VERSION}
|
CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X="github.com/zricethezav/gitleaks/v8/cmd.Version=${VERSION}
|
||||||
|
|
||||||
FROM alpine:3.14.2
|
FROM alpine:3.14.2
|
||||||
RUN adduser -D gitleaks && \
|
RUN adduser -D gitleaks && \
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v8/cmd.Version=$(VERSION)"
|
|||||||
COVER=--cover --coverprofile=cover.out
|
COVER=--cover --coverprofile=cover.out
|
||||||
|
|
||||||
test-cover:
|
test-cover:
|
||||||
go test ./... --race $(COVER) $(PKG) -v
|
go test -v ./... --race $(COVER) $(PKG)
|
||||||
go tool cover -html=cover.out
|
go tool cover -html=cover.out
|
||||||
|
|
||||||
format:
|
format:
|
||||||
@@ -14,7 +14,7 @@ format:
|
|||||||
|
|
||||||
test: format
|
test: format
|
||||||
go vet ./...
|
go vet ./...
|
||||||
go test ./... --race $(PKG) -v
|
go test -v ./... --race $(PKG)
|
||||||
|
|
||||||
build: format
|
build: format
|
||||||
go vet ./...
|
go vet ./...
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
# gitleaks
|
||||||
```
|
```
|
||||||
○
|
┌─○───┐
|
||||||
│╲
|
│ │╲ │
|
||||||
│ ○
|
│ │ ○ │
|
||||||
○ ░
|
│ ○ ░ │
|
||||||
░ gitleaks
|
└─░───┘
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ Use "gitleaks [command] --help" for more information about a command.
|
|||||||
### Commands
|
### Commands
|
||||||
There are two commands you will use to detect secrets; `detect` and `protect`.
|
There are two commands you will use to detect secrets; `detect` and `protect`.
|
||||||
#### Detect
|
#### Detect
|
||||||
The `detect` command is used to scan repos, directories, and files. This comand can be used on developer machines and in CI environments.
|
The `detect` command is used to scan repos, directories, and files. This command can be used on developer machines and in CI environments.
|
||||||
|
|
||||||
When running `detect` on a git repository, gitleaks will parse the output of a `git log -p` command (you can see how this executed
|
When running `detect` on a git repository, gitleaks will parse the output of a `git log -p` command (you can see how this executed
|
||||||
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L17-L25)).
|
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L17-L25)).
|
||||||
@@ -200,97 +200,77 @@ title = "Gitleaks title"
|
|||||||
# An array of tables that contain information that define instructions
|
# An array of tables that contain information that define instructions
|
||||||
# on how to detect secrets
|
# on how to detect secrets
|
||||||
[[rules]]
|
[[rules]]
|
||||||
|
|
||||||
# Unique identifier for this rule
|
# Unique identifier for this rule
|
||||||
id = "awesome-rule-1"
|
id = "awesome-rule-1"
|
||||||
|
|
||||||
# Short human readable description of the rule.
|
# Short human readable description of the rule.
|
||||||
description = "awsome rule 1"
|
description = "awesome rule 1"
|
||||||
|
|
||||||
# Golang regular expression used to detect secrets. Note Golang's regex engine
|
# Golang regular expression used to detect secrets. Note Golang's regex engine
|
||||||
# does not support lookaheads.
|
# does not support lookaheads.
|
||||||
regex = '''one-go-style-regex-for-this-rule'''
|
regex = '''one-go-style-regex-for-this-rule'''
|
||||||
|
|
||||||
# Golang regular expression used to match paths. This can be used as a standalone rule or it can be used
|
# Golang regular expression used to match paths. This can be used as a standalone rule or it can be used
|
||||||
# in conjunction with a valid `regex` entry.
|
# in conjunction with a valid `regex` entry.
|
||||||
path = '''a-file-path-regex'''
|
path = '''a-file-path-regex'''
|
||||||
|
|
||||||
# Array of strings used for metadata and reporting purposes.
|
# Array of strings used for metadata and reporting purposes.
|
||||||
tags = ["tag","another tag"]
|
tags = ["tag","another tag"]
|
||||||
|
|
||||||
# Int used to extract secret from regex match and used as the group that will have
|
# Int used to extract secret from regex match and used as the group that will have
|
||||||
# its entropy checked if `entropy` is set.
|
# its entropy checked if `entropy` is set.
|
||||||
secretGroup = 3
|
secretGroup = 3
|
||||||
|
|
||||||
# Float representing the minimum shannon entropy a regex group must have to be considered a secret.
|
# Float representing the minimum shannon entropy a regex group must have to be considered a secret.
|
||||||
entropy = 3.5
|
entropy = 3.5
|
||||||
|
|
||||||
# You can include an allowlist table for a single rule to reduce false positives or ignore commits
|
# You can include an allowlist table for a single rule to reduce false positives or ignore commits
|
||||||
# with known/rotated secrets
|
# with known/rotated secrets
|
||||||
[rules.allowlist]
|
[rules.allowlist]
|
||||||
description = "ignore commit A"
|
description = "ignore commit A"
|
||||||
commits = [ "commit-A", "commit-B"]
|
commits = [ "commit-A", "commit-B"]
|
||||||
paths = ['''one-file-path-regex''']
|
paths = [
|
||||||
regexes = ['''one-regex-within-the-already-matched-regex''']
|
'''go\.mod''',
|
||||||
|
'''go\.sum'''
|
||||||
|
]
|
||||||
|
regexes = [
|
||||||
|
'''process''',
|
||||||
|
'''getenv''',
|
||||||
|
]
|
||||||
|
|
||||||
# This is a global allowlist which has a higher order of precendence than rule-specific allowlists.
|
# This is a global allowlist which has a higher order of precedence than rule-specific allowlists.
|
||||||
# If a commit listed in the `commits` field below is encountered then that commit will be skipped and no
|
# If a commit listed in the `commits` field below is encountered then that commit will be skipped and no
|
||||||
# secrets will be detected for said commit. The same logic applies for regexes and paths.
|
# secrets will be detected for said commit. The same logic applies for regexes and paths.
|
||||||
[allowlist]
|
[allowlist]
|
||||||
description = "ignore commit A"
|
description = "global allow list"
|
||||||
commits = [ "commit-A", "commit-B"]
|
commits = [ "commit-A", "commit-B", "commit-C"]
|
||||||
paths = ['''one-file-path-regex''']
|
paths = [
|
||||||
regexes = ['''one-regex-within-the-already-matched-regex''']
|
'''gitleaks\.toml''',
|
||||||
|
'''(.*?)(jpg|gif|doc)'''
|
||||||
|
]
|
||||||
|
regexes = [
|
||||||
|
'''219-09-9999''',
|
||||||
|
'''078-05-1120''',
|
||||||
|
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
|
||||||
|
]
|
||||||
```
|
```
|
||||||
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples and advice on writing regular expressions for secret detection.
|
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples and advice on writing regular expressions for secret detection.
|
||||||
|
|
||||||
### Tips on Writing Regular Expressions
|
|
||||||
Gitleaks rules are defined by regular expressions and entropy ranges.
|
|
||||||
Some secrets have unique signatures which make detecting those secrets easy.
|
|
||||||
Examples of those secrets would be Gitlab Personal Access Tokens, AWS keys, and Github Access Tokens.
|
|
||||||
All these examples have defined prefixes like `glpat`, `AKIA`, `ghp_`, etc.
|
|
||||||
|
|
||||||
Other secrets might just be a hash which means we need to write more complex rules to verify
|
|
||||||
that what we are matching is a secret.
|
|
||||||
|
|
||||||
Here is an example of a semi-generic secret
|
|
||||||
```
|
|
||||||
discord_client_secret = "8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ"
|
|
||||||
```
|
|
||||||
We can write a regular expression to capture the variable name (identifier),
|
|
||||||
the assignment symbol (like '=' or ':='), and finally the actual secret.
|
|
||||||
The structure of a rule to match this example secret is below:
|
|
||||||
|
|
||||||
Beginning string
|
|
||||||
quotation
|
|
||||||
│ End string quotation
|
|
||||||
│ │
|
|
||||||
▼ ▼
|
|
||||||
(?i)(discord[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9=_\-]{32})['\"]
|
|
||||||
|
|
||||||
▲ ▲ ▲
|
|
||||||
│ │ │
|
|
||||||
│ │ │
|
|
||||||
identifier assignment symbol
|
|
||||||
Secret
|
|
||||||
|
|
||||||
|
|
||||||
#### A Note on Generic Secrets
|
|
||||||
Let's continue with the example `discord_client_secret = "8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ"`.
|
|
||||||
This secret would match both the `discord-client-secret` rule and the `generic-api-key` rule in the default config.
|
|
||||||
```
|
|
||||||
[[rules]]
|
|
||||||
id = "discord-client-secret"
|
|
||||||
description = "Discord client secret"
|
|
||||||
regex = '''(?i)(discord[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9=_\-]{32})['\"]'''
|
|
||||||
secretGroup = 3
|
|
||||||
|
|
||||||
[[rules]]
|
|
||||||
id = "generic-api-key"
|
|
||||||
description = "Generic API Key"
|
|
||||||
regex = '''(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]'''
|
|
||||||
entropy = 3.7
|
|
||||||
secretGroup = 4
|
|
||||||
```
|
|
||||||
If gitleaks encountered `discord_client_secret = "8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ"`, only the `discord` rule would report a finding because
|
|
||||||
the generic rule has the string `generic` somewhere in the rule's `id`. If a secret is encountered and both a `generic` and non-generic rule have discovered the same secret, the non-generic
|
|
||||||
will be given precedence.
|
|
||||||
|
|
||||||
|
|
||||||
## Sponsorships
|
## Sponsorships
|
||||||
[](https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks)
|
<p align="left">
|
||||||
|
<a href="https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">
|
||||||
|
<img alt="Tines Sponsorship" src="https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png" width=200>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<a href="https://www.typeform.com/">
|
||||||
|
<img src="https://user-images.githubusercontent.com/15034943/146945294-a6473d55-86b8-4f53-941e-7f185ad6b3d7.png" width=200/>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Exit Codes
|
## Exit Codes
|
||||||
|
|||||||
+68
-33
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
"github.com/zricethezav/gitleaks/v8/detect"
|
"github.com/zricethezav/gitleaks/v8/detect"
|
||||||
"github.com/zricethezav/gitleaks/v8/git"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
"github.com/zricethezav/gitleaks/v8/report"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,56 +34,92 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
viper.Unmarshal(&vc)
|
// Load config
|
||||||
|
if err = viper.Unmarshal(&vc); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("Failed to load config")
|
||||||
|
}
|
||||||
cfg, err := vc.Translate()
|
cfg, err := vc.Translate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Failed to load config")
|
log.Fatal().Err(err).Msg("Failed to load config")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Path, _ = cmd.Flags().GetString("config")
|
cfg.Path, _ = cmd.Flags().GetString("config")
|
||||||
source, _ := cmd.Flags().GetString("source")
|
|
||||||
logOpts, _ := cmd.Flags().GetString("log-opts")
|
// start timer
|
||||||
verbose, _ := cmd.Flags().GetBool("verbose")
|
|
||||||
redact, _ := cmd.Flags().GetBool("redact")
|
|
||||||
noGit, _ := cmd.Flags().GetBool("no-git")
|
|
||||||
exitCode, _ := cmd.Flags().GetInt("exit-code")
|
|
||||||
if cfg.Path == "" {
|
|
||||||
cfg.Path = filepath.Join(source, ".gitleaks.toml")
|
|
||||||
}
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
if noGit {
|
// Setup detector
|
||||||
if logOpts != "" {
|
detector := detect.NewDetector(cfg)
|
||||||
log.Fatal().Err(err).Msg("--log-opts cannot be used with --no-git")
|
detector.Config.Path, err = cmd.Flags().GetString("config")
|
||||||
}
|
if err != nil {
|
||||||
findings, err = detect.FromFiles(source, cfg, detect.Options{
|
log.Fatal().Err(err)
|
||||||
Verbose: verbose,
|
}
|
||||||
Redact: redact,
|
source, err := cmd.Flags().GetString("source")
|
||||||
})
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal().Err(err)
|
||||||
log.Fatal().Err(err).Msg("Failed to scan files")
|
}
|
||||||
}
|
// if config path is not set, then use the {source}/.gitleaks.toml path.
|
||||||
} else {
|
// note that there may not be a `{source}/.gitleaks.toml` file, this is ok.
|
||||||
files, err := git.GitLog(source, logOpts)
|
if detector.Config.Path == "" {
|
||||||
if err != nil {
|
detector.Config.Path = filepath.Join(source, ".gitleaks.toml")
|
||||||
log.Fatal().Err(err).Msg("Failed to get git log")
|
}
|
||||||
}
|
// set verbose flag
|
||||||
|
if detector.Verbose, err = cmd.Flags().GetBool("verbose"); err != nil {
|
||||||
findings = detect.FromGit(files, cfg, detect.Options{Verbose: verbose, Redact: redact})
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
// set redact flag
|
||||||
|
if detector.Redact, err = cmd.Flags().GetBool("redact"); err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set exit code
|
||||||
|
exitCode, err := cmd.Flags().GetInt("exit-code")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine what type of scan:
|
||||||
|
// - git: scan the history of the repo
|
||||||
|
// - no-git: scan files by treating the repo as a plain directory
|
||||||
|
noGit, err := cmd.Flags().GetBool("no-git")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// start the detector scan
|
||||||
|
if noGit {
|
||||||
|
findings, err = detector.DetectFiles(source)
|
||||||
|
if err != nil {
|
||||||
|
// don't exit on error, just log it
|
||||||
|
log.Error().Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
logOpts, err := cmd.Flags().GetString("log-opts")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
findings, err = detector.DetectGit(source, logOpts, detect.DetectType)
|
||||||
|
if err != nil {
|
||||||
|
// don't exit on error, just log it
|
||||||
|
log.Error().Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// log info about the scan
|
||||||
|
log.Info().Msgf("scan completed in %s", time.Since(start))
|
||||||
if len(findings) != 0 {
|
if len(findings) != 0 {
|
||||||
log.Warn().Msgf("leaks found: %d", len(findings))
|
log.Warn().Msgf("leaks found: %d", len(findings))
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("no leaks found")
|
log.Info().Msg("no leaks found")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msgf("scan completed in %s", time.Since(start))
|
// write report if desired
|
||||||
|
|
||||||
reportPath, _ := cmd.Flags().GetString("report-path")
|
reportPath, _ := cmd.Flags().GetString("report-path")
|
||||||
ext, _ := cmd.Flags().GetString("report-format")
|
ext, _ := cmd.Flags().GetString("report-format")
|
||||||
if reportPath != "" {
|
if reportPath != "" {
|
||||||
report.Write(findings, cfg, ext, reportPath)
|
if err = report.Write(findings, cfg, ext, reportPath); err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(findings) != 0 {
|
if len(findings) != 0 {
|
||||||
|
|||||||
+47
-14
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
"github.com/zricethezav/gitleaks/v8/detect"
|
"github.com/zricethezav/gitleaks/v8/detect"
|
||||||
"github.com/zricethezav/gitleaks/v8/git"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
"github.com/zricethezav/gitleaks/v8/report"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,41 +29,75 @@ func runProtect(cmd *cobra.Command, args []string) {
|
|||||||
initConfig()
|
initConfig()
|
||||||
var vc config.ViperConfig
|
var vc config.ViperConfig
|
||||||
|
|
||||||
viper.Unmarshal(&vc)
|
if err := viper.Unmarshal(&vc); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("Failed to load config")
|
||||||
|
}
|
||||||
cfg, err := vc.Translate()
|
cfg, err := vc.Translate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Failed to load config")
|
log.Fatal().Err(err).Msg("Failed to load config")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Path, _ = cmd.Flags().GetString("config")
|
cfg.Path, _ = cmd.Flags().GetString("config")
|
||||||
source, _ := cmd.Flags().GetString("source")
|
|
||||||
verbose, _ := cmd.Flags().GetBool("verbose")
|
|
||||||
redact, _ := cmd.Flags().GetBool("redact")
|
|
||||||
exitCode, _ := cmd.Flags().GetInt("exit-code")
|
exitCode, _ := cmd.Flags().GetInt("exit-code")
|
||||||
staged, _ := cmd.Flags().GetBool("staged")
|
staged, _ := cmd.Flags().GetBool("staged")
|
||||||
if cfg.Path == "" {
|
|
||||||
cfg.Path = filepath.Join(source, ".gitleaks.toml")
|
|
||||||
}
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
files, err := git.GitDiff(source, staged)
|
// Setup detector
|
||||||
|
detector := detect.NewDetector(cfg)
|
||||||
|
detector.Config.Path, err = cmd.Flags().GetString("config")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Failed to get git log")
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
source, err := cmd.Flags().GetString("source")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
// if config path is not set, then use the {source}/.gitleaks.toml path.
|
||||||
|
// note that there may not be a `{source}/.gitleaks.toml` file, this is ok.
|
||||||
|
if detector.Config.Path == "" {
|
||||||
|
detector.Config.Path = filepath.Join(source, ".gitleaks.toml")
|
||||||
|
}
|
||||||
|
// set verbose flag
|
||||||
|
if detector.Verbose, err = cmd.Flags().GetBool("verbose"); err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
// set redact flag
|
||||||
|
if detector.Redact, err = cmd.Flags().GetBool("redact"); err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
findings := detect.FromGit(files, cfg, detect.Options{Verbose: verbose, Redact: redact})
|
// get log options for git scan
|
||||||
|
logOpts, err := cmd.Flags().GetString("log-opts")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// start git scan
|
||||||
|
var findings []report.Finding
|
||||||
|
if staged {
|
||||||
|
findings, err = detector.DetectGit(source, logOpts, detect.ProtectStagedType)
|
||||||
|
} else {
|
||||||
|
findings, err = detector.DetectGit(source, logOpts, detect.ProtectType)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
// don't exit on error, just log it
|
||||||
|
log.Error().Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// log info about the scan
|
||||||
|
log.Info().Msgf("scan completed in %s", time.Since(start))
|
||||||
if len(findings) != 0 {
|
if len(findings) != 0 {
|
||||||
log.Warn().Msgf("leaks found: %d", len(findings))
|
log.Warn().Msgf("leaks found: %d", len(findings))
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("no leaks found")
|
log.Info().Msg("no leaks found")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msgf("scan duration: %s", time.Since(start))
|
|
||||||
|
|
||||||
reportPath, _ := cmd.Flags().GetString("report-path")
|
reportPath, _ := cmd.Flags().GetString("report-path")
|
||||||
ext, _ := cmd.Flags().GetString("report-format")
|
ext, _ := cmd.Flags().GetString("report-format")
|
||||||
if reportPath != "" {
|
if reportPath != "" {
|
||||||
report.Write(findings, cfg, ext, reportPath)
|
if err = report.Write(findings, cfg, ext, reportPath); err != nil {
|
||||||
|
log.Fatal().Err(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(findings) != 0 {
|
if len(findings) != 0 {
|
||||||
os.Exit(exitCode)
|
os.Exit(exitCode)
|
||||||
|
|||||||
+11
-4
@@ -45,7 +45,10 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (debug, info, warn, error, fatal)")
|
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (debug, info, warn, error, fatal)")
|
||||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
||||||
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
||||||
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
|
err := viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Msgf("err binding config %s", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initLog() {
|
func initLog() {
|
||||||
@@ -71,7 +74,7 @@ func initLog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
fmt.Fprintf(os.Stderr, banner)
|
fmt.Fprint(os.Stderr, banner)
|
||||||
cfgPath, err := rootCmd.Flags().GetString("config")
|
cfgPath, err := rootCmd.Flags().GetString("config")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Msg(err.Error())
|
log.Fatal().Msg(err.Error())
|
||||||
@@ -97,14 +100,18 @@ func initConfig() {
|
|||||||
log.Debug().Msgf("Unable to load gitleaks config from %s since --source=%s is a file, using default config",
|
log.Debug().Msgf("Unable to load gitleaks config from %s since --source=%s is a file, using default config",
|
||||||
filepath.Join(source, ".gitleaks.toml"), source)
|
filepath.Join(source, ".gitleaks.toml"), source)
|
||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
viper.ReadConfig(strings.NewReader(config.DefaultConfig))
|
if err = viper.ReadConfig(strings.NewReader(config.DefaultConfig)); err != nil {
|
||||||
|
log.Fatal().Msgf("err reading toml %s", err.Error())
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(filepath.Join(source, ".gitleaks.toml")); os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Join(source, ".gitleaks.toml")); os.IsNotExist(err) {
|
||||||
log.Debug().Msgf("No gitleaks config found in path %s, using default gitleaks config", filepath.Join(source, ".gitleaks.toml"))
|
log.Debug().Msgf("No gitleaks config found in path %s, using default gitleaks config", filepath.Join(source, ".gitleaks.toml"))
|
||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
viper.ReadConfig(strings.NewReader(config.DefaultConfig))
|
if err = viper.ReadConfig(strings.NewReader(config.DefaultConfig)); err != nil {
|
||||||
|
log.Fatal().Msgf("err reading default config toml %s", err.Error())
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
log.Debug().Msgf("Using existing gitleaks config %s from `(--source)/.gitleaks.toml`", filepath.Join(source, ".gitleaks.toml"))
|
log.Debug().Msgf("Using existing gitleaks config %s from `(--source)/.gitleaks.toml`", filepath.Join(source, ".gitleaks.toml"))
|
||||||
|
|||||||
+17
-11
@@ -2,13 +2,23 @@ package config
|
|||||||
|
|
||||||
import "regexp"
|
import "regexp"
|
||||||
|
|
||||||
|
// Allowlist allows a rule to be ignored for specific
|
||||||
|
// regexes, paths, and/or commits
|
||||||
type Allowlist struct {
|
type Allowlist struct {
|
||||||
|
// Short human readable description of the allowlist.
|
||||||
Description string
|
Description string
|
||||||
Regexes []*regexp.Regexp
|
|
||||||
Paths []*regexp.Regexp
|
// Regexes is slice of content regular expressions that are allowed to be ignored.
|
||||||
Commits []string
|
Regexes []*regexp.Regexp
|
||||||
|
|
||||||
|
// Paths is a slice of path regular expressions that are allowed to be ignored.
|
||||||
|
Paths []*regexp.Regexp
|
||||||
|
|
||||||
|
// Commits is a slice of commit SHAs that are allowed to be ignored.
|
||||||
|
Commits []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommitAllowed returns true if the commit is allowed to be ignored.
|
||||||
func (a *Allowlist) CommitAllowed(c string) bool {
|
func (a *Allowlist) CommitAllowed(c string) bool {
|
||||||
if c == "" {
|
if c == "" {
|
||||||
return false
|
return false
|
||||||
@@ -21,16 +31,12 @@ func (a *Allowlist) CommitAllowed(c string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PathAllowed returns true if the path is allowed to be ignored.
|
||||||
func (a *Allowlist) PathAllowed(path string) bool {
|
func (a *Allowlist) PathAllowed(path string) bool {
|
||||||
if anyRegexMatch(path, a.Paths) {
|
return anyRegexMatch(path, a.Paths)
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegexAllowed returns true if the regex is allowed to be ignored.
|
||||||
func (a *Allowlist) RegexAllowed(s string) bool {
|
func (a *Allowlist) RegexAllowed(s string) bool {
|
||||||
if anyRegexMatch(s, a.Regexes) {
|
return anyRegexMatch(s, a.Regexes)
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
+4
-51
@@ -103,7 +103,10 @@ func TestTranslate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var vc ViperConfig
|
var vc ViperConfig
|
||||||
viper.Unmarshal(&vc)
|
err = viper.Unmarshal(&vc)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
cfg, err := vc.Translate()
|
cfg, err := vc.Translate()
|
||||||
if tt.wantError != nil {
|
if tt.wantError != nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -115,53 +118,3 @@ func TestTranslate(t *testing.T) {
|
|||||||
assert.Equal(t, cfg.Rules, tt.cfg.Rules)
|
assert.Equal(t, cfg.Rules, tt.cfg.Rules)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIncludeEntropy(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
rule Rule
|
|
||||||
secret string
|
|
||||||
entropy float32
|
|
||||||
include bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
rule: Rule{
|
|
||||||
RuleID: "generic-api-key",
|
|
||||||
SecretGroup: 4,
|
|
||||||
Entropy: 3.5,
|
|
||||||
Regex: regexp.MustCompile(`(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]`),
|
|
||||||
},
|
|
||||||
secret: `e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5`,
|
|
||||||
entropy: 3.7906235872459746,
|
|
||||||
include: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rule: Rule{
|
|
||||||
RuleID: "generic-api-key",
|
|
||||||
SecretGroup: 4,
|
|
||||||
Entropy: 4,
|
|
||||||
Regex: regexp.MustCompile(`(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]`),
|
|
||||||
},
|
|
||||||
secret: `e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5`,
|
|
||||||
entropy: 3.7906235872459746,
|
|
||||||
include: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rule: Rule{
|
|
||||||
RuleID: "generic-api-key",
|
|
||||||
SecretGroup: 4,
|
|
||||||
Entropy: 3.0,
|
|
||||||
Regex: regexp.MustCompile(`(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]`),
|
|
||||||
},
|
|
||||||
secret: `ssh-keyboard-interactive`,
|
|
||||||
entropy: 0,
|
|
||||||
include: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
include, entropy := tt.rule.IncludeEntropy(tt.secret)
|
|
||||||
assert.Equal(t, true, tt.rule.EntropySet())
|
|
||||||
assert.Equal(t, tt.entropy, float32(entropy))
|
|
||||||
assert.Equal(t, tt.include, include)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+34
-35
@@ -2,7 +2,7 @@ title = "gitleaks config"
|
|||||||
|
|
||||||
# Gitleaks rules are defined by regular expressions and entropy ranges.
|
# Gitleaks rules are defined by regular expressions and entropy ranges.
|
||||||
# Some secrets have unique signatures which make detecting those secrets easy.
|
# Some secrets have unique signatures which make detecting those secrets easy.
|
||||||
# Examples of those secrets would be Gitlab Personal Access Tokens, AWS keys, and Github Access Tokens.
|
# Examples of those secrets would be GitLab Personal Access Tokens, AWS keys, and GitHub Access Tokens.
|
||||||
# All these examples have defined prefixes like `glpat`, `AKIA`, `ghp_`, etc.
|
# All these examples have defined prefixes like `glpat`, `AKIA`, `ghp_`, etc.
|
||||||
#
|
#
|
||||||
# Other secrets might just be a hash which means we need to write more complex rules to verify
|
# Other secrets might just be a hash which means we need to write more complex rules to verify
|
||||||
@@ -32,7 +32,7 @@ title = "gitleaks config"
|
|||||||
[[rules]]
|
[[rules]]
|
||||||
id = "gitlab-pat"
|
id = "gitlab-pat"
|
||||||
description = "GitLab Personal Access Token"
|
description = "GitLab Personal Access Token"
|
||||||
regex = '''glpat-[0-9a-zA-Z\-]{20}'''
|
regex = '''glpat-[0-9a-zA-Z\-\_]{20}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "aws-access-token"
|
id = "aws-access-token"
|
||||||
@@ -62,12 +62,12 @@ regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
|||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "github-pat"
|
id = "github-pat"
|
||||||
description = "Github Personal Access Token"
|
description = "GitHub Personal Access Token"
|
||||||
regex = '''ghp_[0-9a-zA-Z]{36}'''
|
regex = '''ghp_[0-9a-zA-Z]{36}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "github-oauth"
|
id = "github-oauth"
|
||||||
description = "Github OAuth Access Token"
|
description = "GitHub OAuth Access Token"
|
||||||
regex = '''gho_[0-9a-zA-Z]{36}'''
|
regex = '''gho_[0-9a-zA-Z]{36}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
@@ -83,12 +83,12 @@ regex = '''-----BEGIN EC PRIVATE KEY-----'''
|
|||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "github-app-token"
|
id = "github-app-token"
|
||||||
description = "Github App Token"
|
description = "GitHub App Token"
|
||||||
regex = '''(ghu|ghs)_[0-9a-zA-Z]{36}'''
|
regex = '''(ghu|ghs)_[0-9a-zA-Z]{36}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "github-refresh-token"
|
id = "github-refresh-token"
|
||||||
description = "Github Refresh Token"
|
description = "GitHub Refresh Token"
|
||||||
regex = '''ghr_[0-9a-zA-Z]{76}'''
|
regex = '''ghr_[0-9a-zA-Z]{76}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
@@ -124,7 +124,7 @@ regex = '''(?i)(sk|pk)_(test|live)_[0-9a-z]{10,32}'''
|
|||||||
[[rules]]
|
[[rules]]
|
||||||
id = "pypi-upload-token"
|
id = "pypi-upload-token"
|
||||||
description = "PyPI upload token"
|
description = "PyPI upload token"
|
||||||
regex = '''pypi-AgEIcHlwaS5vcmc[A-Za-z0-9-_]{50,1000}'''
|
regex = '''pypi-AgEIcHlwaS5vcmc[A-Za-z0-9\-_]{50,1000}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "gcp-service-account"
|
id = "gcp-service-account"
|
||||||
@@ -233,12 +233,6 @@ description = "Contentful delivery API token"
|
|||||||
regex = '''(?i)(contentful[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9\-=_]{43})['\"]'''
|
regex = '''(?i)(contentful[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9\-=_]{43})['\"]'''
|
||||||
secretGroup = 3
|
secretGroup = 3
|
||||||
|
|
||||||
[[rules]]
|
|
||||||
id = "contentful-preview-api-token"
|
|
||||||
description = "Contentful preview API token"
|
|
||||||
regex = '''(?i)(contentful[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9\-=_]{43})['\"]'''
|
|
||||||
secretGroup = 3
|
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "databricks-api-token"
|
id = "databricks-api-token"
|
||||||
description = "Databricks API token"
|
description = "Databricks API token"
|
||||||
@@ -326,43 +320,43 @@ regex = '''(?i)(finicity[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([
|
|||||||
secretGroup = 3
|
secretGroup = 3
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "flutterweave-public-key"
|
id = "flutterwave-public-key"
|
||||||
description = "Flutterweave public key"
|
description = "Flutterwave public key"
|
||||||
regex = '''FLWPUBK_TEST-(?i)[a-h0-9]{32}-X'''
|
regex = '''FLWPUBK_TEST-(?i)[a-h0-9]{32}-X'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "flutterweave-secret-key"
|
id = "flutterwave-secret-key"
|
||||||
description = "Flutterweave secret key"
|
description = "Flutterwave secret key"
|
||||||
regex = '''FLWSECK_TEST-(?i)[a-h0-9]{32}-X'''
|
regex = '''FLWSECK_TEST-(?i)[a-h0-9]{32}-X'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "flutterweave-enc-key"
|
id = "flutterwave-enc-key"
|
||||||
description = "Flutterweave encrypted key"
|
description = "Flutterwave encrypted key"
|
||||||
regex = '''FLWSECK_TEST[a-h0-9]{12}'''
|
regex = '''FLWSECK_TEST[a-h0-9]{12}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "frameio-api-token"
|
id = "frameio-api-token"
|
||||||
description = "Frame.io API token"
|
description = "Frame.io API token"
|
||||||
regex = '''fio-u-(?i)[a-z0-9-_=]{64}'''
|
regex = '''fio-u-(?i)[a-z0-9\-_=]{64}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "gocardless-api-token"
|
id = "gocardless-api-token"
|
||||||
description = "GoCardless API token"
|
description = "GoCardless API token"
|
||||||
regex = '''['\"]live_(?i)[a-z0-9-_=]{40}['\"]'''
|
regex = '''['\"]live_(?i)[a-z0-9\-_=]{40}['\"]'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "grafana-api-token"
|
id = "grafana-api-token"
|
||||||
description = "Grafana API token"
|
description = "Grafana API token"
|
||||||
regex = '''['\"]eyJrIjoi(?i)[a-z0-9-_=]{72,92}['\"]'''
|
regex = '''['\"]eyJrIjoi(?i)[a-z0-9\-_=]{72,92}['\"]'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "hashicorp-tf-api-token"
|
id = "hashicorp-tf-api-token"
|
||||||
description = "Hashicorp Terraform user/org API token"
|
description = "HashiCorp Terraform user/org API token"
|
||||||
regex = '''['\"](?i)[a-z0-9]{14}\.atlasv1\.[a-z0-9-_=]{60,70}['\"]'''
|
regex = '''['\"](?i)[a-z0-9]{14}\.atlasv1\.[a-z0-9\-_=]{60,70}['\"]'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "hubspot-api-token"
|
id = "hubspot-api-token"
|
||||||
description = "Hubspot API token"
|
description = "HubSpot API token"
|
||||||
regex = '''(?i)(hubspot[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-h0-9]{8}-[a-h0-9]{4}-[a-h0-9]{4}-[a-h0-9]{4}-[a-h0-9]{12})['\"]'''
|
regex = '''(?i)(hubspot[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-h0-9]{8}-[a-h0-9]{4}-[a-h0-9]{4}-[a-h0-9]{4}-[a-h0-9]{12})['\"]'''
|
||||||
secretGroup = 3
|
secretGroup = 3
|
||||||
|
|
||||||
@@ -470,12 +464,12 @@ regex = '''['\"](npm_(?i)[a-z0-9]{36})['\"]'''
|
|||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "planetscale-password"
|
id = "planetscale-password"
|
||||||
description = "Planetscale password"
|
description = "PlanetScale password"
|
||||||
regex = '''pscale_pw_(?i)[a-z0-9\-_\.]{43}'''
|
regex = '''pscale_pw_(?i)[a-z0-9\-_\.]{43}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "planetscale-api-token"
|
id = "planetscale-api-token"
|
||||||
description = "Planetscale API token"
|
description = "PlanetScale API token"
|
||||||
regex = '''pscale_tkn_(?i)[a-z0-9\-_\.]{43}'''
|
regex = '''pscale_tkn_(?i)[a-z0-9\-_\.]{43}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
@@ -495,7 +489,7 @@ regex = '''rubygems_[a-f0-9]{48}'''
|
|||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "sendgrid-api-token"
|
id = "sendgrid-api-token"
|
||||||
description = "Sendgrid API token"
|
description = "SendGrid API token"
|
||||||
regex = '''SG\.(?i)[a-z0-9_\-\.]{66}'''
|
regex = '''SG\.(?i)[a-z0-9_\-\.]{66}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
@@ -509,14 +503,14 @@ description = "Shippo API token"
|
|||||||
regex = '''shippo_(live|test)_[a-f0-9]{40}'''
|
regex = '''shippo_(live|test)_[a-f0-9]{40}'''
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "linedin-client-secret"
|
id = "linkedin-client-secret"
|
||||||
description = "Linkedin Client secret"
|
description = "LinkedIn Client secret"
|
||||||
regex = '''(?i)(linkedin[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z]{16})['\"]'''
|
regex = '''(?i)(linkedin[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z]{16})['\"]'''
|
||||||
secretGroup = 3
|
secretGroup = 3
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "linedin-client-id"
|
id = "linkedin-client-id"
|
||||||
description = "Linkedin Client ID"
|
description = "LinkedIn Client ID"
|
||||||
regex = '''(?i)(linkedin[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9]{14})['\"]'''
|
regex = '''(?i)(linkedin[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9]{14})['\"]'''
|
||||||
secretGroup = 3
|
secretGroup = 3
|
||||||
|
|
||||||
@@ -535,15 +529,20 @@ secretGroup = 3
|
|||||||
[[rules]]
|
[[rules]]
|
||||||
id = "generic-api-key"
|
id = "generic-api-key"
|
||||||
description = "Generic API Key"
|
description = "Generic API Key"
|
||||||
regex = '''(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]'''
|
regex = '''(?i)((key|api[^Version]|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z\-_=]{8,64})['\"]'''
|
||||||
entropy = 3.7
|
entropy = 3.7
|
||||||
secretGroup = 4
|
secretGroup = 4
|
||||||
|
|
||||||
|
|
||||||
[allowlist]
|
[allowlist]
|
||||||
description = "global allow lists"
|
description = "global allow lists"
|
||||||
regexes = ['''219-09-9999''', '''078-05-1120''', '''(9[0-9]{2}|666)-\d{2}-\d{4}''']
|
regexes = [
|
||||||
|
'''219-09-9999''',
|
||||||
|
'''078-05-1120''',
|
||||||
|
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
|
||||||
|
]
|
||||||
paths = [
|
paths = [
|
||||||
'''gitleaks.toml''',
|
'''gitleaks.toml''',
|
||||||
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$'''
|
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
|
||||||
|
'''(go.mod|go.sum)$'''
|
||||||
]
|
]
|
||||||
+25
-32
@@ -2,44 +2,37 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Rules contain information that define details on how to detect secrets
|
||||||
type Rule struct {
|
type Rule struct {
|
||||||
|
// Description is the description of the rule.
|
||||||
Description string
|
Description string
|
||||||
RuleID string
|
|
||||||
Entropy float64
|
// RuleID is a unique identifier for this rule
|
||||||
|
RuleID string
|
||||||
|
|
||||||
|
// Entropy is a float representing the minimum shannon
|
||||||
|
// entropy a regex group must have to be considered a secret.
|
||||||
|
Entropy float64
|
||||||
|
|
||||||
|
// SecretGroup is an int used to extract secret from regex
|
||||||
|
// match and used as the group that will have its entropy
|
||||||
|
// checked if `entropy` is set.
|
||||||
SecretGroup int
|
SecretGroup int
|
||||||
Regex *regexp.Regexp
|
|
||||||
Path *regexp.Regexp
|
|
||||||
Tags []string
|
|
||||||
Allowlist Allowlist
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rule) IncludeEntropy(secret string) (bool, float64) {
|
// Regex is a golang regular expression used to detect secrets.
|
||||||
// NOTE: this is a goofy hack to get around the fact there golang's regex engine
|
Regex *regexp.Regexp
|
||||||
// does not support positive lookaheads. Ideally we would want to add a
|
|
||||||
// restriction on generic rules regex that requires the secret match group
|
|
||||||
// contains both numbers and alphabetical characters. What this bit of code does is
|
|
||||||
// check if the ruleid is prepended with "generic" and enforces the
|
|
||||||
// secret contains both digits and alphabetical characters.
|
|
||||||
if strings.HasPrefix(r.RuleID, "generic") {
|
|
||||||
if !containsDigit(secret) {
|
|
||||||
return false, 0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// group = 0 will check the entropy of the whole regex match
|
|
||||||
e := shannonEntropy(secret)
|
|
||||||
if e > r.Entropy {
|
|
||||||
return true, e
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, e
|
// Path is a golang regular expression used to
|
||||||
}
|
// filter secrets by path
|
||||||
|
Path *regexp.Regexp
|
||||||
|
|
||||||
func (r *Rule) EntropySet() bool {
|
// Tags is an array of strings used for metadata
|
||||||
if r.Entropy == 0.0 {
|
// and reporting purposes.
|
||||||
return false
|
Tags []string
|
||||||
}
|
|
||||||
return true
|
// Allowlist allows a rule to be ignored for specific
|
||||||
|
// regexes, paths, and/or commits
|
||||||
|
Allowlist Allowlist
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,38 +22,3 @@ func regexMatched(f string, re *regexp.Regexp) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func containsDigit(s string) bool {
|
|
||||||
for _, c := range s {
|
|
||||||
switch c {
|
|
||||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// shannonEntropy calculates the entropy of data using the formula defined here:
|
|
||||||
// https://en.wiktionary.org/wiki/Shannon_entropy
|
|
||||||
// Another way to think about what this is doing is calculating the number of bits
|
|
||||||
// needed to on average encode the data. So, the higher the entropy, the more random the data, the
|
|
||||||
// more bits needed to encode that data.
|
|
||||||
func shannonEntropy(data string) (entropy float64) {
|
|
||||||
if data == "" {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
charCounts := make(map[rune]int)
|
|
||||||
for _, char := range data {
|
|
||||||
charCounts[char]++
|
|
||||||
}
|
|
||||||
|
|
||||||
invLength := 1.0 / float64(len(data))
|
|
||||||
for _, count := range charCounts {
|
|
||||||
freq := float64(count) * invLength
|
|
||||||
entropy -= freq * math.Log2(freq)
|
|
||||||
}
|
|
||||||
|
|
||||||
return entropy
|
|
||||||
}
|
|
||||||
+354
-114
@@ -1,149 +1,389 @@
|
|||||||
package detect
|
package detect
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
|
"github.com/zricethezav/gitleaks/v8/detect/git"
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
"github.com/zricethezav/gitleaks/v8/report"
|
||||||
|
|
||||||
|
"github.com/fatih/semgroup"
|
||||||
|
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||||
|
"github.com/h2non/filetype"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
// Type used to differentiate between git scan types:
|
||||||
|
// $ gitleaks detect
|
||||||
|
// $ gitleaks protect
|
||||||
|
// $ gitleaks protect staged
|
||||||
|
type GitScanType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
DetectType GitScanType = iota
|
||||||
|
ProtectType
|
||||||
|
ProtectStagedType
|
||||||
|
|
||||||
|
gitleaksAllowSignature = "gitleaks:allow"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Detector is the main detector struct
|
||||||
|
type Detector struct {
|
||||||
|
// Config is the configuration for the detector
|
||||||
|
Config config.Config
|
||||||
|
|
||||||
|
// Redact is a flag to redact findings. This is exported
|
||||||
|
// so users using gitleaks as a library can set this flag
|
||||||
|
// without calling `detector.Start(cmd *cobra.Command)`
|
||||||
|
Redact bool
|
||||||
|
|
||||||
|
// verbose is a flag to print findings
|
||||||
Verbose bool
|
Verbose bool
|
||||||
Redact bool
|
|
||||||
|
// commitMap is used to keep track of commits that have been scanned.
|
||||||
|
// This is only used for logging purposes and git scans.
|
||||||
|
commitMap map[string]bool
|
||||||
|
|
||||||
|
// findingMutex is to prevent concurrent access to the
|
||||||
|
// findings slice when adding findings.
|
||||||
|
findingMutex *sync.Mutex
|
||||||
|
|
||||||
|
// findings is a slice of report.Findings. This is the result
|
||||||
|
// of the detector's scan which can then be used to generate a
|
||||||
|
// report.
|
||||||
|
findings []report.Finding
|
||||||
}
|
}
|
||||||
|
|
||||||
func DetectFindings(cfg config.Config, b []byte, filePath string, commit string) []report.Finding {
|
// Fragment contains the data to be scanned
|
||||||
var findings []report.Finding
|
type Fragment struct {
|
||||||
linePairs := regexp.MustCompile("\n").FindAllIndex(b, -1)
|
// Raw is the raw content of the fragment
|
||||||
|
Raw string
|
||||||
|
|
||||||
// check if we should skip file based on the global allowlist or if the file is the same as the gitleaks config
|
// FilePath is the path to the file if applicable
|
||||||
if cfg.Allowlist.PathAllowed(filePath) || filePath == cfg.Path {
|
FilePath string
|
||||||
|
|
||||||
|
// CommitSHA is the SHA of the commit if applicable
|
||||||
|
CommitSHA string
|
||||||
|
|
||||||
|
// newlineIndices is a list of indices of newlines in the raw content.
|
||||||
|
// This is used to calculate the line location of a finding
|
||||||
|
newlineIndices [][]int
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDetector creates a new detector with the given config
|
||||||
|
func NewDetector(cfg config.Config) *Detector {
|
||||||
|
return &Detector{
|
||||||
|
commitMap: make(map[string]bool),
|
||||||
|
findingMutex: &sync.Mutex{},
|
||||||
|
findings: make([]report.Finding, 0),
|
||||||
|
Config: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDetectorDefaultConfig creates a new detector with the default config
|
||||||
|
func NewDetectorDefaultConfig() (*Detector, error) {
|
||||||
|
viper.SetConfigType("toml")
|
||||||
|
err := viper.ReadConfig(strings.NewReader(config.DefaultConfig))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var vc config.ViperConfig
|
||||||
|
err = viper.Unmarshal(&vc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cfg, err := vc.Translate()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewDetector(cfg), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DetectBytes scans the given bytes and returns a list of findings
|
||||||
|
func (d *Detector) DetectBytes(content []byte) []report.Finding {
|
||||||
|
return d.DetectString(string(content))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DetectString scans the given string and returns a list of findings
|
||||||
|
func (d *Detector) DetectString(content string) []report.Finding {
|
||||||
|
return d.Detect(Fragment{
|
||||||
|
Raw: content,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// detectRule scans the given fragment for the given rule and returns a list of findings
|
||||||
|
func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Finding {
|
||||||
|
var findings []report.Finding
|
||||||
|
|
||||||
|
// check if filepath or commit is allowed for this rule
|
||||||
|
if rule.Allowlist.CommitAllowed(fragment.CommitSHA) ||
|
||||||
|
rule.Allowlist.PathAllowed(fragment.FilePath) {
|
||||||
return findings
|
return findings
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range cfg.Rules {
|
if rule.Path != nil && rule.Regex == nil {
|
||||||
pathSkip := false
|
// Path _only_ rule
|
||||||
if r.Allowlist.CommitAllowed(commit) {
|
if rule.Path.Match([]byte(fragment.FilePath)) {
|
||||||
continue
|
finding := report.Finding{
|
||||||
}
|
Description: rule.Description,
|
||||||
if r.Allowlist.PathAllowed(filePath) {
|
File: fragment.FilePath,
|
||||||
continue
|
RuleID: rule.RuleID,
|
||||||
}
|
Match: fmt.Sprintf("file detected: %s", fragment.FilePath),
|
||||||
|
Tags: rule.Tags,
|
||||||
// Check if path should be considered
|
|
||||||
if r.Path != nil {
|
|
||||||
if r.Path.Match([]byte(filePath)) {
|
|
||||||
if r.Regex == nil {
|
|
||||||
// This is a path only rule
|
|
||||||
f := report.Finding{
|
|
||||||
Description: r.Description,
|
|
||||||
File: filePath,
|
|
||||||
RuleID: r.RuleID,
|
|
||||||
Match: fmt.Sprintf("file detected: %s", filePath),
|
|
||||||
Tags: r.Tags,
|
|
||||||
}
|
|
||||||
findings = append(findings, f)
|
|
||||||
pathSkip = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pathSkip = true
|
|
||||||
}
|
}
|
||||||
|
return append(findings, finding)
|
||||||
}
|
}
|
||||||
if pathSkip {
|
} else if rule.Path != nil {
|
||||||
|
// if path is set _and_ a regex is set, then we need to check both
|
||||||
|
// so if the path does not match, then we should return early and not
|
||||||
|
// consider the regex
|
||||||
|
if !rule.Path.Match([]byte(fragment.FilePath)) {
|
||||||
|
return findings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matchIndices := rule.Regex.FindAllStringIndex(fragment.Raw, -1)
|
||||||
|
for _, matchIndex := range matchIndices {
|
||||||
|
// extract secret from match
|
||||||
|
secret := strings.Trim(fragment.Raw[matchIndex[0]:matchIndex[1]], "\n")
|
||||||
|
|
||||||
|
// determine location of match. Note that the location
|
||||||
|
// in the finding will be the line/column numbers of the _match_
|
||||||
|
// not the _secret_, which will be different if the secretGroup
|
||||||
|
// value is set for this rule
|
||||||
|
loc := location(fragment, matchIndex)
|
||||||
|
|
||||||
|
finding := report.Finding{
|
||||||
|
Description: rule.Description,
|
||||||
|
File: fragment.FilePath,
|
||||||
|
RuleID: rule.RuleID,
|
||||||
|
StartLine: loc.startLine,
|
||||||
|
EndLine: loc.endLine,
|
||||||
|
StartColumn: loc.startColumn,
|
||||||
|
EndColumn: loc.endColumn,
|
||||||
|
Secret: secret,
|
||||||
|
Match: secret,
|
||||||
|
Tags: rule.Tags,
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(fragment.Raw[loc.startLineIndex:loc.endLineIndex],
|
||||||
|
gitleaksAllowSignature) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
matchIndices := r.Regex.FindAllIndex(b, -1)
|
// extract secret from secret group if set
|
||||||
for _, m := range matchIndices {
|
if rule.SecretGroup != 0 {
|
||||||
location := getLocation(linePairs, m[0], m[1])
|
groups := rule.Regex.FindStringSubmatch(secret)
|
||||||
secret := strings.Trim(string(b[m[0]:m[1]]), "\n")
|
if len(groups) <= rule.SecretGroup || len(groups) == 0 {
|
||||||
f := report.Finding{
|
// Config validation should prevent this
|
||||||
Description: r.Description,
|
|
||||||
File: filePath,
|
|
||||||
RuleID: r.RuleID,
|
|
||||||
StartLine: location.startLine,
|
|
||||||
EndLine: location.endLine,
|
|
||||||
StartColumn: location.startColumn,
|
|
||||||
EndColumn: location.endColumn,
|
|
||||||
Secret: secret,
|
|
||||||
Match: secret,
|
|
||||||
Tags: r.Tags,
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Allowlist.RegexAllowed(f.Secret) || cfg.Allowlist.RegexAllowed(f.Secret) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
secret = groups[rule.SecretGroup]
|
||||||
// extract secret from secret group if set
|
finding.Secret = secret
|
||||||
if r.SecretGroup != 0 {
|
|
||||||
groups := r.Regex.FindStringSubmatch(secret)
|
|
||||||
if len(groups)-1 > r.SecretGroup || len(groups) == 0 {
|
|
||||||
// Config validation should prevent this
|
|
||||||
break
|
|
||||||
}
|
|
||||||
secret = groups[r.SecretGroup]
|
|
||||||
f.Secret = secret
|
|
||||||
}
|
|
||||||
|
|
||||||
// extract secret from secret group if set
|
|
||||||
if r.EntropySet() {
|
|
||||||
include, entropy := r.IncludeEntropy(secret)
|
|
||||||
if include {
|
|
||||||
f.Entropy = float32(entropy)
|
|
||||||
findings = append(findings, f)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
findings = append(findings, f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return dedupe(findings)
|
// check if the secret is in the allowlist
|
||||||
}
|
if rule.Allowlist.RegexAllowed(finding.Secret) ||
|
||||||
|
d.Config.Allowlist.RegexAllowed(finding.Secret) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
func limit(s string) string {
|
// check entropy
|
||||||
if len(s) > 500 {
|
entropy := shannonEntropy(finding.Secret)
|
||||||
return s[:500] + "..."
|
finding.Entropy = float32(entropy)
|
||||||
}
|
if rule.Entropy != 0.0 {
|
||||||
return s
|
if entropy <= rule.Entropy {
|
||||||
}
|
// entropy is too low, skip this finding
|
||||||
|
continue
|
||||||
func printFinding(f report.Finding) {
|
}
|
||||||
var b []byte
|
// NOTE: this is a goofy hack to get around the fact there golang's regex engine
|
||||||
b, _ = json.MarshalIndent(f, "", " ")
|
// does not support positive lookaheads. Ideally we would want to add a
|
||||||
fmt.Println(string(b))
|
// restriction on generic rules regex that requires the secret match group
|
||||||
}
|
// contains both numbers and alphabetical characters, not just alphabetical characters.
|
||||||
|
// What this bit of code does is check if the ruleid is prepended with "generic" and enforces the
|
||||||
func dedupe(findings []report.Finding) []report.Finding {
|
// secret contains both digits and alphabetical characters.
|
||||||
var retFindings []report.Finding
|
// TODO: this should be replaced with stop words
|
||||||
for _, f := range findings {
|
if strings.HasPrefix(rule.RuleID, "generic") {
|
||||||
include := true
|
if !containsDigit(secret) {
|
||||||
if strings.Contains(strings.ToLower(f.RuleID), "generic") {
|
continue
|
||||||
for _, fPrime := range findings {
|
|
||||||
if f.StartLine == fPrime.StartLine &&
|
|
||||||
f.EndLine == fPrime.EndLine &&
|
|
||||||
f.Commit == fPrime.Commit &&
|
|
||||||
f.RuleID != fPrime.RuleID &&
|
|
||||||
strings.Contains(fPrime.Secret, f.Secret) &&
|
|
||||||
!strings.Contains(strings.ToLower(fPrime.RuleID), "generic") {
|
|
||||||
|
|
||||||
genericMatch := strings.Replace(f.Match, f.Secret, "REDACTED", -1)
|
|
||||||
betterMatch := strings.Replace(fPrime.Match, fPrime.Secret, "REDACTED", -1)
|
|
||||||
log.Debug().Msgf("skipping %s finding (%s), %s rule takes precendence (%s)", f.RuleID, genericMatch, fPrime.RuleID, betterMatch)
|
|
||||||
include = false
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if include {
|
|
||||||
retFindings = append(retFindings, f)
|
findings = append(findings, finding)
|
||||||
|
}
|
||||||
|
return findings
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitScan accepts a *gitdiff.File channel which contents a git history generated from
|
||||||
|
// the output of `git log -p ...`. startGitScan will look at each file (patch) in the history
|
||||||
|
// and determine if the patch contains any findings.
|
||||||
|
func (d *Detector) DetectGit(source string, logOpts string, gitScanType GitScanType) ([]report.Finding, error) {
|
||||||
|
var (
|
||||||
|
gitdiffFiles <-chan *gitdiff.File
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
switch gitScanType {
|
||||||
|
case DetectType:
|
||||||
|
gitdiffFiles, err = git.GitLog(source, logOpts)
|
||||||
|
if err != nil {
|
||||||
|
return d.findings, err
|
||||||
|
}
|
||||||
|
case ProtectType:
|
||||||
|
gitdiffFiles, err = git.GitDiff(source, false)
|
||||||
|
if err != nil {
|
||||||
|
return d.findings, err
|
||||||
|
}
|
||||||
|
case ProtectStagedType:
|
||||||
|
gitdiffFiles, err = git.GitDiff(source, true)
|
||||||
|
if err != nil {
|
||||||
|
return d.findings, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retFindings
|
s := semgroup.NewGroup(context.Background(), 4)
|
||||||
|
|
||||||
|
for gitdiffFile := range gitdiffFiles {
|
||||||
|
gitdiffFile := gitdiffFile
|
||||||
|
|
||||||
|
// skip binary files
|
||||||
|
if gitdiffFile.IsBinary || gitdiffFile.IsDelete {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if commit is allowed
|
||||||
|
commitSHA := ""
|
||||||
|
if gitdiffFile.PatchHeader != nil {
|
||||||
|
commitSHA = gitdiffFile.PatchHeader.SHA
|
||||||
|
if d.Config.Allowlist.CommitAllowed(gitdiffFile.PatchHeader.SHA) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.addCommit(commitSHA)
|
||||||
|
|
||||||
|
s.Go(func() error {
|
||||||
|
for _, textFragment := range gitdiffFile.TextFragments {
|
||||||
|
if textFragment == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment := Fragment{
|
||||||
|
Raw: textFragment.Raw(gitdiff.OpAdd),
|
||||||
|
CommitSHA: commitSHA,
|
||||||
|
FilePath: gitdiffFile.NewName,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, finding := range d.Detect(fragment) {
|
||||||
|
d.addFinding(augmentGitFinding(finding, textFragment, gitdiffFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.Wait(); err != nil {
|
||||||
|
return d.findings, err
|
||||||
|
}
|
||||||
|
log.Debug().Msgf("%d commits scanned. Note: this number might be smaller than expected due to commits with no additions", len(d.commitMap))
|
||||||
|
return d.findings, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DetectFiles accepts a path to a source directory or file and begins a scan of the
|
||||||
|
// file or directory.
|
||||||
|
func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
|
||||||
|
s := semgroup.NewGroup(context.Background(), 4)
|
||||||
|
paths := make(chan string)
|
||||||
|
s.Go(func() error {
|
||||||
|
defer close(paths)
|
||||||
|
return filepath.Walk(source,
|
||||||
|
func(path string, fInfo os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if fInfo.Name() == ".git" {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
if fInfo.Mode().IsRegular() {
|
||||||
|
paths <- path
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
})
|
||||||
|
for pa := range paths {
|
||||||
|
p := pa
|
||||||
|
s.Go(func() error {
|
||||||
|
b, err := os.ReadFile(p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mimetype, err := filetype.Match(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if mimetype.MIME.Type == "application" {
|
||||||
|
return nil // skip binary files
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment := Fragment{
|
||||||
|
Raw: string(b),
|
||||||
|
FilePath: p,
|
||||||
|
}
|
||||||
|
for _, finding := range d.Detect(fragment) {
|
||||||
|
// need to add 1 since line counting starts at 1
|
||||||
|
finding.EndLine++
|
||||||
|
finding.StartLine++
|
||||||
|
d.addFinding(finding)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.Wait(); err != nil {
|
||||||
|
return d.findings, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.findings, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect scans the given fragment and returns a list of findings
|
||||||
|
func (d *Detector) Detect(fragment Fragment) []report.Finding {
|
||||||
|
var findings []report.Finding
|
||||||
|
|
||||||
|
// check if filepath is allowed
|
||||||
|
if d.Config.Allowlist.PathAllowed(fragment.FilePath) ||
|
||||||
|
fragment.FilePath == d.Config.Path {
|
||||||
|
return findings
|
||||||
|
}
|
||||||
|
|
||||||
|
// add newline indices for location calculation in detectRule
|
||||||
|
fragment.newlineIndices = regexp.MustCompile("\n").FindAllStringIndex(fragment.Raw, -1)
|
||||||
|
|
||||||
|
for _, rule := range d.Config.Rules {
|
||||||
|
findings = append(findings, d.detectRule(fragment, rule)...)
|
||||||
|
}
|
||||||
|
return filter(findings, d.Redact)
|
||||||
|
}
|
||||||
|
|
||||||
|
// addFinding synchronously adds a finding to the findings slice
|
||||||
|
func (d *Detector) addFinding(finding report.Finding) {
|
||||||
|
d.findingMutex.Lock()
|
||||||
|
d.findings = append(d.findings, finding)
|
||||||
|
if d.Verbose {
|
||||||
|
printFinding(finding)
|
||||||
|
}
|
||||||
|
d.findingMutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// addCommit synchronously adds a commit to the commit slice
|
||||||
|
func (d *Detector) addCommit(commit string) {
|
||||||
|
d.commitMap[commit] = true
|
||||||
}
|
}
|
||||||
+368
-41
@@ -2,6 +2,7 @@ package detect
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -12,20 +13,91 @@ import (
|
|||||||
"github.com/zricethezav/gitleaks/v8/report"
|
"github.com/zricethezav/gitleaks/v8/report"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDetectFindings(t *testing.T) {
|
const configPath = "../testdata/config/"
|
||||||
|
const repoBasePath = "../testdata/repos/"
|
||||||
|
|
||||||
|
func TestDetect(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
cfgName string
|
cfgName string
|
||||||
opts Options
|
fragment Fragment
|
||||||
filePath string
|
|
||||||
bytes []byte
|
|
||||||
commit string
|
|
||||||
expectedFindings []report.Finding
|
expectedFindings []report.Finding
|
||||||
wantError error
|
wantError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
cfgName: "simple",
|
cfgName: "simple",
|
||||||
bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `awsToken := \"AKIALALEMEL33243OKIA\ // gitleaks:allow"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
|
expectedFindings: []report.Finding{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cfgName: "simple",
|
||||||
|
fragment: Fragment{
|
||||||
|
Raw: `awsToken := \
|
||||||
|
|
||||||
|
\"AKIALALEMEL33243OKIA\ // gitleaks:allow"
|
||||||
|
|
||||||
|
|
||||||
|
`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
|
expectedFindings: []report.Finding{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cfgName: "simple",
|
||||||
|
fragment: Fragment{
|
||||||
|
Raw: `awsToken := \"AKIALALEMEL33243OKIA\"
|
||||||
|
|
||||||
|
// gitleaks:allow"
|
||||||
|
|
||||||
|
`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
|
expectedFindings: []report.Finding{
|
||||||
|
{
|
||||||
|
Description: "AWS Access Key",
|
||||||
|
Secret: "AKIALALEMEL33243OKIA",
|
||||||
|
Match: "AKIALALEMEL33243OKIA",
|
||||||
|
File: "tmp.go",
|
||||||
|
RuleID: "aws-access-key",
|
||||||
|
Tags: []string{"key", "AWS"},
|
||||||
|
StartLine: 0,
|
||||||
|
EndLine: 0,
|
||||||
|
StartColumn: 15,
|
||||||
|
EndColumn: 34,
|
||||||
|
Entropy: 3.1464393,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cfgName: "escaped_character_group",
|
||||||
|
fragment: Fragment{
|
||||||
|
Raw: `pypi-AgEIcHlwaS5vcmcAAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAAB`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
|
expectedFindings: []report.Finding{
|
||||||
|
{
|
||||||
|
Description: "PyPI upload token",
|
||||||
|
Secret: "pypi-AgEIcHlwaS5vcmcAAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAAB",
|
||||||
|
Match: "pypi-AgEIcHlwaS5vcmcAAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAAAAAAAAB",
|
||||||
|
File: "tmp.go",
|
||||||
|
RuleID: "pypi-upload-token",
|
||||||
|
Tags: []string{"key", "pypi"},
|
||||||
|
StartLine: 1,
|
||||||
|
EndLine: 1,
|
||||||
|
StartColumn: 1,
|
||||||
|
EndColumn: 86,
|
||||||
|
Entropy: 1.9606875,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cfgName: "simple",
|
||||||
|
fragment: Fragment{
|
||||||
|
Raw: `awsToken := \"AKIALALEMEL33243OLIA\"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{
|
expectedFindings: []report.Finding{
|
||||||
{
|
{
|
||||||
Description: "AWS Access Key",
|
Description: "AWS Access Key",
|
||||||
@@ -38,32 +110,41 @@ func TestDetectFindings(t *testing.T) {
|
|||||||
EndLine: 1,
|
EndLine: 1,
|
||||||
StartColumn: 15,
|
StartColumn: 15,
|
||||||
EndColumn: 34,
|
EndColumn: 34,
|
||||||
|
Entropy: 3.0841837,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "allow_aws_re",
|
cfgName: "allow_aws_re",
|
||||||
bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `awsToken := \"AKIALALEMEL33243OLIA\"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{},
|
expectedFindings: []report.Finding{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "allow_path",
|
cfgName: "allow_path",
|
||||||
bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `awsToken := \"AKIALALEMEL33243OLIA\"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{},
|
expectedFindings: []report.Finding{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "allow_commit",
|
cfgName: "allow_commit",
|
||||||
bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `awsToken := \"AKIALALEMEL33243OLIA\"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
CommitSHA: "allowthiscommit",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{},
|
expectedFindings: []report.Finding{},
|
||||||
commit: "allowthiscommit",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "entropy_group",
|
cfgName: "entropy_group",
|
||||||
bytes: []byte(`const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{
|
expectedFindings: []report.Finding{
|
||||||
{
|
{
|
||||||
Description: "Discord API key",
|
Description: "Discord API key",
|
||||||
@@ -81,15 +162,19 @@ func TestDetectFindings(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "generic_with_py_path",
|
cfgName: "generic_with_py_path",
|
||||||
bytes: []byte(`const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{},
|
expectedFindings: []report.Finding{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "generic_with_py_path",
|
cfgName: "generic_with_py_path",
|
||||||
bytes: []byte(`const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.py",
|
Raw: `const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||||
|
FilePath: "tmp.py",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{
|
expectedFindings: []report.Finding{
|
||||||
{
|
{
|
||||||
Description: "Generic API Key",
|
Description: "Generic API Key",
|
||||||
@@ -107,9 +192,11 @@ func TestDetectFindings(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "path_only",
|
cfgName: "path_only",
|
||||||
bytes: []byte(`const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.py",
|
Raw: `const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||||
|
FilePath: "tmp.py",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{
|
expectedFindings: []report.Finding{
|
||||||
{
|
{
|
||||||
Description: "Python Files",
|
Description: "Python Files",
|
||||||
@@ -121,22 +208,36 @@ func TestDetectFindings(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "bad_entropy_group",
|
cfgName: "bad_entropy_group",
|
||||||
bytes: []byte(`const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{},
|
expectedFindings: []report.Finding{},
|
||||||
wantError: fmt.Errorf("Discord API key invalid regex secret group 5, max regex secret group 3"),
|
wantError: fmt.Errorf("Discord API key invalid regex secret group 5, max regex secret group 3"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "simple",
|
cfgName: "simple",
|
||||||
bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`),
|
fragment: Fragment{
|
||||||
filePath: filepath.Join(configPath, "simple.toml"),
|
Raw: `awsToken := \"AKIALALEMEL33243OLIA\"`,
|
||||||
|
FilePath: filepath.Join(configPath, "simple.toml"),
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{},
|
expectedFindings: []report.Finding{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cfgName: "allow_global_aws_re",
|
cfgName: "allow_global_aws_re",
|
||||||
bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`),
|
fragment: Fragment{
|
||||||
filePath: "tmp.go",
|
Raw: `awsToken := \"AKIALALEMEL33243OLIA\"`,
|
||||||
|
FilePath: "tmp.go",
|
||||||
|
},
|
||||||
|
expectedFindings: []report.Finding{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cfgName: "generic_with_py_path",
|
||||||
|
fragment: Fragment{
|
||||||
|
Raw: `const Discord_Public_Key = "load2523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||||
|
FilePath: "tmp.py",
|
||||||
|
},
|
||||||
expectedFindings: []report.Finding{},
|
expectedFindings: []report.Finding{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -152,7 +253,10 @@ func TestDetectFindings(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var vc config.ViperConfig
|
var vc config.ViperConfig
|
||||||
viper.Unmarshal(&vc)
|
err = viper.Unmarshal(&vc)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
cfg, err := vc.Translate()
|
cfg, err := vc.Translate()
|
||||||
cfg.Path = filepath.Join(configPath, tt.cfgName+".toml")
|
cfg.Path = filepath.Join(configPath, tt.cfgName+".toml")
|
||||||
if tt.wantError != nil {
|
if tt.wantError != nil {
|
||||||
@@ -161,8 +265,231 @@ func TestDetectFindings(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Equal(t, tt.wantError, err)
|
assert.Equal(t, tt.wantError, err)
|
||||||
}
|
}
|
||||||
|
d := NewDetector(cfg)
|
||||||
|
|
||||||
findings := DetectFindings(cfg, tt.bytes, tt.filePath, tt.commit)
|
findings := d.Detect(tt.fragment)
|
||||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestFromGit tests the FromGit function
|
||||||
|
func TestFromGit(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
cfgName string
|
||||||
|
source string
|
||||||
|
logOpts string
|
||||||
|
expectedFindings []report.Finding
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
source: filepath.Join(repoBasePath, "small"),
|
||||||
|
cfgName: "simple",
|
||||||
|
expectedFindings: []report.Finding{
|
||||||
|
{
|
||||||
|
Description: "AWS Access Key",
|
||||||
|
StartLine: 20,
|
||||||
|
EndLine: 20,
|
||||||
|
StartColumn: 19,
|
||||||
|
EndColumn: 38,
|
||||||
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
|
Match: "AKIALALEMEL33243OLIA",
|
||||||
|
File: "main.go",
|
||||||
|
Date: "2021-11-02T23:37:53Z",
|
||||||
|
Commit: "1b6da43b82b22e4eaa10bcf8ee591e91abbfc587",
|
||||||
|
Author: "Zachary Rice",
|
||||||
|
Email: "zricer@protonmail.com",
|
||||||
|
Message: "Accidentally add a secret",
|
||||||
|
RuleID: "aws-access-key",
|
||||||
|
Tags: []string{"key", "AWS"},
|
||||||
|
Entropy: 3.0841837,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: "AWS Access Key",
|
||||||
|
StartLine: 9,
|
||||||
|
EndLine: 9,
|
||||||
|
StartColumn: 17,
|
||||||
|
EndColumn: 36,
|
||||||
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
|
Match: "AKIALALEMEL33243OLIA",
|
||||||
|
File: "foo/foo.go",
|
||||||
|
Date: "2021-11-02T23:48:06Z",
|
||||||
|
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
||||||
|
Author: "Zach Rice",
|
||||||
|
Email: "zricer@protonmail.com",
|
||||||
|
Message: "adding foo package with secret",
|
||||||
|
RuleID: "aws-access-key",
|
||||||
|
Tags: []string{"key", "AWS"},
|
||||||
|
Entropy: 3.0841837,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: filepath.Join(repoBasePath, "small"),
|
||||||
|
logOpts: "--all foo...",
|
||||||
|
cfgName: "simple",
|
||||||
|
expectedFindings: []report.Finding{
|
||||||
|
{
|
||||||
|
Description: "AWS Access Key",
|
||||||
|
StartLine: 9,
|
||||||
|
EndLine: 9,
|
||||||
|
StartColumn: 17,
|
||||||
|
EndColumn: 36,
|
||||||
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
|
Match: "AKIALALEMEL33243OLIA",
|
||||||
|
Date: "2021-11-02T23:48:06Z",
|
||||||
|
File: "foo/foo.go",
|
||||||
|
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
||||||
|
Author: "Zach Rice",
|
||||||
|
Email: "zricer@protonmail.com",
|
||||||
|
Message: "adding foo package with secret",
|
||||||
|
RuleID: "aws-access-key",
|
||||||
|
Tags: []string{"key", "AWS"},
|
||||||
|
Entropy: 3.0841837,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := moveDotGit("dotGit", ".git")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err := moveDotGit(".git", "dotGit"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
|
||||||
|
viper.AddConfigPath(configPath)
|
||||||
|
viper.SetConfigName("simple")
|
||||||
|
viper.SetConfigType("toml")
|
||||||
|
err = viper.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var vc config.ViperConfig
|
||||||
|
err = viper.Unmarshal(&vc)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
cfg, err := vc.Translate()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
detector := NewDetector(cfg)
|
||||||
|
findings, err := detector.DetectGit(tt.source, tt.logOpts, DetectType)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range findings {
|
||||||
|
f.Match = "" // remove lines cause copying and pasting them has some wack formatting
|
||||||
|
}
|
||||||
|
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestFromGit tests the FromGit function
|
||||||
|
func TestFromFiles(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
cfgName string
|
||||||
|
source string
|
||||||
|
expectedFindings []report.Finding
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
source: filepath.Join(repoBasePath, "nogit"),
|
||||||
|
cfgName: "simple",
|
||||||
|
expectedFindings: []report.Finding{
|
||||||
|
{
|
||||||
|
Description: "AWS Access Key",
|
||||||
|
StartLine: 20,
|
||||||
|
EndLine: 20,
|
||||||
|
StartColumn: 16,
|
||||||
|
EndColumn: 35,
|
||||||
|
Match: "AKIALALEMEL33243OLIA",
|
||||||
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
|
File: "../testdata/repos/nogit/main.go",
|
||||||
|
RuleID: "aws-access-key",
|
||||||
|
Tags: []string{"key", "AWS"},
|
||||||
|
Entropy: 3.0841837,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: filepath.Join(repoBasePath, "nogit", "main.go"),
|
||||||
|
cfgName: "simple",
|
||||||
|
expectedFindings: []report.Finding{
|
||||||
|
{
|
||||||
|
Description: "AWS Access Key",
|
||||||
|
StartLine: 20,
|
||||||
|
EndLine: 20,
|
||||||
|
StartColumn: 16,
|
||||||
|
EndColumn: 35,
|
||||||
|
Match: "AKIALALEMEL33243OLIA",
|
||||||
|
Secret: "AKIALALEMEL33243OLIA",
|
||||||
|
File: "../testdata/repos/nogit/main.go",
|
||||||
|
RuleID: "aws-access-key",
|
||||||
|
Tags: []string{"key", "AWS"},
|
||||||
|
Entropy: 3.0841837,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
viper.AddConfigPath(configPath)
|
||||||
|
viper.SetConfigName("simple")
|
||||||
|
viper.SetConfigType("toml")
|
||||||
|
err := viper.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var vc config.ViperConfig
|
||||||
|
err = viper.Unmarshal(&vc)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
cfg, _ := vc.Translate()
|
||||||
|
detector := NewDetector(cfg)
|
||||||
|
findings, err := detector.DetectFiles(tt.source)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveDotGit(from, to string) error {
|
||||||
|
repoDirs, err := os.ReadDir("../testdata/repos")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, dir := range repoDirs {
|
||||||
|
if to == ".git" {
|
||||||
|
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), "dotGit"))
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
// dont want to delete the only copy of .git accidentally
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
os.RemoveAll(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), ".git"))
|
||||||
|
}
|
||||||
|
if !dir.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from))
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Rename(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from),
|
||||||
|
fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), to))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
package detect
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"golang.org/x/sync/errgroup"
|
|
||||||
godocutil "golang.org/x/tools/godoc/util"
|
|
||||||
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FromFiles opens the directory or file specified in source and checks each file against the rules
|
|
||||||
// from the configuration. If any secrets are found, they are added to the list of findings.
|
|
||||||
func FromFiles(source string, cfg config.Config, outputOptions Options) ([]report.Finding, error) {
|
|
||||||
var (
|
|
||||||
findings []report.Finding
|
|
||||||
mu sync.Mutex
|
|
||||||
)
|
|
||||||
g, _ := errgroup.WithContext(context.Background())
|
|
||||||
paths := make(chan string)
|
|
||||||
g.Go(func() error {
|
|
||||||
defer close(paths)
|
|
||||||
return filepath.Walk(source,
|
|
||||||
func(path string, fInfo os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if fInfo.Name() == ".git" {
|
|
||||||
return filepath.SkipDir
|
|
||||||
}
|
|
||||||
if fInfo.Mode().IsRegular() {
|
|
||||||
paths <- path
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
})
|
|
||||||
for pa := range paths {
|
|
||||||
p := pa
|
|
||||||
g.Go(func() error {
|
|
||||||
b, err := os.ReadFile(p)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !godocutil.IsText(b) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
fis := DetectFindings(cfg, b, p, "")
|
|
||||||
for _, fi := range fis {
|
|
||||||
// need to add 1 since line counting starts at 1
|
|
||||||
fi.StartLine++
|
|
||||||
fi.EndLine++
|
|
||||||
|
|
||||||
if outputOptions.Redact {
|
|
||||||
fi.Redact()
|
|
||||||
}
|
|
||||||
if outputOptions.Verbose {
|
|
||||||
printFinding(fi)
|
|
||||||
}
|
|
||||||
mu.Lock()
|
|
||||||
findings = append(findings, fi)
|
|
||||||
mu.Unlock()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := g.Wait(); err != nil {
|
|
||||||
return findings, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return findings, nil
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package detect
|
|
||||||
|
|
||||||
import (
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestFromGit tests the FromGit function
|
|
||||||
func TestFromFiles(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
cfgName string
|
|
||||||
opts Options
|
|
||||||
source string
|
|
||||||
expectedFindings []report.Finding
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
source: filepath.Join(repoBasePath, "nogit"),
|
|
||||||
cfgName: "simple",
|
|
||||||
expectedFindings: []report.Finding{
|
|
||||||
{
|
|
||||||
Description: "AWS Access Key",
|
|
||||||
StartLine: 20,
|
|
||||||
EndLine: 20,
|
|
||||||
StartColumn: 16,
|
|
||||||
EndColumn: 35,
|
|
||||||
Match: "AKIALALEMEL33243OLIA",
|
|
||||||
Secret: "AKIALALEMEL33243OLIA",
|
|
||||||
File: "../testdata/repos/nogit/main.go",
|
|
||||||
RuleID: "aws-access-key",
|
|
||||||
Tags: []string{"key", "AWS"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
source: filepath.Join(repoBasePath, "nogit", "main.go"),
|
|
||||||
cfgName: "simple",
|
|
||||||
expectedFindings: []report.Finding{
|
|
||||||
{
|
|
||||||
Description: "AWS Access Key",
|
|
||||||
StartLine: 20,
|
|
||||||
EndLine: 20,
|
|
||||||
StartColumn: 16,
|
|
||||||
EndColumn: 35,
|
|
||||||
Match: "AKIALALEMEL33243OLIA",
|
|
||||||
Secret: "AKIALALEMEL33243OLIA",
|
|
||||||
File: "../testdata/repos/nogit/main.go",
|
|
||||||
RuleID: "aws-access-key",
|
|
||||||
Tags: []string{"key", "AWS"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
viper.AddConfigPath(configPath)
|
|
||||||
viper.SetConfigName("simple")
|
|
||||||
viper.SetConfigType("toml")
|
|
||||||
err := viper.ReadInConfig()
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var vc config.ViperConfig
|
|
||||||
viper.Unmarshal(&vc)
|
|
||||||
cfg, _ := vc.Translate()
|
|
||||||
|
|
||||||
findings, err := FromFiles(tt.source, cfg, tt.opts)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
package detect
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
|
||||||
godocutil "golang.org/x/tools/godoc/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FromGit accepts a gitdiff.File channel (structure output from `git log -p`) and a configuration
|
|
||||||
// struct. Files from the gitdiff.File channel are then checked against each rule in the configuration to
|
|
||||||
// check for secrets. If any secrets are found, they are added to the list of findings.
|
|
||||||
func FromGit(files <-chan *gitdiff.File, cfg config.Config, outputOptions Options) []report.Finding {
|
|
||||||
var findings []report.Finding
|
|
||||||
mu := sync.Mutex{}
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
commitMap := make(map[string]bool)
|
|
||||||
for f := range files {
|
|
||||||
// keep track of commits for logging
|
|
||||||
if f.PatchHeader != nil {
|
|
||||||
commitMap[f.PatchHeader.SHA] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
wg.Add(1)
|
|
||||||
go func(f *gitdiff.File) {
|
|
||||||
defer wg.Done()
|
|
||||||
if f.IsBinary {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.IsDelete {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
commitSHA := ""
|
|
||||||
|
|
||||||
// Check if commit is allowed
|
|
||||||
if f.PatchHeader != nil {
|
|
||||||
commitSHA = f.PatchHeader.SHA
|
|
||||||
if cfg.Allowlist.CommitAllowed(f.PatchHeader.SHA) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tf := range f.TextFragments {
|
|
||||||
if f.TextFragments == nil {
|
|
||||||
// TODO fix this in gitleaks gitdiff fork
|
|
||||||
// https://github.com/gitleaks/gitleaks/issues/11
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !godocutil.IsText([]byte(tf.Raw(gitdiff.OpAdd))) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, fi := range DetectFindings(cfg, []byte(tf.Raw(gitdiff.OpAdd)), f.NewName, commitSHA) {
|
|
||||||
// don't add to start/end lines if finding is from a file only rule
|
|
||||||
if !strings.HasPrefix(fi.Match, "file detected") {
|
|
||||||
fi.StartLine += int(tf.NewPosition)
|
|
||||||
fi.EndLine += int(tf.NewPosition)
|
|
||||||
}
|
|
||||||
if f.PatchHeader != nil {
|
|
||||||
fi.Commit = f.PatchHeader.SHA
|
|
||||||
fi.Message = f.PatchHeader.Message()
|
|
||||||
if f.PatchHeader.Author != nil {
|
|
||||||
fi.Author = f.PatchHeader.Author.Name
|
|
||||||
fi.Email = f.PatchHeader.Author.Email
|
|
||||||
}
|
|
||||||
fi.Date = f.PatchHeader.AuthorDate.UTC().Format(time.RFC3339)
|
|
||||||
}
|
|
||||||
|
|
||||||
if outputOptions.Redact {
|
|
||||||
fi.Redact()
|
|
||||||
}
|
|
||||||
|
|
||||||
if outputOptions.Verbose {
|
|
||||||
printFinding(fi)
|
|
||||||
}
|
|
||||||
mu.Lock()
|
|
||||||
findings = append(findings, fi)
|
|
||||||
mu.Unlock()
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
wg.Wait()
|
|
||||||
log.Debug().Msgf("%d commits scanned. Note: this number might be smaller than expected due to commits with no additions", len(commitMap))
|
|
||||||
return findings
|
|
||||||
}
|
|
||||||
File renamed without changes.
@@ -0,0 +1,158 @@
|
|||||||
|
package git_test
|
||||||
|
|
||||||
|
// TODO: commenting out this test for now because it's flaky. Alternatives to consider to get this working:
|
||||||
|
// -- use `git stash` instead of `restore()`
|
||||||
|
|
||||||
|
// const repoBasePath = "../../testdata/repos/"
|
||||||
|
|
||||||
|
// const expectPath = "../../testdata/expected/"
|
||||||
|
|
||||||
|
// func TestGitLog(t *testing.T) {
|
||||||
|
// tests := []struct {
|
||||||
|
// source string
|
||||||
|
// logOpts string
|
||||||
|
// expected string
|
||||||
|
// }{
|
||||||
|
// {
|
||||||
|
// source: filepath.Join(repoBasePath, "small"),
|
||||||
|
// expected: filepath.Join(expectPath, "git", "small.txt"),
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// source: filepath.Join(repoBasePath, "small"),
|
||||||
|
// expected: filepath.Join(expectPath, "git", "small-branch-foo.txt"),
|
||||||
|
// logOpts: "--all foo...",
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
|
||||||
|
// err := moveDotGit("dotGit", ".git")
|
||||||
|
// if err != nil {
|
||||||
|
// t.Fatal(err)
|
||||||
|
// }
|
||||||
|
// defer func() {
|
||||||
|
// if err = moveDotGit(".git", "dotGit"); err != nil {
|
||||||
|
// t.Fatal(err)
|
||||||
|
// }
|
||||||
|
// }()
|
||||||
|
|
||||||
|
// for _, tt := range tests {
|
||||||
|
// files, err := git.GitLog(tt.source, tt.logOpts)
|
||||||
|
// if err != nil {
|
||||||
|
// t.Error(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var diffSb strings.Builder
|
||||||
|
// for f := range files {
|
||||||
|
// for _, tf := range f.TextFragments {
|
||||||
|
// diffSb.WriteString(tf.Raw(gitdiff.OpAdd))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// expectedBytes, err := os.ReadFile(tt.expected)
|
||||||
|
// if err != nil {
|
||||||
|
// t.Error(err)
|
||||||
|
// }
|
||||||
|
// expected := string(expectedBytes)
|
||||||
|
// if expected != diffSb.String() {
|
||||||
|
// // write string builder to .got file using os.Create
|
||||||
|
// err = os.WriteFile(strings.Replace(tt.expected, ".txt", ".got.txt", 1), []byte(diffSb.String()), 0644)
|
||||||
|
// if err != nil {
|
||||||
|
// t.Error(err)
|
||||||
|
// }
|
||||||
|
// t.Error("expected: ", expected, "got: ", diffSb.String())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func TestGitDiff(t *testing.T) {
|
||||||
|
// tests := []struct {
|
||||||
|
// source string
|
||||||
|
// expected string
|
||||||
|
// additions string
|
||||||
|
// target string
|
||||||
|
// }{
|
||||||
|
// {
|
||||||
|
// source: filepath.Join(repoBasePath, "small"),
|
||||||
|
// expected: "this line is added\nand another one",
|
||||||
|
// additions: "this line is added\nand another one",
|
||||||
|
// target: filepath.Join(repoBasePath, "small", "main.go"),
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
|
||||||
|
// err := moveDotGit("dotGit", ".git")
|
||||||
|
// if err != nil {
|
||||||
|
// t.Fatal(err)
|
||||||
|
// }
|
||||||
|
// defer func() {
|
||||||
|
// if err = moveDotGit(".git", "dotGit"); err != nil {
|
||||||
|
// t.Fatal(err)
|
||||||
|
// }
|
||||||
|
// }()
|
||||||
|
|
||||||
|
// for _, tt := range tests {
|
||||||
|
// noChanges, err := os.ReadFile(tt.target)
|
||||||
|
// if err != nil {
|
||||||
|
// t.Error(err)
|
||||||
|
// }
|
||||||
|
// err = os.WriteFile(tt.target, []byte(tt.additions), 0644)
|
||||||
|
// if err != nil {
|
||||||
|
// restore(tt.target, noChanges, t)
|
||||||
|
// t.Error(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// files, err := git.GitDiff(tt.source, false)
|
||||||
|
// if err != nil {
|
||||||
|
// restore(tt.target, noChanges, t)
|
||||||
|
// t.Error(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for f := range files {
|
||||||
|
// sb := strings.Builder{}
|
||||||
|
// for _, tf := range f.TextFragments {
|
||||||
|
// sb.WriteString(tf.Raw(gitdiff.OpAdd))
|
||||||
|
// }
|
||||||
|
// if sb.String() != tt.expected {
|
||||||
|
// restore(tt.target, noChanges, t)
|
||||||
|
// t.Error("expected: ", tt.expected, "got: ", sb.String())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// restore(tt.target, noChanges, t)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func restore(path string, data []byte, t *testing.T) {
|
||||||
|
// err := os.WriteFile(path, data, 0644)
|
||||||
|
// if err != nil {
|
||||||
|
// t.Fatal(err)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func moveDotGit(from, to string) error {
|
||||||
|
// repoDirs, err := os.ReadDir("../../testdata/repos")
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// for _, dir := range repoDirs {
|
||||||
|
// if to == ".git" {
|
||||||
|
// _, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), "dotGit"))
|
||||||
|
// if os.IsNotExist(err) {
|
||||||
|
// // dont want to delete the only copy of .git accidentally
|
||||||
|
// continue
|
||||||
|
// }
|
||||||
|
// os.RemoveAll(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), ".git"))
|
||||||
|
// }
|
||||||
|
// if !dir.IsDir() {
|
||||||
|
// continue
|
||||||
|
// }
|
||||||
|
// _, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from))
|
||||||
|
// if os.IsNotExist(err) {
|
||||||
|
// continue
|
||||||
|
// }
|
||||||
|
|
||||||
|
// err = os.Rename(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from),
|
||||||
|
// fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), to))
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
package detect
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
|
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/git"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/report"
|
|
||||||
)
|
|
||||||
|
|
||||||
const repoBasePath = "../testdata/repos/"
|
|
||||||
const expectPath = "../testdata/expected/"
|
|
||||||
const configPath = "../testdata/config/"
|
|
||||||
|
|
||||||
// TestFromGit tests the FromGit function
|
|
||||||
func TestFromGit(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
cfgName string
|
|
||||||
opts Options
|
|
||||||
source string
|
|
||||||
logOpts string
|
|
||||||
expected string
|
|
||||||
expectedFindings []report.Finding
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
source: filepath.Join(repoBasePath, "small"),
|
|
||||||
expected: filepath.Join(expectPath, "git", "small.txt"),
|
|
||||||
cfgName: "simple",
|
|
||||||
expectedFindings: []report.Finding{
|
|
||||||
{
|
|
||||||
Description: "AWS Access Key",
|
|
||||||
StartLine: 20,
|
|
||||||
EndLine: 20,
|
|
||||||
StartColumn: 19,
|
|
||||||
EndColumn: 38,
|
|
||||||
Secret: "AKIALALEMEL33243OLIA",
|
|
||||||
Match: "AKIALALEMEL33243OLIA",
|
|
||||||
File: "main.go",
|
|
||||||
Date: "2021-11-02T23:37:53Z",
|
|
||||||
Commit: "1b6da43b82b22e4eaa10bcf8ee591e91abbfc587",
|
|
||||||
Author: "Zachary Rice",
|
|
||||||
Email: "zricer@protonmail.com",
|
|
||||||
Message: "Accidentally add a secret",
|
|
||||||
RuleID: "aws-access-key",
|
|
||||||
Tags: []string{"key", "AWS"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Description: "AWS Access Key",
|
|
||||||
StartLine: 9,
|
|
||||||
EndLine: 9,
|
|
||||||
StartColumn: 17,
|
|
||||||
EndColumn: 36,
|
|
||||||
Secret: "AKIALALEMEL33243OLIA",
|
|
||||||
Match: "AKIALALEMEL33243OLIA",
|
|
||||||
File: "foo/foo.go",
|
|
||||||
Date: "2021-11-02T23:48:06Z",
|
|
||||||
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
|
||||||
Author: "Zach Rice",
|
|
||||||
Email: "zricer@protonmail.com",
|
|
||||||
Message: "adding foo package with secret",
|
|
||||||
RuleID: "aws-access-key",
|
|
||||||
Tags: []string{"key", "AWS"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
source: filepath.Join(repoBasePath, "small"),
|
|
||||||
expected: filepath.Join(expectPath, "git", "small-branch-foo.txt"),
|
|
||||||
logOpts: "--all foo...",
|
|
||||||
cfgName: "simple",
|
|
||||||
expectedFindings: []report.Finding{
|
|
||||||
{
|
|
||||||
Description: "AWS Access Key",
|
|
||||||
StartLine: 9,
|
|
||||||
EndLine: 9,
|
|
||||||
StartColumn: 17,
|
|
||||||
EndColumn: 36,
|
|
||||||
Secret: "AKIALALEMEL33243OLIA",
|
|
||||||
Match: "AKIALALEMEL33243OLIA",
|
|
||||||
Date: "2021-11-02T23:48:06Z",
|
|
||||||
File: "foo/foo.go",
|
|
||||||
Commit: "491504d5a31946ce75e22554cc34203d8e5ff3ca",
|
|
||||||
Author: "Zach Rice",
|
|
||||||
Email: "zricer@protonmail.com",
|
|
||||||
Message: "adding foo package with secret",
|
|
||||||
RuleID: "aws-access-key",
|
|
||||||
Tags: []string{"key", "AWS"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := moveDotGit("dotGit", ".git")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer moveDotGit(".git", "dotGit")
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
files, err := git.GitLog(tt.source, tt.logOpts)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
viper.AddConfigPath(configPath)
|
|
||||||
viper.SetConfigName("simple")
|
|
||||||
viper.SetConfigType("toml")
|
|
||||||
err = viper.ReadInConfig()
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var vc config.ViperConfig
|
|
||||||
viper.Unmarshal(&vc)
|
|
||||||
cfg, _ := vc.Translate()
|
|
||||||
|
|
||||||
findings := FromGit(files, cfg, tt.opts)
|
|
||||||
for _, f := range findings {
|
|
||||||
f.Match = "" // remove lines cause copying and pasting them has some wack formatting
|
|
||||||
}
|
|
||||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func moveDotGit(from, to string) error {
|
|
||||||
repoDirs, err := os.ReadDir("../testdata/repos")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, dir := range repoDirs {
|
|
||||||
if to == ".git" {
|
|
||||||
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), "dotGit"))
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
// dont want to delete the only copy of .git accidentally
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
os.RemoveAll(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), ".git"))
|
|
||||||
}
|
|
||||||
if !dir.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from))
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Rename(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from),
|
|
||||||
fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), to))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
+19
-3
@@ -10,7 +10,7 @@ type Location struct {
|
|||||||
endLineIndex int
|
endLineIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLocation(linePairs [][]int, start int, end int) Location {
|
func location(fragment Fragment, matchIndex []int) Location {
|
||||||
var (
|
var (
|
||||||
prevNewLine int
|
prevNewLine int
|
||||||
location Location
|
location Location
|
||||||
@@ -18,8 +18,10 @@ func getLocation(linePairs [][]int, start int, end int) Location {
|
|||||||
_lineNum int
|
_lineNum int
|
||||||
)
|
)
|
||||||
|
|
||||||
for lineNum, pair := range linePairs {
|
start := matchIndex[0]
|
||||||
_lineNum = lineNum
|
end := matchIndex[1]
|
||||||
|
|
||||||
|
for lineNum, pair := range fragment.newlineIndices {
|
||||||
newLineByteIndex := pair[0]
|
newLineByteIndex := pair[0]
|
||||||
if prevNewLine <= start && start < newLineByteIndex {
|
if prevNewLine <= start && start < newLineByteIndex {
|
||||||
lineSet = true
|
lineSet = true
|
||||||
@@ -45,6 +47,20 @@ func getLocation(linePairs [][]int, start int, end int) Location {
|
|||||||
location.endColumn = (end - prevNewLine)
|
location.endColumn = (end - prevNewLine)
|
||||||
location.startLine = _lineNum + 1
|
location.startLine = _lineNum + 1
|
||||||
location.endLine = _lineNum + 1
|
location.endLine = _lineNum + 1
|
||||||
|
location.startLineIndex = start
|
||||||
|
|
||||||
|
// search for new line byte index
|
||||||
|
i := 0
|
||||||
|
for end+i < len(fragment.Raw) {
|
||||||
|
if fragment.Raw[end+i] == '\n' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if fragment.Raw[end+i] == '\r' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
location.endLineIndex = end + i
|
||||||
}
|
}
|
||||||
return location
|
return location
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ func TestGetLocation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
loc := getLocation(test.linePairs, test.start, test.end)
|
loc := location(Fragment{newlineIndices: test.linePairs}, []int{test.start, test.end})
|
||||||
if loc != test.wantLocation {
|
if loc != test.wantLocation {
|
||||||
t.Errorf("\nstartLine %d\nstartColumn: %d\nendLine: %d\nendColumn: %d\nstartLineIndex: %d\nendlineIndex %d",
|
t.Errorf("\nstartLine %d\nstartColumn: %d\nendLine: %d\nendColumn: %d\nstartLineIndex: %d\nendlineIndex %d",
|
||||||
loc.startLine, loc.startColumn, loc.endLine, loc.endColumn, loc.startLineIndex, loc.endLineIndex)
|
loc.startLine, loc.startColumn, loc.endLine, loc.endColumn, loc.startLineIndex, loc.endLineIndex)
|
||||||
|
|||||||
+108
@@ -0,0 +1,108 @@
|
|||||||
|
package detect
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/zricethezav/gitleaks/v8/report"
|
||||||
|
|
||||||
|
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// augmentGitFinding updates the start and end line numbers of a finding to include the
|
||||||
|
// delta from the git diff
|
||||||
|
func augmentGitFinding(finding report.Finding, textFragment *gitdiff.TextFragment, f *gitdiff.File) report.Finding {
|
||||||
|
if !strings.HasPrefix(finding.Match, "file detected") {
|
||||||
|
finding.StartLine += int(textFragment.NewPosition)
|
||||||
|
finding.EndLine += int(textFragment.NewPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.PatchHeader != nil {
|
||||||
|
finding.Commit = f.PatchHeader.SHA
|
||||||
|
finding.Message = f.PatchHeader.Message()
|
||||||
|
if f.PatchHeader.Author != nil {
|
||||||
|
finding.Author = f.PatchHeader.Author.Name
|
||||||
|
finding.Email = f.PatchHeader.Author.Email
|
||||||
|
}
|
||||||
|
finding.Date = f.PatchHeader.AuthorDate.UTC().Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
return finding
|
||||||
|
}
|
||||||
|
|
||||||
|
// shannonEntropy calculates the entropy of data using the formula defined here:
|
||||||
|
// https://en.wiktionary.org/wiki/Shannon_entropy
|
||||||
|
// Another way to think about what this is doing is calculating the number of bits
|
||||||
|
// needed to on average encode the data. So, the higher the entropy, the more random the data, the
|
||||||
|
// more bits needed to encode that data.
|
||||||
|
func shannonEntropy(data string) (entropy float64) {
|
||||||
|
if data == "" {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
charCounts := make(map[rune]int)
|
||||||
|
for _, char := range data {
|
||||||
|
charCounts[char]++
|
||||||
|
}
|
||||||
|
|
||||||
|
invLength := 1.0 / float64(len(data))
|
||||||
|
for _, count := range charCounts {
|
||||||
|
freq := float64(count) * invLength
|
||||||
|
entropy -= freq * math.Log2(freq)
|
||||||
|
}
|
||||||
|
|
||||||
|
return entropy
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter will dedupe and redact findings
|
||||||
|
func filter(findings []report.Finding, redact bool) []report.Finding {
|
||||||
|
var retFindings []report.Finding
|
||||||
|
for _, f := range findings {
|
||||||
|
include := true
|
||||||
|
if strings.Contains(strings.ToLower(f.RuleID), "generic") {
|
||||||
|
for _, fPrime := range findings {
|
||||||
|
if f.StartLine == fPrime.StartLine &&
|
||||||
|
f.EndLine == fPrime.EndLine &&
|
||||||
|
f.Commit == fPrime.Commit &&
|
||||||
|
f.RuleID != fPrime.RuleID &&
|
||||||
|
strings.Contains(fPrime.Secret, f.Secret) &&
|
||||||
|
!strings.Contains(strings.ToLower(fPrime.RuleID), "generic") {
|
||||||
|
|
||||||
|
genericMatch := strings.Replace(f.Match, f.Secret, "REDACTED", -1)
|
||||||
|
betterMatch := strings.Replace(fPrime.Match, fPrime.Secret, "REDACTED", -1)
|
||||||
|
log.Debug().Msgf("skipping %s finding (%s), %s rule takes precendence (%s)", f.RuleID, genericMatch, fPrime.RuleID, betterMatch)
|
||||||
|
include = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if redact {
|
||||||
|
f.Redact()
|
||||||
|
}
|
||||||
|
if include {
|
||||||
|
retFindings = append(retFindings, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retFindings
|
||||||
|
}
|
||||||
|
|
||||||
|
func printFinding(f report.Finding) {
|
||||||
|
var b []byte
|
||||||
|
b, _ = json.MarshalIndent(f, "", " ")
|
||||||
|
fmt.Println(string(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
func containsDigit(s string) bool {
|
||||||
|
for _, c := range s {
|
||||||
|
switch c {
|
||||||
|
case '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
-157
@@ -1,157 +0,0 @@
|
|||||||
package git_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
|
||||||
"github.com/zricethezav/gitleaks/v8/git"
|
|
||||||
)
|
|
||||||
|
|
||||||
const repoBasePath = "../testdata/repos/"
|
|
||||||
const expectPath = "../testdata/expected/"
|
|
||||||
|
|
||||||
func TestGitLog(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
source string
|
|
||||||
logOpts string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
source: filepath.Join(repoBasePath, "small"),
|
|
||||||
expected: filepath.Join(expectPath, "git", "small.txt"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
source: filepath.Join(repoBasePath, "small"),
|
|
||||||
expected: filepath.Join(expectPath, "git", "small-branch-foo.txt"),
|
|
||||||
logOpts: "--all foo...",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := moveDotGit("dotGit", ".git")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer moveDotGit(".git", "dotGit")
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
files, err := git.GitLog(tt.source, tt.logOpts)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var diffSb strings.Builder
|
|
||||||
for f := range files {
|
|
||||||
for _, tf := range f.TextFragments {
|
|
||||||
diffSb.WriteString(tf.Raw(gitdiff.OpAdd))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedBytes, err := os.ReadFile(tt.expected)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
expected := string(expectedBytes)
|
|
||||||
if expected != diffSb.String() {
|
|
||||||
// write string builder to .got file using os.Create
|
|
||||||
err = os.WriteFile(strings.Replace(tt.expected, ".txt", ".got.txt", 1), []byte(diffSb.String()), 0644)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
t.Error("expected: ", expected, "got: ", diffSb.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGitDiff(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
source string
|
|
||||||
expected string
|
|
||||||
additions string
|
|
||||||
target string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
source: filepath.Join(repoBasePath, "small"),
|
|
||||||
expected: "this line is added\nand another one",
|
|
||||||
additions: "this line is added\nand another one",
|
|
||||||
target: filepath.Join(repoBasePath, "small", "main.go"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := moveDotGit("dotGit", ".git")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer moveDotGit(".git", "dotGit")
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
noChanges, err := os.ReadFile(tt.target)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
err = os.WriteFile(tt.target, []byte(tt.additions), 0644)
|
|
||||||
if err != nil {
|
|
||||||
restore(tt.target, noChanges, t)
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
files, err := git.GitDiff(tt.source, false)
|
|
||||||
if err != nil {
|
|
||||||
restore(tt.target, noChanges, t)
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for f := range files {
|
|
||||||
sb := strings.Builder{}
|
|
||||||
for _, tf := range f.TextFragments {
|
|
||||||
sb.WriteString(tf.Raw(gitdiff.OpAdd))
|
|
||||||
}
|
|
||||||
if sb.String() != tt.expected {
|
|
||||||
restore(tt.target, noChanges, t)
|
|
||||||
t.Error("expected: ", tt.expected, "got: ", sb.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
restore(tt.target, noChanges, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func restore(path string, data []byte, t *testing.T) {
|
|
||||||
err := os.WriteFile(path, data, 0644)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func moveDotGit(from, to string) error {
|
|
||||||
repoDirs, err := os.ReadDir("../testdata/repos")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, dir := range repoDirs {
|
|
||||||
if to == ".git" {
|
|
||||||
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), "dotGit"))
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
// dont want to delete the only copy of .git accidentally
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
os.RemoveAll(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), ".git"))
|
|
||||||
}
|
|
||||||
if !dir.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from))
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Rename(fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), from),
|
|
||||||
fmt.Sprintf("%s/%s/%s", repoBasePath, dir.Name(), to))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,35 @@
|
|||||||
module github.com/zricethezav/gitleaks/v8
|
module github.com/zricethezav/gitleaks/v8
|
||||||
|
|
||||||
go 1.16
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/fatih/semgroup v1.2.0
|
||||||
github.com/gitleaks/go-gitdiff v0.7.4
|
github.com/gitleaks/go-gitdiff v0.7.4
|
||||||
github.com/rs/zerolog v1.25.0
|
github.com/rs/zerolog v1.26.1
|
||||||
github.com/spf13/cobra v1.2.1
|
github.com/spf13/cobra v1.2.1
|
||||||
github.com/spf13/viper v1.8.1
|
github.com/spf13/viper v1.8.1
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||||
|
github.com/h2non/filetype v1.1.3 // indirect
|
||||||
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
|
github.com/magiconair/properties v1.8.5 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.9.3 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/spf13/afero v1.6.0 // indirect
|
||||||
|
github.com/spf13/cast v1.3.1 // indirect
|
||||||
|
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/subosito/gotenv v1.2.0 // indirect
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect
|
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect
|
||||||
golang.org/x/tools v0.1.5
|
golang.org/x/text v0.3.6 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||||
)
|
)
|
||||||
@@ -67,6 +67,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
|
|||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
|
github.com/fatih/semgroup v1.2.0 h1:h/OLXwEM+3NNyAdZEpMiH1OzfplU09i2qXPVThGZvyg=
|
||||||
|
github.com/fatih/semgroup v1.2.0/go.mod h1:1KAD4iIYfXjE4U13B48VM4z9QUwV5Tt8O4rS879kgm8=
|
||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||||
@@ -141,6 +143,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
|
|||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||||
|
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
|
||||||
|
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
|
||||||
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
|
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
|
||||||
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
@@ -209,8 +213,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
|
|||||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
github.com/rs/zerolog v1.25.0 h1:Rj7XygbUHKUlDPcVdoLyR91fJBsduXj5fRxyqIQj/II=
|
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
|
||||||
github.com/rs/zerolog v1.25.0/go.mod h1:7KHcEGe0QZPOm2IE4Kpb5rTh6n1h2hIgS5OOnu1rUaI=
|
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||||
@@ -246,6 +250,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
|||||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
|
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||||
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
|
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
|
||||||
@@ -266,6 +271,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
|
|||||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||||
@@ -337,6 +343,7 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
|
|||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
|
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
@@ -401,7 +408,9 @@ golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 h1:WecRHqgE09JBkh/584XIE6PMz5KKE/vER4izNUi30AQ=
|
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 h1:WecRHqgE09JBkh/584XIE6PMz5KKE/vER4izNUi30AQ=
|
||||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
@@ -411,8 +420,9 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
|
|||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
@@ -467,8 +477,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
|
|||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||||
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
|
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@@ -576,9 +585,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
|
|||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
||||||
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
|||||||
@@ -2,4 +2,3 @@ package report
|
|||||||
|
|
||||||
const version = "v8.0.0"
|
const version = "v8.0.0"
|
||||||
const driver = "gitleaks"
|
const driver = "gitleaks"
|
||||||
const driverURL = "https://github.com/zricethezav/gitleaks"
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package report
|
package report
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,10 +42,3 @@ func (f *Finding) Redact() {
|
|||||||
f.Match = strings.Replace(f.Match, f.Secret, "REDACTED", -1)
|
f.Match = strings.Replace(f.Match, f.Secret, "REDACTED", -1)
|
||||||
f.Secret = "REDACT"
|
f.Secret = "REDACT"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Finding) Hash() string {
|
|
||||||
return f.Secret + f.Commit +
|
|
||||||
strconv.Itoa(f.EndLine) +
|
|
||||||
strconv.Itoa(f.StartLine)
|
|
||||||
|
|
||||||
}
|
|
||||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
func writeJson(findings []Finding, w io.WriteCloser) error {
|
func writeJson(findings []Finding, w io.WriteCloser) error {
|
||||||
if len(findings) == 0 {
|
if len(findings) == 0 {
|
||||||
return nil
|
findings = []Finding{}
|
||||||
}
|
}
|
||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
encoder.SetIndent("", " ")
|
encoder.SetIndent("", " ")
|
||||||
|
|||||||
+1
-2
@@ -39,9 +39,8 @@ func TestWriteJSON(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
{
|
{
|
||||||
|
|
||||||
wantEmpty: true,
|
|
||||||
testReportName: "empty",
|
testReportName: "empty",
|
||||||
expected: filepath.Join(expectPath, "report", "this_should_not_exist.json"),
|
expected: filepath.Join(expectPath, "report", "empty.json"),
|
||||||
findings: []Finding{}},
|
findings: []Finding{}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-8
@@ -14,9 +14,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Write(findings []Finding, cfg config.Config, ext string, reportPath string) error {
|
func Write(findings []Finding, cfg config.Config, ext string, reportPath string) error {
|
||||||
if len(findings) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
file, err := os.Create(reportPath)
|
file, err := os.Create(reportPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -24,13 +21,12 @@ func Write(findings []Finding, cfg config.Config, ext string, reportPath string)
|
|||||||
ext = strings.ToLower(ext)
|
ext = strings.ToLower(ext)
|
||||||
switch ext {
|
switch ext {
|
||||||
case ".json", "json":
|
case ".json", "json":
|
||||||
writeJson(findings, file)
|
err = writeJson(findings, file)
|
||||||
case ".csv", "csv":
|
case ".csv", "csv":
|
||||||
writeCsv(findings, file)
|
err = writeCsv(findings, file)
|
||||||
case ".sarif", "sarif":
|
case ".sarif", "sarif":
|
||||||
writeSarif(cfg, findings, file)
|
err = writeSarif(cfg, findings, file)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
+28
-18
@@ -30,25 +30,46 @@ func getRuns(cfg config.Config, findings []Finding) []Runs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTool(cfg config.Config) Tool {
|
func getTool(cfg config.Config) Tool {
|
||||||
return Tool{
|
tool := Tool{
|
||||||
Driver: Driver{
|
Driver: Driver{
|
||||||
Name: driver,
|
Name: driver,
|
||||||
SemanticVersion: version,
|
SemanticVersion: version,
|
||||||
Rules: getRules(cfg),
|
Rules: getRules(cfg),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if this tool has no rules, ensure that it is represented as [] instead of null/nil
|
||||||
|
if hasEmptyRules(tool) {
|
||||||
|
tool.Driver.Rules = make([]Rules, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tool
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasEmptyRules(tool Tool) bool {
|
||||||
|
return len(tool.Driver.Rules) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRules(cfg config.Config) []Rules {
|
func getRules(cfg config.Config) []Rules {
|
||||||
// TODO for _, rule := range cfg.Rules {
|
// TODO for _, rule := range cfg.Rules {
|
||||||
var rules []Rules
|
var rules []Rules
|
||||||
for _, rule := range cfg.Rules {
|
for _, rule := range cfg.Rules {
|
||||||
rules = append(rules, Rules{
|
shortDescription := ShortDescription{
|
||||||
ID: rule.RuleID,
|
Text: rule.Description,
|
||||||
Name: rule.Description,
|
}
|
||||||
Description: ShortDescription{
|
if rule.Regex != nil {
|
||||||
|
shortDescription = ShortDescription{
|
||||||
Text: rule.Regex.String(),
|
Text: rule.Regex.String(),
|
||||||
},
|
}
|
||||||
|
} else if rule.Path != nil {
|
||||||
|
shortDescription = ShortDescription{
|
||||||
|
Text: rule.Path.String(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rules = append(rules, Rules{
|
||||||
|
ID: rule.RuleID,
|
||||||
|
Name: rule.Description,
|
||||||
|
Description: shortDescription,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return rules
|
return rules
|
||||||
@@ -64,7 +85,7 @@ func messageText(f Finding) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getResults(findings []Finding) []Results {
|
func getResults(findings []Finding) []Results {
|
||||||
var results []Results
|
results := []Results{}
|
||||||
for _, f := range findings {
|
for _, f := range findings {
|
||||||
r := Results{
|
r := Results{
|
||||||
Message: Message{
|
Message: Message{
|
||||||
@@ -186,14 +207,3 @@ type Runs struct {
|
|||||||
Tool Tool `json:"tool"`
|
Tool Tool `json:"tool"`
|
||||||
Results []Results `json:"results"`
|
Results []Results `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func configToRules(cfg config.Config) []Rules {
|
|
||||||
var rules []Rules
|
|
||||||
for _, rule := range cfg.Rules {
|
|
||||||
rules = append(rules, Rules{
|
|
||||||
ID: rule.RuleID,
|
|
||||||
Name: rule.Description,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return rules
|
|
||||||
}
|
|
||||||
@@ -63,7 +63,11 @@ func TestWriteSarif(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var vc config.ViperConfig
|
var vc config.ViperConfig
|
||||||
viper.Unmarshal(&vc)
|
err = viper.Unmarshal(&vc)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
cfg, err := vc.Translate()
|
cfg, err := vc.Translate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
title = "gitleaks config"
|
||||||
|
# https://learnxinyminutes.com/docs/toml/ for toml reference
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
id = "pypi-upload-token"
|
||||||
|
description = "PyPI upload token"
|
||||||
|
regex = '''pypi-AgEIcHlwaS5vcmc[A-Za-z0-9\-_]{50,1000}'''
|
||||||
|
tags = ["key", "pypi"]
|
||||||
+27
@@ -7,3 +7,30 @@ regex = '''(?i)((key|api|token|secret|password)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|
|
|||||||
path = '''.py'''
|
path = '''.py'''
|
||||||
entropy = 3.7
|
entropy = 3.7
|
||||||
secretGroup = 4
|
secretGroup = 4
|
||||||
|
|
||||||
|
[allowlist]
|
||||||
|
description = "global allow lists"
|
||||||
|
regexes = [
|
||||||
|
'''219-09-9999''',
|
||||||
|
'''078-05-1120''',
|
||||||
|
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
|
||||||
|
'''process''',
|
||||||
|
'''getenv''',
|
||||||
|
'''\.env''',
|
||||||
|
'''env\(''',
|
||||||
|
'''env\.''',
|
||||||
|
'''setting''',
|
||||||
|
'''load''',
|
||||||
|
'''token''',
|
||||||
|
'''password''',
|
||||||
|
'''secret''',
|
||||||
|
'''api\_key''',
|
||||||
|
'''apikey''',
|
||||||
|
'''api\-key''',
|
||||||
|
]
|
||||||
|
paths = [
|
||||||
|
'''gitleaks.toml''',
|
||||||
|
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
|
||||||
|
'''(go.mod|go.sum)$'''
|
||||||
|
]
|
||||||
|
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
Vendored
BIN
Binary file not shown.
Reference in new issue
Block a user