mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-27 19:54:24 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f75511665 | ||
|
|
190ac977be | ||
|
|
6dbb0c5af5 | ||
|
|
6705461b33 | ||
|
|
9869eab4c2 | ||
|
|
16f1ec0f1e | ||
|
|
8d80a5a5a2 | ||
|
|
146f69e51b | ||
|
|
51ca0f89b9 | ||
|
|
81cf30855c | ||
|
|
bd8b145bea | ||
|
|
839f114f2b | ||
|
|
63c3076ea2 | ||
|
|
b5a726e96a | ||
|
|
56079dc9ea | ||
|
|
9c6650d14a | ||
|
|
6fa63f41d8 | ||
|
|
fe9fb37c36 | ||
|
|
c3b7a98911 | ||
|
|
6c4a88c5a4 | ||
|
|
27481a9071 | ||
|
|
9701bf1724 | ||
|
|
a5b9c24779 | ||
|
|
db79d8194f | ||
|
|
8a31f4a4be | ||
|
|
6b0c303b26 | ||
|
|
1fb3a77eb8 | ||
|
|
765bcd5854 | ||
|
|
11c2ad01a4 | ||
|
|
e55d3975ec | ||
|
|
2dd9946052 | ||
|
|
4b5e8e1829 | ||
|
|
343e69399b | ||
|
|
0060ab636a | ||
|
|
025908808f | ||
|
|
088f8b8074 | ||
|
|
afdccad46f | ||
|
|
e002920355 | ||
|
|
d805fb9144 | ||
|
|
391d4d75f6 | ||
|
|
f77493274a | ||
|
|
7f229faf12 | ||
|
|
d0733f96f3 |
No files matched your search
@@ -27,3 +27,11 @@ If applicable, add screenshots to help explain your problem.
|
||||
Add any other context about the problem here.
|
||||
|
||||
cc @zricethezav
|
||||
|
||||
<!--
|
||||
|
||||
Check out the Secret Scanning Discord Server for live discussions:
|
||||
|
||||
https://discord.gg/sydS6AHTUP
|
||||
|
||||
--->
|
||||
@@ -1,5 +1,5 @@
|
||||
name: gitleaks
|
||||
on: [pull_request, push, workflow_dispatch]
|
||||
on: [push, workflow_dispatch]
|
||||
jobs:
|
||||
scan:
|
||||
name: gitleaks
|
||||
@@ -11,3 +11,4 @@ jobs:
|
||||
- uses: gitleaks/gitleaks-action@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}}
|
||||
@@ -9,7 +9,7 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
|
||||
@@ -749,4 +749,12 @@ acce01f2338434a78f6a4a06a097b0fd23280484:README.md:aws-access-token:220
|
||||
111c8b47b65627db117bd20be85ff0aee8961eb9:detect/detect_test.go:private-key:567
|
||||
99d620c719020fa24baa831299f0c964da79875e:detect/detect_test.go:aws-access-token:512
|
||||
99d620c719020fa24baa831299f0c964da79875e:detect/detect_test.go:aws-access-token:513
|
||||
69f161c0a0cc0f7858f7d0609d656f4edcedd84c:detect/detect_test.go:discord-api-token:326
|
||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:testdata/repos/staged/api/api.go:aws-access-token:7
|
||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:detect/detect_test.go:aws-access-token:505
|
||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:detect/detect_test.go:aws-access-token:506
|
||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:detect/detect_test.go:aws-access-token:507
|
||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:testdata/repos/staged/api/api.go:aws-access-token:6
|
||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:testdata/repos/staged/api/api.go:aws-access-token:7
|
||||
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ If you want to add a new rule to the [default Gitleaks configuration](https://gi
|
||||
func Beamer() *config.Rule {
|
||||
// Define Rule
|
||||
r := config.Rule{
|
||||
// Human redable description of the rule
|
||||
// Human readable description of the rule
|
||||
Description: "Beamer API token",
|
||||
|
||||
// Unique ID for the rule
|
||||
@@ -78,7 +78,7 @@ If you want to add a new rule to the [default Gitleaks configuration](https://gi
|
||||
token that is unique enough not to require an identifier then you can use
|
||||
this function. For example, Pulumi's API Token has the prefix `pul-` which is
|
||||
unique enough to use `generateUniqueToken`. But something like Beamer's API
|
||||
token that has a `b_` prefix is not unqiue enough to use `generateUniqueToken`,
|
||||
token that has a `b_` prefix is not unique enough to use `generateUniqueToken`,
|
||||
so instead we use `generateSemiGenericRegex` and require a `beamer`
|
||||
identifier is part of the rule.
|
||||
If a token's prefix has more than `3` characters then you could
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
<a href="https://hub.docker.com/r/zricethezav/gitleaks">
|
||||
<img src="https://img.shields.io/docker/pulls/zricethezav/gitleaks.svg" />
|
||||
</a>
|
||||
<a href="https://www.jit.io/jit-open-source-gitleaks?utm_source=github&utm_medium=badge&utm_campaign=GitleaksReadme&utm_id=oss&items=item-secret-detection">
|
||||
<img src="https://img.shields.io/badge/Secured%20by-Jit-B8287F?style=?style=plastic" />
|
||||
</a>
|
||||
<a href="https://github.com/zricethezav/gitleaks-action">
|
||||
<img alt="gitleaks badge" src="https://img.shields.io/badge/protected%20by-gitleaks-blue">
|
||||
</a>
|
||||
@@ -28,6 +25,8 @@
|
||||
</p>
|
||||
</p>
|
||||
|
||||
### Join our Discord! [](https://discord.gg/sydS6AHTUP)
|
||||
|
||||
Gitleaks is a SAST tool for **detecting** and **preventing** hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks is an **easy-to-use, all-in-one solution** for detecting secrets, past or present, in your code.
|
||||
|
||||
```
|
||||
@@ -68,16 +67,16 @@ docker pull zricethezav/gitleaks:latest
|
||||
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] --source="/path" [OPTIONS]
|
||||
|
||||
# Docker (ghcr.io)
|
||||
docker pull ghcr.io/zricethezav/gitleaks:latest
|
||||
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] --source="/path" [OPTIONS]
|
||||
docker pull ghcr.io/gitleaks/gitleaks:latest
|
||||
docker run -v ${path_to_host_folder_to_scan}:/path gitleaks/gitleaks:latest [COMMAND] --source="/path" [OPTIONS]
|
||||
|
||||
# From Source
|
||||
git clone https://github.com/zricethezav/gitleaks.git
|
||||
git clone https://github.com/gitleaks/gitleaks.git
|
||||
cd gitleaks
|
||||
make build
|
||||
```
|
||||
|
||||
### Github Action
|
||||
### GitHub Action
|
||||
|
||||
Check out the official [Gitleaks GitHub Action](https://github.com/gitleaks/gitleaks-action)
|
||||
|
||||
@@ -105,8 +104,8 @@ jobs:
|
||||
|
||||
```
|
||||
repos:
|
||||
- repo: https://github.com/zricethezav/gitleaks
|
||||
rev: v8.12.0
|
||||
- repo: https://github.com/gitleaks/gitleaks
|
||||
rev: v8.16.1
|
||||
hooks:
|
||||
- id: gitleaks
|
||||
```
|
||||
@@ -155,11 +154,12 @@ Flags:
|
||||
-h, --help help for gitleaks
|
||||
-l, --log-level string log level (trace, debug, info, warn, error, fatal) (default "info")
|
||||
--max-target-megabytes int files larger than this will be skipped
|
||||
--no-color turn off color for verbose output
|
||||
--no-banner suppress banner
|
||||
--redact redact secrets from logs and stdout
|
||||
-f, --report-format string output format (json, csv, sarif) (default "json")
|
||||
-r, --report-path string report file
|
||||
-s, --source string path to source (default: $PWD) (default ".")
|
||||
-s, --source string path to source (default ".")
|
||||
-v, --verbose show verbose output from scan
|
||||
|
||||
Use "gitleaks [command] --help" for more information about a command.
|
||||
@@ -184,7 +184,7 @@ You can scan files and directories by using the `--no-git` option.
|
||||
|
||||
#### Protect
|
||||
|
||||
The `protect` command is used to uncommitted changes in a git repo. This command should be used on developer machines in accordance with
|
||||
The `protect` command is used to scan uncommitted changes in a git repo. This command should be used on developer machines in accordance with
|
||||
[shifting left on security](https://cloud.google.com/architecture/devops/devops-tech-shifting-left-on-security).
|
||||
When running `protect` on a git repository, gitleaks will parse the output of a `git diff` command (you can see how this executed
|
||||
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L48-L49)). You can set the
|
||||
@@ -272,7 +272,7 @@ Gitleaks offers a configuration format you can follow to write your own secret d
|
||||
title = "Gitleaks title"
|
||||
|
||||
# Extend the base (this) configuration. When you extend a configuration
|
||||
# the base rules take precendence over the extended rules. I.e, if there are
|
||||
# the base rules take precedence over the extended rules. I.e., if there are
|
||||
# duplicate rules in both the base configuration and the extended configuration
|
||||
# the base rules will override the extended rules.
|
||||
# Another thing to know with extending configurations is you can chain together
|
||||
@@ -335,6 +335,10 @@ paths = [
|
||||
'''go\.mod''',
|
||||
'''go\.sum'''
|
||||
]
|
||||
# note: (rule) regexTarget defaults to check the _Secret_ in the finding.
|
||||
# if regexTarget is not specified then _Secret_ will be used.
|
||||
# Acceptable values for regexTarget are "match" and "line"
|
||||
regexTarget = "match"
|
||||
regexes = [
|
||||
'''process''',
|
||||
'''getenv''',
|
||||
@@ -357,6 +361,12 @@ paths = [
|
||||
'''gitleaks\.toml''',
|
||||
'''(.*?)(jpg|gif|doc)'''
|
||||
]
|
||||
|
||||
# note: (global) regexTarget defaults to check the _Secret_ in the finding.
|
||||
# if regexTarget is not specified then _Secret_ will be used.
|
||||
# Acceptable values for regexTarget are "match" and "line"
|
||||
regexTarget = "match"
|
||||
|
||||
regexes = [
|
||||
'''219-09-9999''',
|
||||
'''078-05-1120''',
|
||||
@@ -370,7 +380,7 @@ stopwords = [
|
||||
]
|
||||
```
|
||||
|
||||
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples or follow the [contributing guidelines](https://github.com/zricethezav/gitleaks/blob/master/README.md).
|
||||
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples or follow the [contributing guidelines](https://github.com/zricethezav/gitleaks/blob/master/README.md) if you would like to contribute to the default configuration. Additionally, you can check out [this gitleaks blog post](https://blog.gitleaks.io/stop-leaking-secrets-configuration-2-3-aeed293b1fbf) which covers advanced configuration setups.
|
||||
|
||||
### Additional Configuration
|
||||
|
||||
@@ -387,11 +397,7 @@ class CustomClass:
|
||||
|
||||
#### .gitleaksignore
|
||||
|
||||
You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is expirmental and is subject to change in the future.
|
||||
|
||||
## Secured by Jit
|
||||
|
||||
We use [Jit](https://www.jit.io/jit-open-source-gitleaks?utm_source=github&utm_medium=readme&utm_campaign=GitleaksReadme&utm_id=oss&items=item-secret-detection) to secure our codebase, to achieve fully automated, full-stack continuous security using the world's best OSS security tools.
|
||||
You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is experimental and is subject to change in the future.
|
||||
|
||||
## Sponsorships
|
||||
|
||||
|
||||
+23
-2
@@ -20,7 +20,7 @@ func init() {
|
||||
detectCmd.Flags().Bool("no-git", false, "treat git repo as a regular directory and scan those files, --log-opts has no effect on the scan when --no-git is set")
|
||||
detectCmd.Flags().Bool("pipe", false, "scan input from stdin, ex: `cat some_file | gitleaks detect --pipe`")
|
||||
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
|
||||
|
||||
detectCmd.Flags().StringP("gitleaks-ignore-path","i",".","path to .gitleaksignore file or folder containing one")
|
||||
}
|
||||
|
||||
var detectCmd = &cobra.Command{
|
||||
@@ -76,6 +76,27 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
// set color flag
|
||||
if detector.NoColor, err = cmd.Flags().GetBool("no-color"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
gitleaksIgnorePath, err:= cmd.Flags().GetString("gitleaks-ignore-path")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not get .gitleaksignore path")
|
||||
}
|
||||
|
||||
if fileExists(gitleaksIgnorePath) {
|
||||
if err = detector.AddGitleaksIgnore(gitleaksIgnorePath); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||
}
|
||||
}
|
||||
|
||||
if fileExists(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")) {
|
||||
if err = detector.AddGitleaksIgnore(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||
}
|
||||
}
|
||||
|
||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||
@@ -86,7 +107,7 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
// ignore findings from the baseline (an existing report in json format generated earlier)
|
||||
baselinePath, _ := cmd.Flags().GetString("baseline-path")
|
||||
if baselinePath != "" {
|
||||
err = detector.AddBaseline(baselinePath)
|
||||
err = detector.AddBaseline(baselinePath, source)
|
||||
if err != nil {
|
||||
log.Error().Msgf("Could not load baseline. The path must point of a gitleaks report generated using the default format: %s", err)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ func main() {
|
||||
configRules = append(configRules, rules.AsanaClientID())
|
||||
configRules = append(configRules, rules.AsanaClientSecret())
|
||||
configRules = append(configRules, rules.Atlassian())
|
||||
configRules = append(configRules, rules.Authress())
|
||||
configRules = append(configRules, rules.AWS())
|
||||
configRules = append(configRules, rules.BitBucketClientID())
|
||||
configRules = append(configRules, rules.BitBucketClientSecret())
|
||||
@@ -41,6 +42,7 @@ func main() {
|
||||
configRules = append(configRules, rules.Contentful())
|
||||
configRules = append(configRules, rules.Databricks())
|
||||
configRules = append(configRules, rules.DatadogtokenAccessToken())
|
||||
configRules = append(configRules, rules.DefinedNetworkingAPIToken())
|
||||
configRules = append(configRules, rules.DigitalOceanPAT())
|
||||
configRules = append(configRules, rules.DigitalOceanOAuthToken())
|
||||
configRules = append(configRules, rules.DigitalOceanRefreshToken())
|
||||
@@ -73,10 +75,13 @@ func main() {
|
||||
// configRules = append(configRules, rules.GCPServiceAccount())
|
||||
configRules = append(configRules, rules.GCPAPIKey())
|
||||
configRules = append(configRules, rules.GitHubPat())
|
||||
configRules = append(configRules, rules.GitHubFineGrainedPat())
|
||||
configRules = append(configRules, rules.GitHubOauth())
|
||||
configRules = append(configRules, rules.GitHubApp())
|
||||
configRules = append(configRules, rules.GitHubRefresh())
|
||||
configRules = append(configRules, rules.Gitlab())
|
||||
configRules = append(configRules, rules.GitlabPat())
|
||||
configRules = append(configRules, rules.GitlabPipelineTriggerToken())
|
||||
configRules = append(configRules, rules.GitlabRunnerRegistrationToken())
|
||||
configRules = append(configRules, rules.GitterAccessToken())
|
||||
configRules = append(configRules, rules.GrafanaApiKey())
|
||||
configRules = append(configRules, rules.GrafanaCloudApiToken())
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func Authress() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "Authress Service Client Access Key",
|
||||
RuleID: "authress-service-client-access-key",
|
||||
SecretGroup: 1,
|
||||
Regex: generateUniqueTokenRegex(`(?:sc|ext|scauth|authress)_[a-z0-9]{5,30}\.[a-z0-9]{4,6}\.acc_[a-z0-9-]{10,32}\.[a-z0-9+/_=-]{30,120}`),
|
||||
Keywords: []string{"sc_", "ext_", "scauth_", "authress_"},
|
||||
}
|
||||
|
||||
// validate
|
||||
// https://authress.io/knowledge-base/docs/authorization/service-clients/secrets-scanning/#1-detection
|
||||
service_client_id := "sc_" + alphaNumeric("10")
|
||||
access_key_id := alphaNumeric("4")
|
||||
account_id := "acc_" + alphaNumeric("10")
|
||||
signature_key := alphaNumericExtendedShort("40")
|
||||
|
||||
tps := []string{
|
||||
generateSampleSecret("authress", secrets.NewSecret(fmt.Sprintf(`%s\.%s\.%s\.%s`, service_client_id, access_key_id, account_id, signature_key))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -16,7 +16,11 @@ paths = [
|
||||
'''gitleaks.toml''',
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket)$''',
|
||||
'''(go.mod|go.sum)$''',
|
||||
'''gradle.lockfile''',
|
||||
'''node_modules''',
|
||||
'''package-lock.json''',
|
||||
'''pnpm-lock.yaml''',
|
||||
'''Database.refactorlog''',
|
||||
'''vendor''',
|
||||
]
|
||||
|
||||
@@ -57,4 +61,4 @@ keywords = [
|
||||
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
|
||||
]
|
||||
|
||||
{{end}}{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -0,0 +1,32 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func DefinedNetworkingAPIToken() *config.Rule {
|
||||
// Define Rule
|
||||
r := config.Rule{
|
||||
// Human redable description of the rule
|
||||
Description: "Defined Networking API token",
|
||||
|
||||
// Unique ID for the rule
|
||||
RuleID: "defined-networking-api-token",
|
||||
|
||||
// Regex capture group for the actual secret
|
||||
SecretGroup: 1,
|
||||
|
||||
// Regex used for detecting secrets. See regex section below for more details
|
||||
Regex: generateSemiGenericRegex([]string{"dnkey"}, `dnkey-[a-z0-9=_\-]{26}-[a-z0-9=_\-]{52}`),
|
||||
|
||||
// Keywords used for string matching on fragments (think of this as a prefilter)
|
||||
Keywords: []string{"dnkey"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
generateSampleSecret("dnkey", "dnkey-"+secrets.NewSecret(alphaNumericExtended("26"))+"-"+secrets.NewSecret(alphaNumericExtended("52"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -12,7 +12,7 @@ func EasyPost() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "EasyPost API token",
|
||||
RuleID: "easypost-api-token",
|
||||
Regex: regexp.MustCompile(`EZAK(?i)[a-z0-9]{54}`),
|
||||
Regex: regexp.MustCompile(`\bEZAK(?i)[a-z0-9]{54}`),
|
||||
Keywords: []string{"EZAK"},
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func EasyPostTestAPI() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "EasyPost test API token",
|
||||
RuleID: "easypost-test-api-token",
|
||||
Regex: regexp.MustCompile(`EZTK(?i)[a-z0-9]{54}`),
|
||||
Regex: regexp.MustCompile(`\bEZTK(?i)[a-z0-9]{54}`),
|
||||
Keywords: []string{"EZTK"},
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
func Facebook() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "Facebook",
|
||||
Description: "Facebook Access Token",
|
||||
RuleID: "facebook",
|
||||
Regex: generateSemiGenericRegex([]string{"facebook"}, hex("32")),
|
||||
SecretGroup: 1,
|
||||
|
||||
@@ -23,6 +23,22 @@ func GitHubPat() *config.Rule {
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitHubFineGrainedPat() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitHub Fine-Grained Personal Access Token",
|
||||
RuleID: "github-fine-grained-pat",
|
||||
Regex: regexp.MustCompile(`github_pat_[0-9a-zA-Z_]{82}`),
|
||||
Keywords: []string{"github_pat_"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
generateSampleSecret("github", "github_pat_"+secrets.NewSecret(alphaNumeric("82"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitHubOauth() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func Gitlab() *config.Rule {
|
||||
func GitlabPat() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitLab Personal Access Token",
|
||||
@@ -22,3 +22,35 @@ func Gitlab() *config.Rule {
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitlabPipelineTriggerToken() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitLab Pipeline Trigger Token",
|
||||
RuleID: "gitlab-ptt",
|
||||
Regex: regexp.MustCompile(`glptt-[0-9a-f]{40}`),
|
||||
Keywords: []string{"glptt-"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
generateSampleSecret("gitlab", "glptt-"+secrets.NewSecret(hex("40"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitlabRunnerRegistrationToken() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitLab Runner Registration Token",
|
||||
RuleID: "gitlab-rrt",
|
||||
Regex: regexp.MustCompile(`GR1348941[0-9a-zA-Z\-\_]{20}`),
|
||||
Keywords: []string{"GR1348941"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
generateSampleSecret("gitlab", "GR1348941"+secrets.NewSecret(alphaNumeric("20"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -9,12 +9,12 @@ func JWT() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "JSON Web Token",
|
||||
RuleID: "jwt",
|
||||
Regex: generateUniqueTokenRegex(`ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200}`),
|
||||
Regex: generateUniqueTokenRegex(`ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200}={0,2}`),
|
||||
Keywords: []string{"ey"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{`eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0`, // gitleaks:allow
|
||||
tps := []string{`eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0==`, // gitleaks:allow
|
||||
`JWT := eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0`, // gitleaks:allow
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
|
||||
@@ -11,7 +11,7 @@ func PrivateKey() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "Private Key",
|
||||
RuleID: "private-key",
|
||||
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----`),
|
||||
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----`),
|
||||
Keywords: []string{"-----BEGIN"},
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ anything
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`,
|
||||
`-----BEGIN PRIVATE KEY BLOCK-----
|
||||
anything
|
||||
-----END PRIVATE KEY BLOCK-----`,
|
||||
} // gitleaks:allow
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func StripeAccessToken() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "Stripe",
|
||||
Description: "Stripe Access Token",
|
||||
RuleID: "stripe-access-token",
|
||||
Regex: regexp.MustCompile(`(?i)(sk|pk)_(test|live)_[0-9a-z]{10,32}`),
|
||||
Keywords: []string{
|
||||
|
||||
@@ -28,9 +28,9 @@ func TelegramBotToken() *config.Rule {
|
||||
minToken := secrets.NewSecret(numeric("5") + ":A" + alphaNumericExtendedShort("34"))
|
||||
maxToken := secrets.NewSecret(numeric("16") + ":A" + alphaNumericExtendedShort("34"))
|
||||
tps := []string{
|
||||
// variable assigment
|
||||
// variable assignment
|
||||
generateSampleSecret("telegram", validToken),
|
||||
// URL contaning token
|
||||
// URL containing token
|
||||
generateSampleSecret("url", "https://api.telegram.org/bot"+validToken+"/sendMessage"),
|
||||
// object constructor
|
||||
`const bot = new Telegraf("` + validToken + `")`,
|
||||
|
||||
+28
-1
@@ -17,6 +17,7 @@ import (
|
||||
func init() {
|
||||
protectCmd.Flags().Bool("staged", false, "detect secrets in a --staged state")
|
||||
protectCmd.Flags().String("log-opts", "", "git log options")
|
||||
protectCmd.Flags().StringP("gitleaks-ignore-path","i",".","path to .gitleaksignore file or folder containing one")
|
||||
rootCmd.AddCommand(protectCmd)
|
||||
}
|
||||
|
||||
@@ -66,10 +67,36 @@ func runProtect(cmd *cobra.Command, args []string) {
|
||||
if detector.Redact, err = cmd.Flags().GetBool("redact"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
// set color flag
|
||||
if detector.NoColor, err = cmd.Flags().GetBool("no-color"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
gitleaksIgnorePath, err:= cmd.Flags().GetString("gitleaks-ignore-path")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not get .gitleaksignore path")
|
||||
}
|
||||
|
||||
if fileExists(gitleaksIgnorePath) {
|
||||
if err = detector.AddGitleaksIgnore(gitleaksIgnorePath); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||
}
|
||||
}
|
||||
|
||||
if fileExists(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")) {
|
||||
if err = detector.AddGitleaksIgnore(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||
}
|
||||
}
|
||||
|
||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||
}
|
||||
}
|
||||
|
||||
// get log options for git scan
|
||||
logOpts, err := cmd.Flags().GetString("log-opts")
|
||||
|
||||
+2
-1
@@ -39,12 +39,13 @@ func init() {
|
||||
cobra.OnInitialize(initLog)
|
||||
rootCmd.PersistentFlags().StringP("config", "c", "", configDescription)
|
||||
rootCmd.PersistentFlags().Int("exit-code", 1, "exit code when leaks have been encountered")
|
||||
rootCmd.PersistentFlags().StringP("source", "s", ".", "path to source (default: $PWD)")
|
||||
rootCmd.PersistentFlags().StringP("source", "s", ".", "path to source")
|
||||
rootCmd.PersistentFlags().StringP("report-path", "r", "", "report file")
|
||||
rootCmd.PersistentFlags().StringP("report-format", "f", "json", "output format (json, csv, sarif)")
|
||||
rootCmd.PersistentFlags().StringP("baseline-path", "b", "", "path to baseline with issues that can be ignored")
|
||||
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal)")
|
||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
||||
rootCmd.PersistentFlags().BoolP("no-color", "", false, "turn off color for verbose output")
|
||||
rootCmd.PersistentFlags().Int("max-target-megabytes", 0, "files larger than this will be skipped")
|
||||
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
||||
rootCmd.PersistentFlags().Bool("no-banner", false, "suppress banner")
|
||||
|
||||
@@ -14,6 +14,9 @@ type Allowlist struct {
|
||||
// Regexes is slice of content regular expressions that are allowed to be ignored.
|
||||
Regexes []*regexp.Regexp
|
||||
|
||||
// RegexTarget
|
||||
RegexTarget string
|
||||
|
||||
// Paths is a slice of path regular expressions that are allowed to be ignored.
|
||||
Paths []*regexp.Regexp
|
||||
|
||||
|
||||
+20
-16
@@ -36,17 +36,19 @@ type ViperConfig struct {
|
||||
Tags []string
|
||||
|
||||
Allowlist struct {
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
RegexTarget string
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
}
|
||||
}
|
||||
Allowlist struct {
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
RegexTarget string
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +124,11 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
Tags: r.Tags,
|
||||
Keywords: r.Keywords,
|
||||
Allowlist: Allowlist{
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: r.Allowlist.Commits,
|
||||
StopWords: r.Allowlist.StopWords,
|
||||
RegexTarget: r.Allowlist.RegexTarget,
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: r.Allowlist.Commits,
|
||||
StopWords: r.Allowlist.StopWords,
|
||||
},
|
||||
}
|
||||
orderedRules = append(orderedRules, r.RuleID)
|
||||
@@ -148,10 +151,11 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
Extend: vc.Extend,
|
||||
Rules: rulesMap,
|
||||
Allowlist: Allowlist{
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: vc.Allowlist.Commits,
|
||||
StopWords: vc.Allowlist.StopWords,
|
||||
RegexTarget: vc.Allowlist.RegexTarget,
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: vc.Allowlist.Commits,
|
||||
StopWords: vc.Allowlist.StopWords,
|
||||
},
|
||||
Keywords: keywords,
|
||||
orderedRules: orderedRules,
|
||||
|
||||
+53
-9
@@ -16,7 +16,11 @@ paths = [
|
||||
'''gitleaks.toml''',
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket)$''',
|
||||
'''(go.mod|go.sum)$''',
|
||||
'''gradle.lockfile''',
|
||||
'''node_modules''',
|
||||
'''package-lock.json''',
|
||||
'''pnpm-lock.yaml''',
|
||||
'''Database.refactorlog''',
|
||||
'''vendor''',
|
||||
]
|
||||
|
||||
@@ -115,6 +119,15 @@ keywords = [
|
||||
"atlassian","confluence","jira",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Authress Service Client Access Key"
|
||||
id = "authress-service-client-access-key"
|
||||
regex = '''(?i)\b((?:sc|ext|scauth|authress)_[a-z0-9]{5,30}\.[a-z0-9]{4,6}\.acc_[a-z0-9-]{10,32}\.[a-z0-9+/_=-]{30,120})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
secretGroup = 1
|
||||
keywords = [
|
||||
"sc_","ext_","scauth_","authress_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS"
|
||||
id = "aws-access-token"
|
||||
@@ -238,6 +251,15 @@ keywords = [
|
||||
"datadog",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Defined Networking API token"
|
||||
id = "defined-networking-api-token"
|
||||
regex = '''(?i)(?:dnkey)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:=|\|\|:|<=|=>|:)(?:'|\"|\s|=|\x60){0,5}(dnkey-[a-z0-9=_\-]{26}-[a-z0-9=_\-]{52})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
secretGroup = 1
|
||||
keywords = [
|
||||
"dnkey",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "DigitalOcean OAuth Access Token"
|
||||
id = "digitalocean-access-token"
|
||||
@@ -353,7 +375,7 @@ keywords = [
|
||||
[[rules]]
|
||||
description = "EasyPost API token"
|
||||
id = "easypost-api-token"
|
||||
regex = '''EZAK(?i)[a-z0-9]{54}'''
|
||||
regex = '''\bEZAK(?i)[a-z0-9]{54}'''
|
||||
keywords = [
|
||||
"ezak",
|
||||
]
|
||||
@@ -361,7 +383,7 @@ keywords = [
|
||||
[[rules]]
|
||||
description = "EasyPost test API token"
|
||||
id = "easypost-test-api-token"
|
||||
regex = '''EZTK(?i)[a-z0-9]{54}'''
|
||||
regex = '''\bEZTK(?i)[a-z0-9]{54}'''
|
||||
keywords = [
|
||||
"eztk",
|
||||
]
|
||||
@@ -376,7 +398,7 @@ keywords = [
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook"
|
||||
description = "Facebook Access Token"
|
||||
id = "facebook"
|
||||
regex = '''(?i)(?:facebook)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:=|\|\|:|<=|=>|:)(?:'|\"|\s|=|\x60){0,5}([a-f0-9]{32})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
secretGroup = 1
|
||||
@@ -489,9 +511,6 @@ keywords = [
|
||||
"key","api","token","secret","client","passwd","password","auth","access",
|
||||
]
|
||||
[rules.allowlist]
|
||||
paths = [
|
||||
'''Database.refactorlog'''
|
||||
]
|
||||
stopwords= [
|
||||
"client",
|
||||
"endpoint",
|
||||
@@ -1976,6 +1995,14 @@ keywords = [
|
||||
"ghu_","ghs_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitHub Fine-Grained Personal Access Token"
|
||||
id = "github-fine-grained-pat"
|
||||
regex = '''github_pat_[0-9a-zA-Z_]{82}'''
|
||||
keywords = [
|
||||
"github_pat_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitHub OAuth Access Token"
|
||||
id = "github-oauth"
|
||||
@@ -2008,6 +2035,22 @@ keywords = [
|
||||
"glpat-",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitLab Pipeline Trigger Token"
|
||||
id = "gitlab-ptt"
|
||||
regex = '''glptt-[0-9a-f]{40}'''
|
||||
keywords = [
|
||||
"glptt-",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitLab Runner Registration Token"
|
||||
id = "gitlab-rrt"
|
||||
regex = '''GR1348941[0-9a-zA-Z\-\_]{20}'''
|
||||
keywords = [
|
||||
"gr1348941",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Gitter Access Token"
|
||||
id = "gitter-access-token"
|
||||
@@ -2091,7 +2134,7 @@ keywords = [
|
||||
[[rules]]
|
||||
description = "JSON Web Token"
|
||||
id = "jwt"
|
||||
regex = '''(?i)\b(ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
regex = '''(?i)\b(ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200}={0,2})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
keywords = [
|
||||
"ey",
|
||||
]
|
||||
@@ -2403,7 +2446,7 @@ keywords = [
|
||||
[[rules]]
|
||||
description = "Private Key"
|
||||
id = "private-key"
|
||||
regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----'''
|
||||
regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----'''
|
||||
keywords = [
|
||||
"-----begin",
|
||||
]
|
||||
@@ -2590,7 +2633,7 @@ keywords = [
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Stripe"
|
||||
description = "Stripe Access Token"
|
||||
id = "stripe-access-token"
|
||||
regex = '''(?i)(sk|pk)_(test|live)_[0-9a-z]{10,32}'''
|
||||
keywords = [
|
||||
@@ -2756,3 +2799,4 @@ keywords = [
|
||||
"zendesk",
|
||||
]
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func IsNew(finding report.Finding, baseline []report.Finding) bool {
|
||||
// Explicitly testing each property as it gives significantly better performance in comparison to cmp.Equal(). Drawback is that
|
||||
// the code requires maintanance if/when the Finding struct changes
|
||||
// the code requires maintenance if/when the Finding struct changes
|
||||
for _, b := range baseline {
|
||||
|
||||
if finding.Author == b.Author &&
|
||||
|
||||
+52
-10
@@ -57,6 +57,9 @@ type Detector struct {
|
||||
// followSymlinks is a flag to enable scanning symlink files
|
||||
FollowSymlinks bool
|
||||
|
||||
// NoColor is a flag to disable color output
|
||||
NoColor 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
|
||||
@@ -151,7 +154,12 @@ func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
// https://github.com/securego/gosec/issues/512
|
||||
defer func() {
|
||||
if err := file.Close(); err != nil {
|
||||
log.Warn().Msgf("Error closing .gitleaksignore file: %s\n", err)
|
||||
}
|
||||
}()
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
for scanner.Scan() {
|
||||
@@ -160,14 +168,33 @@ func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Detector) AddBaseline(baselinePath string) error {
|
||||
func (d *Detector) AddBaseline(baselinePath string, source string) error {
|
||||
if baselinePath != "" {
|
||||
absoluteSource, err := filepath.Abs(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
absoluteBaseline, err := filepath.Abs(baselinePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
relativeBaseline, err := filepath.Rel(absoluteSource, absoluteBaseline)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
baseline, err := LoadBaseline(baselinePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.baseline = baseline
|
||||
baselinePath = relativeBaseline
|
||||
|
||||
}
|
||||
|
||||
d.baselinePath = baselinePath
|
||||
return nil
|
||||
}
|
||||
@@ -265,12 +292,6 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
||||
continue
|
||||
}
|
||||
|
||||
// check if the secret is in the allowlist
|
||||
if rule.Allowlist.RegexAllowed(finding.Secret) ||
|
||||
d.Config.Allowlist.RegexAllowed(finding.Secret) {
|
||||
continue
|
||||
}
|
||||
|
||||
// extract secret from secret group if set
|
||||
if rule.SecretGroup != 0 {
|
||||
groups := rule.Regex.FindStringSubmatch(secret)
|
||||
@@ -282,6 +303,27 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
||||
finding.Secret = secret
|
||||
}
|
||||
|
||||
// check if the regexTarget is defined in the allowlist "regexes" entry
|
||||
allowlistTarget := finding.Secret
|
||||
switch rule.Allowlist.RegexTarget {
|
||||
case "match":
|
||||
allowlistTarget = finding.Match
|
||||
case "line":
|
||||
allowlistTarget = finding.Line
|
||||
}
|
||||
|
||||
globalAllowlistTarget := finding.Secret
|
||||
switch d.Config.Allowlist.RegexTarget {
|
||||
case "match":
|
||||
globalAllowlistTarget = finding.Match
|
||||
case "line":
|
||||
globalAllowlistTarget = finding.Line
|
||||
}
|
||||
if rule.Allowlist.RegexAllowed(allowlistTarget) ||
|
||||
d.Config.Allowlist.RegexAllowed(globalAllowlistTarget) {
|
||||
continue
|
||||
}
|
||||
|
||||
// check if the secret is in the list of stopwords
|
||||
if rule.Allowlist.ContainsStopWord(finding.Secret) ||
|
||||
d.Config.Allowlist.ContainsStopWord(finding.Secret) {
|
||||
@@ -502,7 +544,7 @@ func (d *Detector) DetectReader(r io.Reader, bufSize int) ([]report.Finding, err
|
||||
for _, finding := range d.Detect(fragment) {
|
||||
findings = append(findings, finding)
|
||||
if d.Verbose {
|
||||
printFinding(finding)
|
||||
printFinding(finding, d.NoColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -576,7 +618,7 @@ func (d *Detector) addFinding(finding report.Finding) {
|
||||
d.findingMutex.Lock()
|
||||
d.findings = append(d.findings, finding)
|
||||
if d.Verbose {
|
||||
printFinding(finding)
|
||||
printFinding(finding, d.NoColor)
|
||||
}
|
||||
d.findingMutex.Unlock()
|
||||
}
|
||||
|
||||
+113
-16
@@ -18,8 +18,14 @@ const repoBasePath = "../testdata/repos/"
|
||||
|
||||
func TestDetect(t *testing.T) {
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
fragment Fragment
|
||||
cfgName string
|
||||
baselinePath string
|
||||
fragment Fragment
|
||||
// NOTE: for expected findings, all line numbers will be 0
|
||||
// because line deltas are added _after_ the finding is created.
|
||||
// I.e., if the finding is from a --no-git file, the line number will be
|
||||
// increase by 1 in DetectFromFiles(). If the finding is from git,
|
||||
// the line number will be increased by the patch delta.
|
||||
expectedFindings []report.Finding
|
||||
wantError error
|
||||
}{
|
||||
@@ -85,8 +91,8 @@ func TestDetect(t *testing.T) {
|
||||
File: "tmp.go",
|
||||
RuleID: "pypi-upload-token",
|
||||
Tags: []string{"key", "pypi"},
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 1,
|
||||
EndColumn: 86,
|
||||
Entropy: 1.9606875,
|
||||
@@ -108,8 +114,8 @@ func TestDetect(t *testing.T) {
|
||||
File: "tmp.go",
|
||||
RuleID: "aws-access-key",
|
||||
Tags: []string{"key", "AWS"},
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 15,
|
||||
EndColumn: 34,
|
||||
Entropy: 3.0841837,
|
||||
@@ -132,8 +138,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "sidekiq-secret",
|
||||
Tags: []string{},
|
||||
Entropy: 2.6098502,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 8,
|
||||
EndColumn: 60,
|
||||
},
|
||||
@@ -155,8 +161,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "sidekiq-secret",
|
||||
Tags: []string{},
|
||||
Entropy: 2.6098502,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 21,
|
||||
EndColumn: 74,
|
||||
},
|
||||
@@ -178,8 +184,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "sidekiq-sensitive-url",
|
||||
Tags: []string{},
|
||||
Entropy: 2.984234,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 8,
|
||||
EndColumn: 58,
|
||||
},
|
||||
@@ -226,8 +232,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "discord-api-key",
|
||||
Tags: []string{},
|
||||
Entropy: 3.7906237,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 7,
|
||||
EndColumn: 93,
|
||||
},
|
||||
@@ -257,8 +263,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "generic-api-key",
|
||||
Tags: []string{},
|
||||
Entropy: 3.7906237,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 22,
|
||||
EndColumn: 93,
|
||||
},
|
||||
@@ -313,6 +319,15 @@ func TestDetect(t *testing.T) {
|
||||
},
|
||||
expectedFindings: []report.Finding{},
|
||||
},
|
||||
{
|
||||
cfgName: "path_only",
|
||||
baselinePath: ".baseline.json",
|
||||
fragment: Fragment{
|
||||
Raw: `const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||
FilePath: ".baseline.json",
|
||||
},
|
||||
expectedFindings: []report.Finding{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -339,6 +354,7 @@ func TestDetect(t *testing.T) {
|
||||
assert.Equal(t, tt.wantError, err)
|
||||
}
|
||||
d := NewDetector(cfg)
|
||||
d.baselinePath = tt.baselinePath
|
||||
|
||||
findings := d.Detect(tt.fragment)
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
@@ -469,6 +485,87 @@ func TestFromGit(t *testing.T) {
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
}
|
||||
}
|
||||
func TestFromGitStaged(t *testing.T) {
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
source string
|
||||
logOpts string
|
||||
expectedFindings []report.Finding
|
||||
}{
|
||||
{
|
||||
source: filepath.Join(repoBasePath, "staged"),
|
||||
cfgName: "simple",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
Description: "AWS Access Key",
|
||||
StartLine: 7,
|
||||
EndLine: 7,
|
||||
StartColumn: 18,
|
||||
EndColumn: 37,
|
||||
Line: "\n\taws_token2 := \"AKIALALEMEL33243OLIA\" // this one is not",
|
||||
Match: "AKIALALEMEL33243OLIA",
|
||||
Secret: "AKIALALEMEL33243OLIA",
|
||||
File: "api/api.go",
|
||||
SymlinkFile: "",
|
||||
Commit: "",
|
||||
Entropy: 3.0841837,
|
||||
Author: "",
|
||||
Email: "",
|
||||
Date: "0001-01-01T00:00:00Z",
|
||||
Message: "",
|
||||
Tags: []string{
|
||||
"key",
|
||||
"AWS",
|
||||
},
|
||||
RuleID: "aws-access-key",
|
||||
Fingerprint: "api/api.go:aws-access-key:7",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
detector.AddGitleaksIgnore(filepath.Join(tt.source, ".gitleaksignore"))
|
||||
findings, err := detector.DetectGit(tt.source, tt.logOpts, ProtectStagedType)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFromFiles tests the FromFiles function
|
||||
func TestFromFiles(t *testing.T) {
|
||||
|
||||
@@ -24,6 +24,16 @@ func location(fragment Fragment, matchIndex []int) Location {
|
||||
// default startLineIndex to 0
|
||||
location.startLineIndex = 0
|
||||
|
||||
// Fixes: https://github.com/zricethezav/gitleaks/issues/1037
|
||||
// When a fragment does NOT have any newlines, a default "newline"
|
||||
// will be counted to make the subsequent location calculation logic work
|
||||
// for fragments will no newlines.
|
||||
if len(fragment.newlineIndices) == 0 {
|
||||
fragment.newlineIndices = [][]int{
|
||||
{len(fragment.Raw), len(fragment.Raw) + 1},
|
||||
}
|
||||
}
|
||||
|
||||
for lineNum, pair := range fragment.newlineIndices {
|
||||
_lineNum = lineNum
|
||||
newLineByteIndex := pair[0]
|
||||
|
||||
+54
-27
@@ -74,7 +74,7 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
|
||||
|
||||
genericMatch := strings.Replace(f.Match, f.Secret, "REDACTED", -1)
|
||||
betterMatch := strings.Replace(fPrime.Match, fPrime.Secret, "REDACTED", -1)
|
||||
log.Trace().Msgf("skipping %s finding (%s), %s rule takes precendence (%s)", f.RuleID, genericMatch, fPrime.RuleID, betterMatch)
|
||||
log.Trace().Msgf("skipping %s finding (%s), %s rule takes precedence (%s)", f.RuleID, genericMatch, fPrime.RuleID, betterMatch)
|
||||
include = false
|
||||
break
|
||||
}
|
||||
@@ -91,44 +91,71 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
|
||||
return retFindings
|
||||
}
|
||||
|
||||
func printFinding(f report.Finding) {
|
||||
// trim all whitespace and tabs from the line
|
||||
func printFinding(f report.Finding, noColor bool) {
|
||||
// trim all whitespace and tabs
|
||||
f.Line = strings.TrimSpace(f.Line)
|
||||
// trim all whitespace and tabs from the secret
|
||||
f.Secret = strings.TrimSpace(f.Secret)
|
||||
// trim all whitespace and tabs from the match
|
||||
f.Match = strings.TrimSpace(f.Match)
|
||||
|
||||
matchInLineIDX := strings.Index(f.Line, f.Match)
|
||||
secretInMatchIdx := strings.Index(f.Match, f.Secret)
|
||||
isFileMatch := strings.HasPrefix(f.Match, "file detected:")
|
||||
skipColor := noColor
|
||||
finding := ""
|
||||
var secret lipgloss.Style
|
||||
|
||||
// Matches from filenames do not have a |line| or |secret|
|
||||
if !isFileMatch {
|
||||
matchInLineIDX := strings.Index(f.Line, f.Match)
|
||||
secretInMatchIdx := strings.Index(f.Match, f.Secret)
|
||||
|
||||
start := f.Line[0:matchInLineIDX]
|
||||
startMatchIdx := 0
|
||||
if matchInLineIDX > 20 {
|
||||
startMatchIdx = matchInLineIDX - 20
|
||||
start = "..." + f.Line[startMatchIdx:matchInLineIDX]
|
||||
}
|
||||
skipColor = false
|
||||
|
||||
matchBeginning := lipgloss.NewStyle().SetString(f.Match[0:secretInMatchIdx]).Foreground(lipgloss.Color("#f5d445"))
|
||||
secret := lipgloss.NewStyle().SetString(f.Secret).
|
||||
Bold(true).
|
||||
Italic(true).
|
||||
Foreground(lipgloss.Color("#f05c07"))
|
||||
matchEnd := lipgloss.NewStyle().SetString(f.Match[secretInMatchIdx+len(f.Secret):]).Foreground(lipgloss.Color("#f5d445"))
|
||||
lineEnd := f.Line[matchInLineIDX+len(f.Match):]
|
||||
if len(f.Secret) > 100 {
|
||||
secret = lipgloss.NewStyle().SetString(f.Secret[0:100] + "...").
|
||||
if matchInLineIDX == -1 || noColor {
|
||||
skipColor = true
|
||||
matchInLineIDX = 0
|
||||
}
|
||||
|
||||
start := f.Line[0:matchInLineIDX]
|
||||
startMatchIdx := 0
|
||||
if matchInLineIDX > 20 {
|
||||
startMatchIdx = matchInLineIDX - 20
|
||||
start = "..." + f.Line[startMatchIdx:matchInLineIDX]
|
||||
}
|
||||
|
||||
matchBeginning := lipgloss.NewStyle().SetString(f.Match[0:secretInMatchIdx]).Foreground(lipgloss.Color("#f5d445"))
|
||||
secret = lipgloss.NewStyle().SetString(f.Secret).
|
||||
Bold(true).
|
||||
Italic(true).
|
||||
Foreground(lipgloss.Color("#f05c07"))
|
||||
matchEnd := lipgloss.NewStyle().SetString(f.Match[secretInMatchIdx+len(f.Secret):]).Foreground(lipgloss.Color("#f5d445"))
|
||||
|
||||
lineEndIdx := matchInLineIDX + len(f.Match)
|
||||
if len(f.Line)-1 <= lineEndIdx {
|
||||
lineEndIdx = len(f.Line) - 1
|
||||
}
|
||||
|
||||
lineEnd := f.Line[lineEndIdx:]
|
||||
|
||||
if len(f.Secret) > 100 {
|
||||
secret = lipgloss.NewStyle().SetString(f.Secret[0:100] + "...").
|
||||
Bold(true).
|
||||
Italic(true).
|
||||
Foreground(lipgloss.Color("#f05c07"))
|
||||
}
|
||||
if len(lineEnd) > 20 {
|
||||
lineEnd = lineEnd[0:20] + "..."
|
||||
}
|
||||
|
||||
finding = fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
|
||||
}
|
||||
if len(lineEnd) > 20 {
|
||||
lineEnd = lineEnd[0:20] + "..."
|
||||
|
||||
if skipColor || isFileMatch {
|
||||
fmt.Printf("%-12s %s\n", "Finding:", f.Match)
|
||||
fmt.Printf("%-12s %s\n", "Secret:", f.Secret)
|
||||
} else {
|
||||
fmt.Printf("%-12s %s", "Finding:", finding)
|
||||
fmt.Printf("%-12s %s\n", "Secret:", secret)
|
||||
}
|
||||
|
||||
finding := fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
|
||||
fmt.Printf("%-12s %s", "Finding:", finding)
|
||||
fmt.Printf("%-12s %s\n", "Secret:", secret)
|
||||
fmt.Printf("%-12s %s\n", "RuleID:", f.RuleID)
|
||||
fmt.Printf("%-12s %f\n", "Entropy:", f.Entropy)
|
||||
if f.File == "" {
|
||||
|
||||
+3
-9
@@ -1,6 +1,7 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -45,42 +46,35 @@ func TestWriteCSV(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
tmpfile, err := os.Create(filepath.Join(tmpPath, test.testReportName+".csv"))
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".csv"))
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
err = writeCsv(test.findings, tmpfile)
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
got, err := os.ReadFile(tmpfile.Name())
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
if test.wantEmpty {
|
||||
if len(got) > 0 {
|
||||
t.Errorf("Expected empty file, got %s", got)
|
||||
}
|
||||
os.Remove(tmpfile.Name())
|
||||
continue
|
||||
}
|
||||
want, err := os.ReadFile(test.expected)
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if string(got) != string(want) {
|
||||
if !bytes.Equal(got, want) {
|
||||
err = os.WriteFile(strings.Replace(test.expected, ".csv", ".got.csv", 1), got, 0644)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Errorf("got %s, want %s", string(got), string(want))
|
||||
}
|
||||
|
||||
os.Remove(tmpfile.Name())
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -38,7 +38,7 @@ type Finding struct {
|
||||
// Rule is the name of the rule that was matched
|
||||
RuleID string
|
||||
|
||||
// unique identifer
|
||||
// unique identifier
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ func writeJson(findings []Finding, w io.WriteCloser) error {
|
||||
if len(findings) == 0 {
|
||||
findings = []Finding{}
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetIndent("", " ")
|
||||
return encoder.Encode(findings)
|
||||
|
||||
+3
-11
@@ -1,6 +1,7 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -46,44 +47,35 @@ func TestWriteJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
// create tmp file using os.TempDir()
|
||||
tmpfile, err := os.Create(filepath.Join(tmpPath, test.testReportName+".json"))
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".json"))
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
err = writeJson(test.findings, tmpfile)
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
got, err := os.ReadFile(tmpfile.Name())
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
if test.wantEmpty {
|
||||
if len(got) > 0 {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Errorf("Expected empty file, got %s", got)
|
||||
}
|
||||
os.Remove(tmpfile.Name())
|
||||
continue
|
||||
}
|
||||
want, err := os.ReadFile(test.expected)
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if string(got) != string(want) {
|
||||
if !bytes.Equal(got, want) {
|
||||
err = os.WriteFile(strings.Replace(test.expected, ".json", ".got.json", 1), got, 0644)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Errorf("got %s, want %s", string(got), string(want))
|
||||
}
|
||||
|
||||
os.Remove(tmpfile.Name())
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
const (
|
||||
expectPath = "../testdata/expected/"
|
||||
tmpPath = "../testdata/tmp"
|
||||
)
|
||||
|
||||
func TestReport(t *testing.T) {
|
||||
@@ -80,22 +79,18 @@ func TestReport(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
tmpfile, err := os.Create(filepath.Join(tmpPath, strconv.Itoa(i)+test.ext))
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), strconv.Itoa(i)+test.ext))
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
err = Write(test.findings, config.Config{}, test.ext, tmpfile.Name())
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
got, err := os.ReadFile(tmpfile.Name())
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
os.Remove(tmpfile.Name())
|
||||
|
||||
if len(got) == 0 && !test.wantEmpty {
|
||||
t.Errorf("got empty file with extension " + test.ext)
|
||||
|
||||
+4
-1
@@ -10,10 +10,11 @@ import (
|
||||
|
||||
func writeSarif(cfg config.Config, findings []Finding, w io.WriteCloser) error {
|
||||
sarif := Sarif{
|
||||
Schema: "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
||||
Schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
||||
Version: "2.1.0",
|
||||
Runs: getRuns(cfg, findings),
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetIndent("", " ")
|
||||
@@ -34,6 +35,7 @@ func getTool(cfg config.Config) Tool {
|
||||
Driver: Driver{
|
||||
Name: driver,
|
||||
SemanticVersion: version,
|
||||
InformationUri: "https://github.com/gitleaks/gitleaks",
|
||||
Rules: getRules(cfg),
|
||||
},
|
||||
}
|
||||
@@ -164,6 +166,7 @@ type Rules struct {
|
||||
type Driver struct {
|
||||
Name string `json:"name"`
|
||||
SemanticVersion string `json:"semanticVersion"`
|
||||
InformationUri string `json:"informationUri"`
|
||||
Rules []Rules `json:"rules"`
|
||||
}
|
||||
|
||||
|
||||
+3
-10
@@ -1,6 +1,7 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -48,10 +49,8 @@ func TestWriteSarif(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
// create tmp file using os.TempDir()
|
||||
tmpfile, err := os.Create(filepath.Join(tmpPath, test.testReportName+".json"))
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".json"))
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
viper.Reset()
|
||||
@@ -76,29 +75,24 @@ func TestWriteSarif(t *testing.T) {
|
||||
err = writeSarif(cfg, test.findings, tmpfile)
|
||||
fmt.Println(cfg)
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
got, err := os.ReadFile(tmpfile.Name())
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
if test.wantEmpty {
|
||||
if len(got) > 0 {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Errorf("Expected empty file, got %s", got)
|
||||
}
|
||||
os.Remove(tmpfile.Name())
|
||||
continue
|
||||
}
|
||||
want, err := os.ReadFile(test.expected)
|
||||
if err != nil {
|
||||
os.Remove(tmpfile.Name())
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if string(got) != string(want) {
|
||||
if !bytes.Equal(got, want) {
|
||||
err = os.WriteFile(strings.Replace(test.expected, ".sarif", ".got.sarif", 1), got, 0644)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -106,6 +100,5 @@ func TestWriteSarif(t *testing.T) {
|
||||
t.Errorf("got %s, want %s", string(got), string(want))
|
||||
}
|
||||
|
||||
os.Remove(tmpfile.Name())
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
||||
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
|
||||
"version": "2.1.0",
|
||||
"runs": [
|
||||
]
|
||||
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
||||
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
|
||||
"version": "2.1.0",
|
||||
"runs": [
|
||||
{
|
||||
@@ -7,6 +7,7 @@
|
||||
"driver": {
|
||||
"name": "gitleaks",
|
||||
"semanticVersion": "v8.0.0",
|
||||
"informationUri": "https://github.com/gitleaks/gitleaks",
|
||||
"rules": [
|
||||
{
|
||||
"id": "aws-access-key",
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
api/api.go:aws-access-key:6
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
# test
|
||||
This is a repo used for testing gitleaks
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
package api
|
||||
|
||||
import "fmt"
|
||||
|
||||
func PrintHello() {
|
||||
aws_token := "AKIALALEMEL33243OLIA" // fingerprint of that secret is added to .gitleaksignore
|
||||
aws_token2 := "AKIALALEMEL33243OLIA" // this one is not
|
||||
fmt.Println(aws_token)
|
||||
fmt.Println(aws_token2)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
add .gitleaksignore file
|
||||
+1
@@ -0,0 +1 @@
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e branch 'main' of github.com:gitleaks/test
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
ref: refs/heads/main
|
||||
+1
@@ -0,0 +1 @@
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
[remote "origin"]
|
||||
url = git@github.com:gitleaks/test.git
|
||||
fetch = +refs/heads/*:refs/remotes/origin/*
|
||||
[branch "main"]
|
||||
remote = origin
|
||||
merge = refs/heads/main
|
||||
+1
@@ -0,0 +1 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
||||
Vendored
BIN
Binary file not shown.
+6
@@ -0,0 +1,6 @@
|
||||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
0000000000000000000000000000000000000000 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896329 -0500 clone: from github.com:gitleaks/test.git
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896362 -0500 checkout: moving from main to remove-secrets
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 906335481df9a4b48906c90318b4fac76b67fe73 Zach Rice <zricer@protonmail.com> 1635896426 -0500 commit: load token via env var
|
||||
906335481df9a4b48906c90318b4fac76b67fe73 a122b33c6bad3ee54724f52f2caad385ab1982ab Zach Rice <zricer@protonmail.com> 1635896518 -0500 commit: add api package
|
||||
a122b33c6bad3ee54724f52f2caad385ab1982ab a122b33c6bad3ee54724f52f2caad385ab1982ab Zach Rice <zricer@protonmail.com> 1635896543 -0500 checkout: moving from remove-secrets to api-pkg
|
||||
a122b33c6bad3ee54724f52f2caad385ab1982ab 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896644 -0500 checkout: moving from api-pkg to main
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635896648 -0500 pull origin main: Fast-forward
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635896716 -0500 checkout: moving from main to foo
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e 491504d5a31946ce75e22554cc34203d8e5ff3ca Zach Rice <zricer@protonmail.com> 1635896886 -0500 commit: adding foo package with secret
|
||||
491504d5a31946ce75e22554cc34203d8e5ff3ca f1b58b97808f8e744f6a23c693859df5b5968901 Zach Rice <zricer@protonmail.com> 1635896931 -0500 commit: removing secret from foo package
|
||||
f1b58b97808f8e744f6a23c693859df5b5968901 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635897009 -0500 checkout: moving from foo to main
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e f1b58b97808f8e744f6a23c693859df5b5968901 Zach Rice <zricer@protonmail.com> 1635897062 -0500 checkout: moving from main to foo
|
||||
f1b58b97808f8e744f6a23c693859df5b5968901 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635897508 -0500 checkout: moving from foo to main
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e bf3f24164d7256b4021575cbdb2f97b98e6f057e Rafael Figueiredo <rfigueiredo@garoa.cloud> 1679239434 -0300 commit: add .gitleaksignore file
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 a122b33c6bad3ee54724f52f2caad385ab1982ab Zach Rice <zricer@protonmail.com> 1635896543 -0500 branch: Created from HEAD
|
||||
@@ -0,0 +1,3 @@
|
||||
0000000000000000000000000000000000000000 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635896716 -0500 branch: Created from HEAD
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e 491504d5a31946ce75e22554cc34203d8e5ff3ca Zach Rice <zricer@protonmail.com> 1635896886 -0500 commit: adding foo package with secret
|
||||
491504d5a31946ce75e22554cc34203d8e5ff3ca f1b58b97808f8e744f6a23c693859df5b5968901 Zach Rice <zricer@protonmail.com> 1635896931 -0500 commit: removing secret from foo package
|
||||
@@ -0,0 +1,3 @@
|
||||
0000000000000000000000000000000000000000 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896329 -0500 clone: from github.com:gitleaks/test.git
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635896648 -0500 pull origin main: Fast-forward
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e bf3f24164d7256b4021575cbdb2f97b98e6f057e Rafael Figueiredo <rfigueiredo@garoa.cloud> 1679239434 -0300 commit: add .gitleaksignore file
|
||||
@@ -0,0 +1,3 @@
|
||||
0000000000000000000000000000000000000000 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896362 -0500 branch: Created from HEAD
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 906335481df9a4b48906c90318b4fac76b67fe73 Zach Rice <zricer@protonmail.com> 1635896426 -0500 commit: load token via env var
|
||||
906335481df9a4b48906c90318b4fac76b67fe73 a122b33c6bad3ee54724f52f2caad385ab1982ab Zach Rice <zricer@protonmail.com> 1635896518 -0500 commit: add api package
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896329 -0500 clone: from github.com:gitleaks/test.git
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 a122b33c6bad3ee54724f52f2caad385ab1982ab Zach Rice <zricer@protonmail.com> 1635896552 -0500 update by push
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 f1b58b97808f8e744f6a23c693859df5b5968901 Zach Rice <zricer@protonmail.com> 1635896935 -0500 update by push
|
||||
@@ -0,0 +1 @@
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635896648 -0500 pull origin main: fast-forward
|
||||
+1
@@ -0,0 +1 @@
|
||||
xUÌ1Â0`×ܯ8nJ––.‚ƒƒ:*(8–´\¤´É•$ê þw3 Noxï{Ý$6Ëf1Û~´wF'0øYbF␍ŠœÏTB�p�ÐãND|ƒ*]uŽCÈSÐT •…ªkLÌ>a²Ž#(ûJm–‘®Ö(©ÚsæðÔ´¹]Úëé°=õ÷ô>ð°ú03
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+3
@@ -0,0 +1,3 @@
|
||||
xťŽM
|
||||
Â0F]çs%™üt
|
||||
"žÁĄ»I2ˇEŰ”»đôö®>xĽ_ŞË2w@;śză‘�ءCŚXЧ@‘˛Ö65Ź)–ÔĆMÖ&†ĚÎF:l'ĚFÇTHÄŹFFĂ1–äiPüéSmđä4ÁcN×o;¦Ý·V{]žß—T—�`=ŤÁa€łöZ«�»ü«w彾d…}f�u‡ť›úKKś
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+2
@@ -0,0 +1,2 @@
|
||||
x¥ŽAn!sæó�X³ÀÎɲ|Êòƒš5ÊÚX˜ý¬ò[ª*uj·[dçð1:@"1-œ9q,1Š—ct%preB(6ç¨l£wæ¡÷—ˆ)G¿X êì
|
||||
KòlEág¼P's8Âè>®Ó·ÅF_uÝQ;r£S/ÿã²jozH[Ûó™&Y‚uÁ;OŸì˜Mú;;ðfÆhÎtXëØ ?ϺÞ[•ºÁü_]U
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
+2
@@ -0,0 +1,2 @@
|
||||
# pack-refs with: peeled fully-peeled sorted
|
||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 refs/remotes/origin/main
|
||||
@@ -0,0 +1 @@
|
||||
a122b33c6bad3ee54724f52f2caad385ab1982ab
|
||||
+1
@@ -0,0 +1 @@
|
||||
f1b58b97808f8e744f6a23c693859df5b5968901
|
||||
@@ -0,0 +1 @@
|
||||
bf3f24164d7256b4021575cbdb2f97b98e6f057e
|
||||
@@ -0,0 +1 @@
|
||||
a122b33c6bad3ee54724f52f2caad385ab1982ab
|
||||
@@ -0,0 +1 @@
|
||||
ref: refs/remotes/origin/main
|
||||
@@ -0,0 +1 @@
|
||||
a122b33c6bad3ee54724f52f2caad385ab1982ab
|
||||
@@ -0,0 +1 @@
|
||||
f1b58b97808f8e744f6a23c693859df5b5968901
|
||||
@@ -0,0 +1 @@
|
||||
2e1db472eeba53f06c4026ae4566ea022e36598e
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var a = "initial"
|
||||
fmt.Println(a)
|
||||
|
||||
var b, c int = 1, 2
|
||||
fmt.Println(b, c)
|
||||
|
||||
var d = true
|
||||
fmt.Println(d)
|
||||
|
||||
var e int
|
||||
fmt.Println(e)
|
||||
|
||||
// load secret via env
|
||||
awsToken := os.Getenv("AWS_TOKEN")
|
||||
|
||||
f := "apple"
|
||||
fmt.Println(f)
|
||||
}
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
nothing should be saved here
|
||||
Reference in new issue
Block a user