mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-27 19:54:24 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2afd56bbe | ||
|
|
818e32f7a4 | ||
|
|
3fa5a3a954 | ||
|
|
2020e6a9ab | ||
|
|
9122a2d359 | ||
|
|
398d0c46dd | ||
|
|
ae26eff464 | ||
|
|
c6424a6fc3 | ||
|
|
6411402d43 | ||
|
|
d71d95d65e | ||
|
|
3188ad6005 | ||
|
|
7fc11bb264 | ||
|
|
36c52c6b73 | ||
|
|
1f323d8b69 | ||
|
|
d88bc094f7 | ||
|
|
3fdaefdaa3 | ||
|
|
f3ae52e138 | ||
|
|
d6a828a530 | ||
|
|
d2ffffecbd | ||
|
|
a43dc0d3d0 | ||
|
|
69ed20e25e | ||
|
|
52b895a603 | ||
|
|
3f4d91fc22 | ||
|
|
049f5b2435 | ||
|
|
7a6183dab0 | ||
|
|
3c7f3f0e08 | ||
|
|
0e3f4f7abb | ||
|
|
3ed85671a4 | ||
|
|
e977850ab4 | ||
|
|
ad7a4fb4ea | ||
|
|
b2cf03c7e3 | ||
|
|
a3f623cc69 | ||
|
|
cc71bb1e9a |
No files matched your search
@@ -4,6 +4,7 @@ jobs:
|
||||
scan:
|
||||
name: gitleaks
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.repository == 'gitleaks/gitleaks' }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
|
||||
@@ -10,20 +10,28 @@ on:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
platform: [ ubuntu-latest, windows-latest ]
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.22
|
||||
go-version: 1.23
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Set up gotestsum
|
||||
run: |
|
||||
go install gotest.tools/gotestsum@latest
|
||||
|
||||
- name: Test
|
||||
run: make test
|
||||
run: |
|
||||
gotestsum --raw-command -- go test -json ./... --race
|
||||
|
||||
- name: Validate Config
|
||||
run: go generate ./... && git diff --exit-code
|
||||
@@ -102,7 +102,7 @@ jobs:
|
||||
```
|
||||
repos:
|
||||
- repo: https://github.com/gitleaks/gitleaks
|
||||
rev: v8.19.0
|
||||
rev: v8.23.1
|
||||
hooks:
|
||||
- id: gitleaks
|
||||
```
|
||||
@@ -218,23 +218,35 @@ Gitleaks offers a configuration format you can follow to write your own secret d
|
||||
|
||||
```toml
|
||||
# Title for the gitleaks configuration file.
|
||||
title = "Gitleaks title"
|
||||
title = "Custom Gitleaks configuration"
|
||||
|
||||
# You have basically two options for your custom configuration:
|
||||
#
|
||||
# 1. define your own configuration, default rules do not apply
|
||||
#
|
||||
# use e.g., the default configuration as starting point:
|
||||
# https://github.com/gitleaks/gitleaks/blob/master/config/gitleaks.toml
|
||||
#
|
||||
# 2. extend a configuration, the rules are overwritten or extended
|
||||
#
|
||||
# When you extend a configuration the extended rules take precedence over the
|
||||
# default rules. I.e., if there are duplicate rules in both the extended
|
||||
# configuration and the default configuration the extended rules or
|
||||
# attributes of them will override the default rules.
|
||||
# Another thing to know with extending configurations is you can chain
|
||||
# together multiple configuration files to a depth of 2. Allowlist arrays are
|
||||
# appended and can contain duplicates.
|
||||
|
||||
# Extend the base (this) configuration. When you extend a configuration
|
||||
# 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
|
||||
# multiple configuration files to a depth of 2. Allowlist arrays are appended
|
||||
# and can contain duplicates.
|
||||
# useDefault and path can NOT be used at the same time. Choose one.
|
||||
[extend]
|
||||
# useDefault will extend the base configuration with the default gitleaks config:
|
||||
# useDefault will extend the default gitleaks config built in to the binary
|
||||
# the latest version is located at:
|
||||
# https://github.com/gitleaks/gitleaks/blob/master/config/gitleaks.toml
|
||||
useDefault = true
|
||||
# or you can supply a path to a configuration. Path is relative to where gitleaks
|
||||
# was invoked, not the location of the base config.
|
||||
path = "common_config.toml"
|
||||
# or you can provide a path to a configuration to extend from.
|
||||
# The path is relative to where gitleaks was invoked,
|
||||
# not the location of the base config.
|
||||
# path = "common_config.toml"
|
||||
# If there are any rules you don't want to inherit, they can be specified here.
|
||||
disabledRules = [ "generic-api-key"]
|
||||
|
||||
|
||||
+32
-47
@@ -24,6 +24,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/scm"
|
||||
"github.com/zricethezav/gitleaks/v8/detect"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
"github.com/zricethezav/gitleaks/v8/sources"
|
||||
@@ -36,6 +38,7 @@ func init() {
|
||||
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
|
||||
detectCmd.Flags().StringP("source", "s", ".", "path to source")
|
||||
detectCmd.Flags().String("log-opts", "", "git log options")
|
||||
detectCmd.Flags().String("platform", "", "the target platform used to generate links (github, gitlab)")
|
||||
}
|
||||
|
||||
var detectCmd = &cobra.Command{
|
||||
@@ -46,84 +49,66 @@ var detectCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func runDetect(cmd *cobra.Command, args []string) {
|
||||
source, err := cmd.Flags().GetString("source")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not get source")
|
||||
}
|
||||
initConfig(source)
|
||||
|
||||
var findings []report.Finding
|
||||
|
||||
// setup config (aka, the thing that defines rules)
|
||||
cfg := Config(cmd)
|
||||
|
||||
// start timer
|
||||
start := time.Now()
|
||||
source := mustGetStringFlag(cmd, "source")
|
||||
|
||||
// setup config (aka, the thing that defines rules)
|
||||
initConfig(source)
|
||||
cfg := Config(cmd)
|
||||
|
||||
// create detector
|
||||
detector := Detector(cmd, cfg, source)
|
||||
|
||||
// set follow symlinks flag
|
||||
if detector.FollowSymlinks, err = cmd.Flags().GetBool("follow-symlinks"); err != nil {
|
||||
logging.Fatal().Err(err).Msg("")
|
||||
}
|
||||
// set exit code
|
||||
exitCode, err := cmd.Flags().GetInt("exit-code")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not get exit code")
|
||||
}
|
||||
// parse flags
|
||||
detector.FollowSymlinks = mustGetBoolFlag(cmd, "follow-symlinks")
|
||||
exitCode := mustGetIntFlag(cmd, "exit-code")
|
||||
noGit := mustGetBoolFlag(cmd, "no-git")
|
||||
fromPipe := mustGetBoolFlag(cmd, "pipe")
|
||||
|
||||
// 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 {
|
||||
logging.Fatal().Err(err).Msg("could not call GetBool() for no-git")
|
||||
}
|
||||
fromPipe, err := cmd.Flags().GetBool("pipe")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not call GetBool() for pipe")
|
||||
}
|
||||
|
||||
// start the detector scan
|
||||
var (
|
||||
findings []report.Finding
|
||||
err error
|
||||
)
|
||||
if noGit {
|
||||
var paths <-chan sources.ScanTarget
|
||||
paths, err = sources.DirectoryTargets(
|
||||
paths, err := sources.DirectoryTargets(
|
||||
source,
|
||||
detector.Sema,
|
||||
detector.FollowSymlinks,
|
||||
detector.Config.Allowlist.PathAllowed,
|
||||
)
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err)
|
||||
logging.Fatal().Err(err).Send()
|
||||
}
|
||||
|
||||
findings, err = detector.DetectFiles(paths)
|
||||
if err != nil {
|
||||
if findings, err = detector.DetectFiles(paths); err != nil {
|
||||
// don't exit on error, just log it
|
||||
logging.Error().Err(err).Msg("failed scan directory")
|
||||
}
|
||||
} else if fromPipe {
|
||||
findings, err = detector.DetectReader(os.Stdin, 10)
|
||||
if err != nil {
|
||||
if findings, err = detector.DetectReader(os.Stdin, 10); err != nil {
|
||||
// log fatal to exit, no need to continue since a report
|
||||
// will not be generated when scanning from a pipe...for now
|
||||
logging.Fatal().Err(err).Msg("failed scan input from stdin")
|
||||
}
|
||||
} else {
|
||||
var (
|
||||
gitCmd *sources.GitCmd
|
||||
logOpts string
|
||||
logOpts = mustGetStringFlag(cmd, "log-opts")
|
||||
gitCmd *sources.GitCmd
|
||||
scmPlatform scm.Platform
|
||||
remote = detect.NewRemoteInfo(scmPlatform, source)
|
||||
)
|
||||
logOpts, err = cmd.Flags().GetString("log-opts")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not call GetString() for log-opts")
|
||||
}
|
||||
gitCmd, err = sources.NewGitLogCmd(source, logOpts)
|
||||
if err != nil {
|
||||
if gitCmd, err = sources.NewGitLogCmd(source, logOpts); err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not create Git cmd")
|
||||
}
|
||||
findings, err = detector.DetectGit(gitCmd)
|
||||
if err != nil {
|
||||
if scmPlatform, err = scm.PlatformFromString(mustGetStringFlag(cmd, "platform")); err != nil {
|
||||
logging.Fatal().Err(err).Send()
|
||||
}
|
||||
|
||||
if findings, err = detector.DetectGit(gitCmd, remote); err != nil {
|
||||
// don't exit on error, just log it
|
||||
logging.Error().Err(err).Msg("failed to scan Git repository")
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func CreateGlobalConfig() config.Config {
|
||||
@@ -33,9 +33,9 @@ func CreateGlobalConfig() config.Config {
|
||||
}(),
|
||||
|
||||
// ----------- Environment Variables -----------
|
||||
regexp.MustCompile(`^\$(\d+|{\d+})$`),
|
||||
regexp.MustCompile(`^\$([A-Z_]+|[a-z_]+)$`),
|
||||
regexp.MustCompile(`^\${([A-Z_]+|[a-z_]+)}$`),
|
||||
regexp.MustCompile(`^\$(?:\d+|{\d+})$`),
|
||||
regexp.MustCompile(`^\$(?:[A-Z_]+|[a-z_]+)$`),
|
||||
regexp.MustCompile(`^\${(?:[A-Z_]+|[a-z_]+)}$`),
|
||||
|
||||
// ----------- Interpolated Variables -----------
|
||||
// Ansible (https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html)
|
||||
@@ -43,64 +43,71 @@ func CreateGlobalConfig() config.Config {
|
||||
// GitHub Actions
|
||||
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables
|
||||
// https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions
|
||||
regexp.MustCompile(`^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$`),
|
||||
regexp.MustCompile(`^\$\{\{[ \t]*(?:(?:env|github|secrets|vars)(?:\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$`),
|
||||
// NuGet (https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables)
|
||||
regexp.MustCompile(`^%([A-Z_]+|[a-z_]+)%$`),
|
||||
regexp.MustCompile(`^%(?:[A-Z_]+|[a-z_]+)%$`),
|
||||
// String formatting.
|
||||
regexp.MustCompile(`^%[+\-# 0]?[bcdeEfFgGoOpqstTUvxX]$`), // Golang (https://pkg.go.dev/fmt)
|
||||
regexp.MustCompile(`^\{\d{0,2}}$`), // Python (https://docs.python.org/3/tutorial/inputoutput.html)
|
||||
// Urban Code Deploy (https://www.ibm.com/support/pages/replace-token-step-replaces-replacement-values-windows-variables)
|
||||
regexp.MustCompile(`^@([A-Z_]+|[a-z_]+)@$`),
|
||||
regexp.MustCompile(`^@(?:[A-Z_]+|[a-z_]+)@$`),
|
||||
|
||||
// ----------- Miscellaneous -----------
|
||||
// File paths
|
||||
regexp.MustCompile(`^/Users/(?i)[a-z0-9]+/[\w .-/]+$`), // MacOS
|
||||
regexp.MustCompile(`^/(?:bin|etc|home|opt|tmp|usr|var)/[\w ./-]+$`), // Linux
|
||||
// 11980 Jps -Dapplication.home=D:\develop_tools\jdk\jdk1.8.0_131 -Xms8m
|
||||
//regexp.MustCompile(`^$`), // Windows
|
||||
},
|
||||
Paths: []*regexp.Regexp{
|
||||
regexp.MustCompile(`gitleaks\.toml`),
|
||||
|
||||
// ----------- Documents and media -----------
|
||||
regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`), // Images
|
||||
regexp.MustCompile(`\.(eot|[ot]tf|woff2?)$`), // Fonts
|
||||
regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`),
|
||||
regexp.MustCompile(`(?i)\.(?:bmp|gif|jpe?g|png|svg|tiff?)$`), // Images
|
||||
regexp.MustCompile(`(?i)\.(?:eot|[ot]tf|woff2?)$`), // Fonts
|
||||
regexp.MustCompile(`(?i)\.(?:docx?|xlsx?|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf|zip)$`),
|
||||
|
||||
// ----------- Golang files -----------
|
||||
regexp.MustCompile(`go\.(mod|sum|work(\.sum)?)$`),
|
||||
regexp.MustCompile(`(^|/)vendor/modules\.txt$`),
|
||||
regexp.MustCompile(`(^|/)vendor/(github\.com|golang\.org/x|google\.golang\.org|gopkg\.in|istio\.io|k8s\.io|sigs\.k8s\.io)(/.*)?$`),
|
||||
regexp.MustCompile(`go\.(?:mod|sum|work(?:\.sum)?)$`),
|
||||
regexp.MustCompile(`(?:^|/)vendor/modules\.txt$`),
|
||||
regexp.MustCompile(`(?:^|/)vendor/(?:github\.com|golang\.org/x|google\.golang\.org|gopkg\.in|istio\.io|k8s\.io|sigs\.k8s\.io)(?:/.*)?$`),
|
||||
|
||||
// ----------- Java files -----------
|
||||
// Gradle
|
||||
regexp.MustCompile(`(^|/)gradlew(\.bat)?$`),
|
||||
regexp.MustCompile(`(^|/)gradle\.lockfile$`),
|
||||
regexp.MustCompile(`(^|/)mvnw(\.cmd)?$`),
|
||||
regexp.MustCompile(`(^|/)\.mvn/wrapper/MavenWrapperDownloader\.java$`),
|
||||
regexp.MustCompile(`(?:^|/)gradlew(?:\.bat)?$`),
|
||||
regexp.MustCompile(`(?:^|/)gradle\.lockfile$`),
|
||||
regexp.MustCompile(`(?:^|/)mvnw(?:\.cmd)?$`),
|
||||
regexp.MustCompile(`(?:^|/)\.mvn/wrapper/MavenWrapperDownloader\.java$`),
|
||||
|
||||
// ----------- JavaScript files -----------
|
||||
// Dependencies and lock files.
|
||||
regexp.MustCompile(`(^|/)node_modules(/.*)?$`),
|
||||
regexp.MustCompile(`(^|/)(npm-shrinkwrap\.json|package-lock\.json|pnpm-lock\.yaml|yarn\.lock)$`),
|
||||
regexp.MustCompile(`(^|/)bower_components(/.*)?$`),
|
||||
regexp.MustCompile(`(?:^|/)node_modules(?:/.*)?$`),
|
||||
regexp.MustCompile(`(?:^|/)(?:deno\.lock|npm-shrinkwrap\.json|package-lock\.json|pnpm-lock\.yaml|yarn\.lock)$`),
|
||||
regexp.MustCompile(`(?:^|/)bower_components(?:/.*)?$`),
|
||||
// TODO: Add more common static assets, such as swagger-ui.
|
||||
regexp.MustCompile(`(^|/)(angular|jquery(-?ui)?|plotly|swagger-?ui)[a-zA-Z0-9.-]*(\.min)?\.js(\.map)?$`),
|
||||
regexp.MustCompile(`(?:^|/)(?:angular|bootstrap|jquery(?:-?ui)?|plotly|swagger-?ui)[a-zA-Z0-9.-]*(?:\.min)?\.js(?:\.map)?$`),
|
||||
regexp.MustCompile(`(?:^|/)javascript\.json$`),
|
||||
|
||||
// ----------- Python files -----------
|
||||
// Dependencies and lock files.
|
||||
regexp.MustCompile(`(^|/)(Pipfile|poetry)\.lock$`),
|
||||
regexp.MustCompile(`(?:^|/)(?:Pipfile|poetry)\.lock$`),
|
||||
// Virtual environments
|
||||
regexp.MustCompile(`(?i)/?(v?env|virtualenv)/lib(64)?(/.*)?$`),
|
||||
regexp.MustCompile(`(?i)(^|/)(lib(64)?/python[23](\.\d{1,2})+|python/[23](\.\d{1,2})+/lib(64)?)(/.*)?$`),
|
||||
regexp.MustCompile(`(?i)(?:^|/)(?:v?env|virtualenv)/lib(?:64)?(?:/.*)?$`),
|
||||
regexp.MustCompile(`(?i)(?:^|/)(?:lib(?:64)?/python[23](?:\.\d{1,2})+|python/[23](?:\.\d{1,2})+/lib(?:64)?)(?:/.*)?$`),
|
||||
// dist-info directory (https://py-pkgs.org/04-package-structure.html#building-sdists-and-wheels)
|
||||
regexp.MustCompile(`(?i)(^|/)[a-z0-9_.]+-[0-9.]+\.dist-info(/.+)?$`),
|
||||
regexp.MustCompile(`(?i)(?:^|/)[a-z0-9_.]+-[0-9.]+\.dist-info(?:/.+)?$`),
|
||||
|
||||
// ----------- Ruby files -----------
|
||||
regexp.MustCompile(`(^|/)vendor/(bundle|ruby)(/.*?)?$`),
|
||||
regexp.MustCompile(`(?:^|/)vendor/(?:bundle|ruby)(?:/.*?)?$`),
|
||||
regexp.MustCompile(`\.gem$`), // tar archive
|
||||
|
||||
// Misc
|
||||
regexp.MustCompile(`verification-metadata\.xml`),
|
||||
regexp.MustCompile(`Database.refactorlog`),
|
||||
//regexp.MustCompile(`vendor`),
|
||||
// regexp.MustCompile(`vendor`),
|
||||
},
|
||||
StopWords: []string{
|
||||
"abcdefghijklmnopqrstuvwxyz", // character range
|
||||
// ----------- Secrets -----------
|
||||
// Checkmarx client secret. (https://github.com/checkmarx-ts/checkmarx-python-sdk/blob/86560f6e2a3e46d16322101294da10d5d190312d/README.md?plain=1#L56)
|
||||
"014df517-39d1-4453-b7b3-9930c563627c",
|
||||
|
||||
@@ -4,70 +4,79 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfigAllowlistRegexes(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
invalid []string
|
||||
valid []string
|
||||
}{
|
||||
"general placeholders": {
|
||||
invalid: []string{
|
||||
`true`, `True`, `false`, `False`, `null`, `NULL`,
|
||||
},
|
||||
var allowlistRegexTests = map[string]struct {
|
||||
invalid []string
|
||||
valid []string
|
||||
}{
|
||||
"general placeholders": {
|
||||
invalid: []string{
|
||||
`true`, `True`, `false`, `False`, `null`, `NULL`,
|
||||
},
|
||||
"general placeholders - repeated characters": {
|
||||
invalid: []string{
|
||||
`aaaaaaaaaaaaaaaaa`, `BBBBBBBBBBbBBBBBBBbBB`, `********************`,
|
||||
},
|
||||
valid: []string{`aaaaaaaaaaaaaaaaaaabaa`, `pas*************d`},
|
||||
},
|
||||
"general placeholders - repeated characters": {
|
||||
invalid: []string{
|
||||
`aaaaaaaaaaaaaaaaa`, `BBBBBBBBBBbBBBBBBBbBB`, `********************`,
|
||||
},
|
||||
"environment variables": {
|
||||
invalid: []string{`$2`, `$GIT_PASSWORD`, `${GIT_PASSWORD}`, `$password`},
|
||||
valid: []string{`$yP@R.@=ibxI`, `$2a6WCust9aE`, `${not_complete1`},
|
||||
valid: []string{`aaaaaaaaaaaaaaaaaaabaa`, `pas*************d`},
|
||||
},
|
||||
"environment variables": {
|
||||
invalid: []string{`$2`, `$GIT_PASSWORD`, `${GIT_PASSWORD}`, `$password`},
|
||||
valid: []string{`$yP@R.@=ibxI`, `$2a6WCust9aE`, `${not_complete1`},
|
||||
},
|
||||
"interpolated variables - ansible": {
|
||||
invalid: []string{
|
||||
`{{ x }}`, `{{ password }}`, `{{password}}`, `{{ data.proxy_password }}`,
|
||||
`{{ dict1 | ansible.builtin.combine(dict2) }}`,
|
||||
},
|
||||
"interpolated variables - ansible": {
|
||||
invalid: []string{
|
||||
`{{ x }}`, `{{ password }}`, `{{password}}`, `{{ data.proxy_password }}`,
|
||||
`{{ dict1 | ansible.builtin.combine(dict2) }}`,
|
||||
},
|
||||
},
|
||||
"interpolated variables - github actions": {
|
||||
invalid: []string{
|
||||
`${{ env.First_Name }}`,
|
||||
`${{ env.DAY_OF_WEEK == 'Monday' }}`,
|
||||
`${{env.JAVA_VERSION}}`,
|
||||
`${{ github.event.issue.title }}`,
|
||||
`${{ github.repository == "Gattocrucco/lsqfitgp" }}`,
|
||||
`${{ github.event.pull_request.number || github.ref }}`,
|
||||
`${{ github.event_name == 'pull_request' && github.event.action == 'unassigned' }}`,
|
||||
`${{ secrets.SuperSecret }}`,
|
||||
`${{ vars.JOB_NAME }}`,
|
||||
`${{ vars.USE_VARIABLES == 'true' }}`,
|
||||
},
|
||||
"interpolated variables - github actions": {
|
||||
invalid: []string{
|
||||
`${{ env.First_Name }}`,
|
||||
`${{ env.DAY_OF_WEEK == 'Monday' }}`,
|
||||
`${{env.JAVA_VERSION}}`,
|
||||
`${{ github.event.issue.title }}`,
|
||||
`${{ github.repository == "Gattocrucco/lsqfitgp" }}`,
|
||||
`${{ github.event.pull_request.number || github.ref }}`,
|
||||
`${{ github.event_name == 'pull_request' && github.event.action == 'unassigned' }}`,
|
||||
`${{ secrets.SuperSecret }}`,
|
||||
`${{ vars.JOB_NAME }}`,
|
||||
`${{ vars.USE_VARIABLES == 'true' }}`,
|
||||
},
|
||||
},
|
||||
"interpolated variables - nuget": {
|
||||
invalid: []string{
|
||||
`%MY_PASSWORD%`, `%password%`,
|
||||
},
|
||||
"interpolated variables - nuget": {
|
||||
invalid: []string{
|
||||
`%MY_PASSWORD%`, `%password%`,
|
||||
},
|
||||
},
|
||||
"interpolated variables - string fmt - golang": {
|
||||
invalid: []string{
|
||||
`%b`, `%c`, `%d`, `% d`, `%e`, `%E`, `%f`, `%F`, `%g`, `%G`, `%o`, `%O`, `%p`, `%q`, `%-s`, `%s`, `%t`, `%T`, `%U`, `%#U`, `%+v`, `%#v`, `%v`, `%x`, `%X`,
|
||||
},
|
||||
"interpolated variables - string fmt - golang": {
|
||||
invalid: []string{
|
||||
`%b`, `%c`, `%d`, `% d`, `%e`, `%E`, `%f`, `%F`, `%g`, `%G`, `%o`, `%O`, `%p`, `%q`, `%-s`, `%s`, `%t`, `%T`, `%U`, `%#U`, `%+v`, `%#v`, `%v`, `%x`, `%X`,
|
||||
},
|
||||
},
|
||||
"interpolated variables - string fmt - python": {
|
||||
invalid: []string{
|
||||
`{}`, `{0}`, `{10}`,
|
||||
},
|
||||
"interpolated variables - string fmt - python": {
|
||||
invalid: []string{
|
||||
`{}`, `{0}`, `{10}`,
|
||||
},
|
||||
},
|
||||
"interpolated variables - ucd": {
|
||||
invalid: []string{`@password@`, `@LDAP_PASS@`},
|
||||
valid: []string{`@username@mastodon.example`},
|
||||
},
|
||||
"miscellaneous - file paths": {
|
||||
invalid: []string{
|
||||
// MacOS
|
||||
`/Users/james/Projects/SwiftCode/build/Release`,
|
||||
// Linux
|
||||
`/tmp/screen-exchange`,
|
||||
},
|
||||
"interpolated variables - ucd": {
|
||||
invalid: []string{`@password@`, `@LDAP_PASS@`},
|
||||
valid: []string{`@username@mastodon.example`},
|
||||
},
|
||||
}
|
||||
valid: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
func TestConfigAllowlistRegexes(t *testing.T) {
|
||||
cfg := CreateGlobalConfig()
|
||||
allowlist := cfg.Allowlist
|
||||
for name, cases := range tests {
|
||||
for name, cases := range allowlistRegexTests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
for _, c := range cases.invalid {
|
||||
if !allowlist.RegexAllowed(c) {
|
||||
@@ -84,50 +93,67 @@ func TestConfigAllowlistRegexes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigAllowlistPaths(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
invalid []string
|
||||
valid []string
|
||||
}{
|
||||
"javascript - common static assets": {
|
||||
invalid: []string{
|
||||
`src/main/static/lib/angular.1.2.16.min.js`,
|
||||
`src/main/resources/static/jquery-ui-1.12.1/jquery-ui-min.js`,
|
||||
`src/main/resources/static/js/jquery-ui-1.10.4.min.js`,
|
||||
`src-static/js/plotly.min.js`,
|
||||
`swagger/swaggerui/swagger-ui-bundle.js.map`,
|
||||
`swagger/swaggerui/swagger-ui-es-bundle.js.map`,
|
||||
`src/main/static/swagger-ui.min.js`,
|
||||
`swagger/swaggerui/swagger-ui.js`,
|
||||
},
|
||||
},
|
||||
"python": {
|
||||
invalid: []string{
|
||||
// lock files
|
||||
`Pipfile.lock`, `poetry.lock`,
|
||||
// virtual environments
|
||||
"env/lib/python3.7/site-packages/urllib3/util/url.py",
|
||||
"venv/Lib/site-packages/regex-2018.08.29.dist-info/DESCRIPTION.rst",
|
||||
"venv/lib64/python3.5/site-packages/pynvml.py",
|
||||
"python/python3/virtualenv/Lib/site-packages/pyphonetics/utils.py",
|
||||
"virtualenv/lib64/python3.7/base64.py",
|
||||
// packages
|
||||
"cde-root/usr/lib64/python2.4/site-packages/Numeric.pth",
|
||||
"lib/python3.9/site-packages/setuptools/_distutils/msvccompiler.py",
|
||||
"lib/python3.8/site-packages/botocore/data/alexaforbusiness/2017-11-09/service-2.json",
|
||||
"code/python/3.7.4/Lib/site-packages/dask/bytes/tests/test_bytes_utils.py",
|
||||
"python/3.7.4/Lib/site-packages/fsspec/utils.py",
|
||||
"python/2.7.16.32/Lib/bsddb/test/test_dbenv.py",
|
||||
"python/lib/python3.8/site-packages/boto3/data/ec2/2016-04-01/resources-1.json",
|
||||
// distinfo
|
||||
"libs/PyX-0.15.dist-info/AUTHORS",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func BenchmarkConfigAllowlistRegexes(b *testing.B) {
|
||||
cfg := CreateGlobalConfig()
|
||||
allowlist := cfg.Allowlist
|
||||
for name, cases := range tests {
|
||||
for n := 0; n < b.N; n++ {
|
||||
for _, cases := range allowlistRegexTests {
|
||||
for _, c := range cases.invalid {
|
||||
allowlist.RegexAllowed(c)
|
||||
}
|
||||
|
||||
for _, c := range cases.valid {
|
||||
allowlist.RegexAllowed(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var allowlistPathsTests = map[string]struct {
|
||||
invalid []string
|
||||
valid []string
|
||||
}{
|
||||
"javascript - common static assets": {
|
||||
invalid: []string{
|
||||
`tests/e2e/nuget/wwwroot/lib/bootstrap/dist/js/bootstrap.esm.min.js`,
|
||||
`src/main/static/lib/angular.1.2.16.min.js`,
|
||||
`src/main/resources/static/jquery-ui-1.12.1/jquery-ui-min.js`,
|
||||
`src/main/resources/static/js/jquery-ui-1.10.4.min.js`,
|
||||
`src-static/js/plotly.min.js`,
|
||||
`swagger/swaggerui/swagger-ui-bundle.js.map`,
|
||||
`swagger/swaggerui/swagger-ui-es-bundle.js.map`,
|
||||
`src/main/static/swagger-ui.min.js`,
|
||||
`swagger/swaggerui/swagger-ui.js`,
|
||||
},
|
||||
},
|
||||
"python": {
|
||||
invalid: []string{
|
||||
// lock files
|
||||
`Pipfile.lock`, `poetry.lock`,
|
||||
// virtual environments
|
||||
"env/lib/python3.7/site-packages/urllib3/util/url.py",
|
||||
"venv/Lib/site-packages/regex-2018.08.29.dist-info/DESCRIPTION.rst",
|
||||
"venv/lib64/python3.5/site-packages/pynvml.py",
|
||||
"python/python3/virtualenv/Lib/site-packages/pyphonetics/utils.py",
|
||||
"virtualenv/lib64/python3.7/base64.py",
|
||||
// packages
|
||||
"cde-root/usr/lib64/python2.4/site-packages/Numeric.pth",
|
||||
"lib/python3.9/site-packages/setuptools/_distutils/msvccompiler.py",
|
||||
"lib/python3.8/site-packages/botocore/data/alexaforbusiness/2017-11-09/service-2.json",
|
||||
"code/python/3.7.4/Lib/site-packages/dask/bytes/tests/test_bytes_utils.py",
|
||||
"python/3.7.4/Lib/site-packages/fsspec/utils.py",
|
||||
"python/2.7.16.32/Lib/bsddb/test/test_dbenv.py",
|
||||
"python/lib/python3.8/site-packages/boto3/data/ec2/2016-04-01/resources-1.json",
|
||||
// distinfo
|
||||
"libs/PyX-0.15.dist-info/AUTHORS",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestConfigAllowlistPaths(t *testing.T) {
|
||||
cfg := CreateGlobalConfig()
|
||||
allowlist := cfg.Allowlist
|
||||
for name, cases := range allowlistPathsTests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
for _, c := range cases.invalid {
|
||||
if !allowlist.PathAllowed(c) {
|
||||
@@ -143,3 +169,19 @@ func TestConfigAllowlistPaths(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkConfigAllowlistPaths(b *testing.B) {
|
||||
cfg := CreateGlobalConfig()
|
||||
allowlist := cfg.Allowlist
|
||||
for n := 0; n < b.N; n++ {
|
||||
for _, cases := range allowlistPathsTests {
|
||||
for _, c := range cases.invalid {
|
||||
allowlist.PathAllowed(c)
|
||||
}
|
||||
|
||||
for _, c := range cases.valid {
|
||||
allowlist.PathAllowed(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +147,7 @@ func main() {
|
||||
rules.MailGunSigningKey(),
|
||||
rules.MapBox(),
|
||||
rules.MattermostAccessToken(),
|
||||
rules.Meraki(),
|
||||
rules.MessageBirdAPIToken(),
|
||||
rules.MessageBirdClientID(),
|
||||
rules.NetlifyAccessToken(),
|
||||
@@ -171,6 +172,7 @@ func main() {
|
||||
rules.Prefect(),
|
||||
rules.PrivateAIToken(),
|
||||
rules.PrivateKey(),
|
||||
rules.PrivateKeyPKCS12File(),
|
||||
rules.PulumiAPIToken(),
|
||||
rules.PyPiUploadToken(),
|
||||
rules.RapidAPIAccessToken(),
|
||||
@@ -204,6 +206,8 @@ func main() {
|
||||
rules.SlackLegacyToken(),
|
||||
rules.SlackWebHookUrl(),
|
||||
rules.Snyk(),
|
||||
rules.Sonar(),
|
||||
rules.SourceGraph(),
|
||||
rules.StripeAccessToken(),
|
||||
rules.SquareAccessToken(),
|
||||
rules.SquareSpaceAccessToken(),
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// https://developer.1password.com/docs/service-accounts/security/?token-example=encoded
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func AgeSecretKey() *config.Rule {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func AWS() *config.Rule {
|
||||
|
||||
@@ -3,12 +3,10 @@ package rules
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// References:
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func Clojars() *config.Rule {
|
||||
|
||||
@@ -29,7 +29,8 @@ paths = [{{ range $i, $path := . }}
|
||||
{{- range $i, $rule := .Rules }}{{println}}[[rules]]
|
||||
id = "{{$rule.RuleID}}"
|
||||
description = "{{$rule.Description}}"
|
||||
regex = '''{{$rule.Regex}}'''
|
||||
{{- with $rule.Regex }}
|
||||
regex = '''{{ . }}'''{{ end -}}
|
||||
{{- with $rule.Path }}
|
||||
path = '''{{ . }}'''{{ end -}}
|
||||
{{- with $rule.SecretGroup }}
|
||||
|
||||
@@ -2,10 +2,10 @@ package rules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// https://curl.se/docs/manpage.html#-u
|
||||
@@ -13,18 +13,18 @@ func CurlBasicAuth() *config.Rule {
|
||||
r := config.Rule{
|
||||
RuleID: "curl-auth-user",
|
||||
Description: "Discovered a potential basic authorization token provided in a curl command, which could compromise the curl accessed resource.",
|
||||
Regex: regexp.MustCompile(`\bcurl\b(?:.*|.*(?:[\r\n]{1,2}.*){1,5})[ \t\n\r](?:-u|--user)(?:=|[ \t]{0,5})(?:"([^:"]{3,}:[^"]{3,})"|'([^:']{3,}:[^']{3,})'|((?:"[^"]{3,}"|'[^']{3,}'|[\w$@.-]+):(?:"[^"]{3,}"|'[^']{3,}'|[\w${}@.-]+)))(?:\s|\z)`),
|
||||
Regex: regexp.MustCompile(`\bcurl\b(?:.*|.*(?:[\r\n]{1,2}.*){1,5})[ \t\n\r](?:-u|--user)(?:=|[ \t]{0,5})("(:[^"]{3,}|[^:"]{3,}:|[^:"]{3,}:[^"]{3,})"|'([^:']{3,}:[^']{3,})'|((?:"[^"]{3,}"|'[^']{3,}'|[\w$@.-]+):(?:"[^"]{3,}"|'[^']{3,}'|[\w${}@.-]+)))(?:\s|\z)`),
|
||||
Keywords: []string{"curl"},
|
||||
Entropy: 2,
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Regexes: []*regexp.Regexp{
|
||||
regexp.MustCompile(`[^:]+:(change(it|me)|pass(word)?|pwd|test|token|\*+|x+)`), // common placeholder passwords
|
||||
regexp.MustCompile(`['"]?<[^>]+>['"]?:['"]?<[^>]+>|<[^:]+:[^>]+>['"]?`), // <placeholder>
|
||||
regexp.MustCompile(`[^:]+:\[[^]]+]`), // [placeholder]
|
||||
regexp.MustCompile(`['"]?[^:]+['"]?:['"]?\$(\d|\w+|\{(\d|\w+)})['"]?`), // $1 or $VARIABLE
|
||||
regexp.MustCompile(`\$\([^)]+\):\$\([^)]+\)`), // $(cat login.txt)
|
||||
regexp.MustCompile(`['"]?\$?{{[^}]+}}['"]?:['"]?\$?{{[^}]+}}['"]?`), // ${{ secrets.FOO }} or {{ .Values.foo }}
|
||||
regexp.MustCompile(`[^:]+:(?:change(?:it|me)|pass(?:word)?|pwd|test|token|\*+|x+)`), // common placeholder passwords
|
||||
regexp.MustCompile(`['"]?<[^>]+>['"]?:['"]?<[^>]+>|<[^:]+:[^>]+>['"]?`), // <placeholder>
|
||||
regexp.MustCompile(`[^:]+:\[[^]]+]`), // [placeholder]
|
||||
regexp.MustCompile(`['"]?[^:]+['"]?:['"]?\$(?:\d|\w+|\{(?:\d|\w+)})['"]?`), // $1 or $VARIABLE
|
||||
regexp.MustCompile(`\$\([^)]+\):\$\([^)]+\)`), // $(cat login.txt)
|
||||
regexp.MustCompile(`['"]?\$?{{[^}]+}}['"]?:['"]?\$?{{[^}]+}}['"]?`), // ${{ secrets.FOO }} or {{ .Values.foo }}
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -38,6 +38,8 @@ func CurlBasicAuth() *config.Rule {
|
||||
-H 'Content-type: text/plain' \
|
||||
-d 'world' \
|
||||
-u developer:yqDVtkqPECriaLRi`, // different line
|
||||
`curl -u ":d2LkV78zLx!t" https://localhost:9200`, // empty username
|
||||
`curl -u "d2LkV78zLx!t:" https://localhost:9200`, // empty password
|
||||
|
||||
// long
|
||||
`curl -sw '%{http_code}' -X POST --user 'johns:h0pk1ns~21s' $GItHUB_API_URL/$GIT_COMMIT --data`,
|
||||
@@ -65,6 +67,7 @@ func CurlBasicAuth() *config.Rule {
|
||||
`curl -u "${_username}:${_password}"`,
|
||||
`curl -u "${username}":"${password}"`,
|
||||
`curl -k -X POST -I -u "SRVC_JENKINS:${APPID}"`,
|
||||
`curl -u ":" https://localhost:9200`, // empty username and password
|
||||
|
||||
// long
|
||||
`curl -sw '%{http_code}' -X POST --user '$USERNAME:$PASSWORD' $GItHUB_API_URL/$GIT_COMMIT --data`,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func Doppler() *config.Rule {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func Duffel() *config.Rule {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func Dynatrace() *config.Rule {
|
||||
@@ -16,7 +14,7 @@ func Dynatrace() *config.Rule {
|
||||
Description: "Detected a Dynatrace API token, potentially risking application performance monitoring and data exposure.",
|
||||
Regex: regexp.MustCompile(`dt0c01\.(?i)[a-z0-9]{24}\.[a-z0-9]{64}`),
|
||||
Entropy: 4,
|
||||
Keywords: []string{"dt0c01"},
|
||||
Keywords: []string{"dt0c01."},
|
||||
}
|
||||
|
||||
// validate
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func EasyPost() *config.Rule {
|
||||
|
||||
@@ -34,14 +34,15 @@ func FacebookAccessToken() *config.Rule {
|
||||
RuleID: "facebook-access-token",
|
||||
Description: "Discovered a Facebook Access Token, posing a risk of unauthorized access to Facebook accounts and personal data exposure.",
|
||||
Regex: utils.GenerateUniqueTokenRegex(`\d{15,16}(\||%)[0-9a-z\-_]{27,40}`, true),
|
||||
Keywords: []string{"facebook"},
|
||||
Entropy: 3,
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
`{"access_token":"911602140448729|AY-lRJZq9BoDLobvAiP25L7RcMg","token_type":"bearer"}`, // gitleaks:allow
|
||||
`1308742762612587|rhoK1cbv0DOU_RTX_87O4MkX7AI`, // gitleaks:allow
|
||||
`1477036645700765|wRPf2v3mt2JfMqCLK8n7oltrEmc`, // gitleaks:allow
|
||||
`{"facebook access_token":"911602140448729|AY-lRJZq9BoDLobvAiP25L7RcMg","token_type":"bearer"}`, // gitleaks:allow
|
||||
`facebook 1308742762612587|rhoK1cbv0DOU_RTX_87O4MkX7AI`, // gitleaks:allow
|
||||
`facebook 1477036645700765|wRPf2v3mt2JfMqCLK8n7oltrEmc`, // gitleaks:allow
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func FlutterwavePublicKey() *config.Rule {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func FrameIO() *config.Rule {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func Freemius() *config.Rule {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// TODO this one could probably use some work
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func GenericCredential() *config.Rule {
|
||||
@@ -20,11 +19,10 @@ func GenericCredential() *config.Rule {
|
||||
"credential",
|
||||
"creds",
|
||||
"key",
|
||||
"passwd",
|
||||
"password",
|
||||
"passw(?:or)?d",
|
||||
"secret",
|
||||
"token",
|
||||
}, `[\w.=-]{10,150}`, true),
|
||||
}, `[\w.=-]{10,150}|[a-z0-9][a-z0-9+/]{11,}={0,3}`, true),
|
||||
Keywords: []string{
|
||||
"access",
|
||||
"api",
|
||||
@@ -51,12 +49,13 @@ func GenericCredential() *config.Rule {
|
||||
MatchCondition: config.AllowlistMatchOr,
|
||||
RegexTarget: "match",
|
||||
Regexes: []*regexp.Regexp{
|
||||
regexp.MustCompile(`(?i)(` +
|
||||
regexp.MustCompile(`(?i)(?:` +
|
||||
// Access
|
||||
`accessor` +
|
||||
`access(?:ibility|or)` +
|
||||
`|access[_.-]?id` +
|
||||
`|random[_.-]?access` +
|
||||
// API
|
||||
`|api[_.-]?(version|id)` + // version/id -> not a secret
|
||||
`|api[_.-]?(?:id|name|version)` + // id/name/version -> not a secret
|
||||
`|rapid|capital` + // common words containing "api"
|
||||
`|[a-z0-9-]*?api[a-z0-9-]*?:jar:` + // Maven META-INF dependencies that contain "api" in the name.
|
||||
// Auth
|
||||
@@ -64,26 +63,41 @@ func GenericCredential() *config.Rule {
|
||||
`|X-MS-Exchange-Organization-Auth` + // email header
|
||||
`|Authentication-Results` + // email header
|
||||
// Credentials
|
||||
`|(credentials?[_.-]?id|withCredentials)` + // Jenkins plugins
|
||||
`|(?:credentials?[_.-]?id|withCredentials)` + // Jenkins plugins
|
||||
// Key
|
||||
`|(bucket|foreign|hot|natural|primary|schema|sequence)[_.-]?key` +
|
||||
`|key[_.-]?(alias|board|code|ring|selector|size|stone|storetype|word|up|down|left|right)` +
|
||||
`|key(store|tab)[_.-]?(file|path)` +
|
||||
`|(?:bucket|foreign|hot|idx|natural|primary|pub(?:lic)?|schema|sequence)[_.-]?key` +
|
||||
`|key[_.-]?(?:alias|board|code|frame|id|length|mesh|name|pair|press(?:ed)?|ring|selector|signature|size|stone|storetype|word|up|down|left|right)` +
|
||||
// Azure KeyVault
|
||||
`|key[_.-]?vault[_.-]?(?:id|name)|keyVaultToStoreSecrets` +
|
||||
`|key(?:store|tab)[_.-]?(?:file|path)` +
|
||||
`|issuerkeyhash` + // part of ssl cert
|
||||
`|(?-i:[DdMm]onkey|[DM]ONKEY)|keying` + // common words containing "key"
|
||||
// Secret
|
||||
`|(secret)[_.-]?name` + // name of e.g. env variable
|
||||
`|(?:secret)[_.-]?(?:length|name|size)` + // name of e.g. env variable
|
||||
`|UserSecretsId` + // https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-8.0&tabs=linux
|
||||
|
||||
// Token
|
||||
`|(?:io\.jsonwebtoken[ \t]?:[ \t]?[\w-]+)` + // Maven library coordinats. (e.g., https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt)
|
||||
|
||||
// General
|
||||
`|(api|credentials|token)[_.-]?(endpoint|ur[il])` +
|
||||
`|public[_.-]?(key|token)` + // public key -> not a secret
|
||||
`|(key|token)[_.-]?file` +
|
||||
`|(?:api|credentials|token)[_.-]?(?:endpoint|ur[il])` +
|
||||
`|public[_.-]?token` +
|
||||
`|(?:key|token)[_.-]?file` +
|
||||
// Empty variables capturing the next line (e.g., .env files)
|
||||
`|(?-i:(?:[A-Z_]+=\n[A-Z_]+=|[a-z_]+=\n[a-z_]+=)(?:\n|\z))` +
|
||||
`|(?-i:(?:[A-Z.]+=\n[A-Z.]+=|[a-z.]+=\n[a-z.]+=)(?:\n|\z))` +
|
||||
`)`),
|
||||
},
|
||||
StopWords: DefaultStopWords,
|
||||
StopWords: append(DefaultStopWords,
|
||||
"6fe4476ee5a1832882e326b506d14126", // https://github.com/yarnpkg/berry/issues/6201
|
||||
),
|
||||
},
|
||||
{
|
||||
RegexTarget: "line",
|
||||
Regexes: []*regexp.Regexp{
|
||||
// Docker build secrets (https://docs.docker.com/build/building/secrets/#using-build-secrets).
|
||||
regexp.MustCompile(`--mount=type=secret,`),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -99,6 +113,8 @@ func GenericCredential() *config.Rule {
|
||||
`some_api_token_123 = "`+newPlausibleSecret(`[a-zA-Z0-9]{60}`)+`"`,
|
||||
|
||||
// Auth
|
||||
`"user_auth": "am9obmRvZTpkMDY5NGIxYi1jMTcxLTQ4ODYt+TMyYS0wMmUwOWQ1/mIwNjc="`,
|
||||
|
||||
// Credentials
|
||||
`"credentials" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
|
||||
`creds = `+newPlausibleSecret(`[a-zA-Z0-9]{30}`),
|
||||
@@ -116,13 +132,17 @@ func GenericCredential() *config.Rule {
|
||||
`todo_secret_do_not_commit = `+newPlausibleSecret(`[a-zA-Z0-9]{30}`),
|
||||
|
||||
// Token
|
||||
utils.GenerateSampleSecret("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443"), //gitleaks:allow
|
||||
utils.GenerateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
|
||||
` utils.GetEnvOrDefault("api_token", "dafa7817-e246-48f3-91a7-e87653d587b8")`,
|
||||
// `"env": {
|
||||
//"API_TOKEN": "Lj2^5O%xi214"`,
|
||||
)
|
||||
fps := []string{
|
||||
// Access
|
||||
`"accessor":"rA1wk0Y45YCufyfq",`,
|
||||
`report_access_id: e8e4df51-2054-49b0-ab1c-516ac95c691d`,
|
||||
`accessibilityYesOptionId = "0736f5ef-7e88-499a-80cc-90c85d2a5180"`,
|
||||
`_RandomAccessIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 `,
|
||||
|
||||
// API
|
||||
`this.ultraPictureBox1.Name = "ultraPictureBox1";`,
|
||||
@@ -133,6 +153,7 @@ func GenericCredential() *config.Rule {
|
||||
`[DEBUG] org.slf4j.slf4j-api:jar:1.7.8.:compile (version managed from default)`,
|
||||
`[DEBUG] org.neo4j.neo4j-graphdb-api:jar:3.5.12:test`,
|
||||
`apiUrl=apigee.corpint.com`,
|
||||
`X-API-Name": "NRG0-Hermes-INTERNAL-API",`,
|
||||
// TODO: Jetbrains IML files (requires line-level allowlist).
|
||||
// `<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.directory.api:api-asn1-api:1.0.0-M20" level="projcet" />`
|
||||
|
||||
@@ -154,6 +175,8 @@ func GenericCredential() *config.Rule {
|
||||
// Key
|
||||
`keyword: "Befaehigung_P2"`,
|
||||
`public_key = "9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit"`,
|
||||
`pub const X509_pubkey_st = struct_X509_pubkey_st;`,
|
||||
`|| pIdxKey->default_rc==0`,
|
||||
`monkeys-audio:mx64-uwp=fail`,
|
||||
`primaryKey=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
||||
`foreignKey=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
||||
@@ -163,7 +186,6 @@ func GenericCredential() *config.Rule {
|
||||
`minisat-master-keying:x64-uwp=fail`,
|
||||
`IceSSL.KeyFile=s_rsa1024_priv.pem`,
|
||||
`"bucket_key": "SalesResults-1.2"`,
|
||||
// `<TAR key="REF_ID_923.properties" value="/opts/config/alias/"/>`,
|
||||
`<key tag="SecurityIdentifier" name="SecurityIdentifier" type="STRING" />`,
|
||||
// `packageKey":` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
||||
`schemaKey = 'DOC_Vector_5_32'`,
|
||||
@@ -173,7 +195,22 @@ func GenericCredential() *config.Rule {
|
||||
` doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;`,
|
||||
`o.keySelector=n,o.haKey=!1,`,
|
||||
// TODO: Requires line-level allowlists.
|
||||
` "key_name": "prod5zyxlmy-cmk",`,
|
||||
` "kms_key_id": "555ea4a3-d53a-4412-9c66-3a7cb667b0d6",`,
|
||||
` "key_vault_name": "web21prqodx24021",`,
|
||||
` keyVaultToStoreSecrets: cmp2-qat-1208358310`, // e.g., https://github.com/2uasimojo/community-operators-prod/blob/9e51e4c8e0b5caaa3087e8e18e6fb918b2c36643/operators/azure-service-operator/1.0.59040/manifests/azure.microsoft.com_cosmosdbs.yaml#L50
|
||||
`,apiKey:"6fe4476ee5a1832882e326b506d14126",`,
|
||||
`const validKeyChars = "0123456789abcdefghijklmnopqrstuvwxyz_-."`,
|
||||
`const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"`,
|
||||
`key_length = XSalsa20.key_length`,
|
||||
`pub const SN_id_Gost28147_89_None_KeyMeshing = "id-Gost28147-89-None-KeyMeshing"`,
|
||||
`KeyPair = X25519.KeyPair`,
|
||||
`BlindKeySignatures = Ed25519.BlindKeySignatures`,
|
||||
`AVEncVideoMaxKeyframeDistance, "2987123a-ba93-4704-b489-ec1e5f25292c"`,
|
||||
` keyPressed = kVK_Return.u16`,
|
||||
// `<add key="SchemaTable" value="G:\SchemaTable.xml" />`,
|
||||
//` { key: '9df21e95-3848-409d-8f94-c675cdfee839', value: 'Americas' },`,
|
||||
// `<TAR key="REF_ID_923.properties" value="/opts/config/alias/"/>`,
|
||||
// `secret:
|
||||
// secretName: app-decryption-secret
|
||||
// items:
|
||||
@@ -181,7 +218,7 @@ func GenericCredential() *config.Rule {
|
||||
// path: app-k8s.yml`,
|
||||
|
||||
// TODO: https://learn.microsoft.com/en-us/windows/apps/design/style/xaml-theme-resources
|
||||
// `<Color x:Key="NormalBrushGradient1">#FFBAE4FF</Color>`,
|
||||
//`<Color x:Key="NormalBrushGradient1">#FFBAE4FF</Color>`,
|
||||
|
||||
// Password
|
||||
`password combination.
|
||||
@@ -192,15 +229,25 @@ R5: Regulatory--21`,
|
||||
// Secret
|
||||
`LLM_SECRET_NAME = "NEXUS-GPT4-API-KEY"`,
|
||||
` <UserSecretsId>79a3edd0-2092-40a2-a04d-dcb46d5ca9ed</UserSecretsId>`,
|
||||
`secret_length = X25519.secret_length`,
|
||||
`secretSize must be >= XXH3_SECRET_SIZE_MIN`,
|
||||
`# get build time secret for authentication
|
||||
#RUN --mount=type=secret,id=jfrog_secret \
|
||||
# JFROG_SECRET = $(cat /run/secrets/jfrog_secret) && \`,
|
||||
|
||||
// Token
|
||||
` access_token_url='https://github.com/login/oauth/access_token',`,
|
||||
`publicToken = "9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit"`,
|
||||
`<SourceFile SourceLocation="F:\Extracts\" TokenFile="RTL_INST_CODE.cer">`,
|
||||
`notes = "Maven - io.jsonwebtoken:jjwt-jackson-0.11.2"`,
|
||||
// TODO: `TOKEN_AUDIENCE = "25872395-ed3a-4703-b647-22ec53f3683c"`,
|
||||
|
||||
// General
|
||||
`clientId = "73082700-1f09-405b-80d0-3131bfd6272d"`,
|
||||
`GITHUB_API_KEY=
|
||||
DYNATRACE_API_KEY=`,
|
||||
`snowflake.password=
|
||||
jdbc.snowflake.url=`,
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
@@ -216,7 +263,7 @@ func newPlausibleSecret(regex string) string {
|
||||
if !regexp.MustCompile(`[1-9]`).MatchString(secret) {
|
||||
continue
|
||||
}
|
||||
if allowList.ContainsStopWord(secret) {
|
||||
if ok, _ := allowList.ContainsStopWord(secret); ok {
|
||||
continue
|
||||
}
|
||||
return secret
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
var githubAllowlist = []config.Allowlist{
|
||||
{
|
||||
Paths: []*regexp.Regexp{
|
||||
// https://github.com/octokit/auth-token.js/?tab=readme-ov-file#createtokenauthtoken-options
|
||||
regexp.MustCompile(`(^|/)@octokit/auth-token/README\.md$`),
|
||||
regexp.MustCompile(`(?:^|/)@octokit/auth-token/README\.md$`),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// overview with all GitLab tokens:
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func HarnessApiKey() *config.Rule {
|
||||
|
||||
@@ -3,12 +3,10 @@ package rules
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func HashiCorpTerraform() *config.Rule {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func VaultServiceToken() *config.Rule {
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
b64 "encoding/base64"
|
||||
"fmt"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func JWT() *config.Rule {
|
||||
|
||||
@@ -3,11 +3,9 @@ package rules
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// KubernetesSecret validates if we detected a kubernetes secret which contains data!
|
||||
@@ -47,7 +45,7 @@ func KubernetesSecret() *config.Rule {
|
||||
// Avoid overreach between directives.
|
||||
RegexTarget: "match",
|
||||
Regexes: []*regexp.Regexp{
|
||||
regexp.MustCompile(`(kind:(.|\s)+\n---\n(.|\s)+\bdata:|data:(.|\s)+\n---\n(.|\s)+\bkind:)`),
|
||||
regexp.MustCompile(`(kind:(?:.|\s)+\n---\n(?:.|\s)+\bdata:|data:(?:.|\s)+\n---\n(?:.|\s)+\bkind:)`),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func LinearAPIToken() *config.Rule {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func Meraki() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
RuleID: "cisco-meraki-api-key",
|
||||
Description: "Cisco Meraki is a cloud-managed IT solution that provides networking, security, and device management through an easy-to-use interface.",
|
||||
Regex: utils.GenerateSemiGenericRegex([]string{`(?-i:[Mm]eraki|MERAKI)`}, `[0-9a-f]{40}`, false),
|
||||
Entropy: 3,
|
||||
Keywords: []string{"meraki"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := utils.GenerateSampleSecrets("meraki", secrets.NewSecret(utils.Hex("40")))
|
||||
fps := []string{
|
||||
`meraki: aaaaaaaaaa1111111111bbbbbbbbbb2222222222`, // low entropy
|
||||
`meraki-api-key: acdeFf05b1a6d4c890237bf08c5e6e8d2b4d0f2e`, // invalid case
|
||||
`meraki: abdefghjk0123456789mnopqrstuvwx12345678`, // invalid character
|
||||
`meraki_token = 5cb4a5f04cd412fe946667b17f0129ba17aeb2e0c7b5b7264efcebf7d022bfe2R21`, // invalid length
|
||||
`ReactNativeCameraKit: f15a5a04b0f6dc6073e6db0296e6ef2d8b8d2522`,
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func NugetConfigPassword() *config.Rule {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// OpenShift 4 user tokens are prefixed with `sha256~`.
|
||||
|
||||
@@ -1,32 +1,61 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func PrivateKey() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.",
|
||||
RuleID: "private-key",
|
||||
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*?KEY(?: BLOCK)?-----`),
|
||||
Description: "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.",
|
||||
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]{64,}?KEY(?: BLOCK)?-----`),
|
||||
Keywords: []string{"-----BEGIN"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{`-----BEGIN PRIVATE KEY-----
|
||||
anything
|
||||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDAC4AWkdwKYSd8
|
||||
Ks14IReLcYgADhoXk56ZzXI=
|
||||
-----END PRIVATE KEY-----`,
|
||||
`-----BEGIN RSA PRIVATE KEY-----
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
MIIEpQIBAAKCAQEAn6/O8li+SX4m98LLYt/PKSzEmQ++ZBD7Loh9P13f4yQ92EF3
|
||||
yxR5MsXFu9PRsrYQA7/4UTPHiC4y2sAVCBg4C2yyBpUEtMQjyCESi6Y=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`,
|
||||
`-----BEGIN PRIVATE KEY BLOCK-----
|
||||
anything
|
||||
-----END PRIVATE KEY BLOCK-----`,
|
||||
`-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
lQWGBGSVV4YBDAClvRnxezIRy2Yv7SFlzC0iFiRF/O/jePSw+XYhvcrTaqSYTGic
|
||||
=8xQN
|
||||
-----END PGP PRIVATE KEY BLOCK-----`,
|
||||
} // gitleaks:allow
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
`-----BEGIN PRIVATE KEY-----
|
||||
anything
|
||||
-----END PRIVATE KEY-----`,
|
||||
`-----BEGIN OPENSSH PRIVATE KEY----------END OPENSSH PRIVATE KEY-----`,
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
|
||||
func PrivateKeyPKCS12File() *config.Rule {
|
||||
// https://en.wikipedia.org/wiki/PKCS_12
|
||||
r := config.Rule{
|
||||
RuleID: "pkcs12-file",
|
||||
Description: "Found a PKCS #12 file, which commonly contain bundled private keys.",
|
||||
Path: regexp.MustCompile(`(?i)(?:^|\/)[^\/]+\.p(?:12|fx)$`),
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := map[string]string{
|
||||
"security/es_certificates/opensearch/es_kibana_client.p12": "",
|
||||
"cagw_key.P12": "",
|
||||
"ToDo/ToDo.UWP/ToDo.UWP_TemporaryKey.pfx": "",
|
||||
}
|
||||
fps := map[string]string{
|
||||
"doc/typenum/type.P126.html": "",
|
||||
"scripts/keeneland/syntest.p1200.sh": "",
|
||||
}
|
||||
return utils.ValidateWithPaths(r, tps, fps)
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func PyPiUploadToken() *config.Rule {
|
||||
|
||||
@@ -2,11 +2,11 @@ package rules
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func SentryAccessToken() *config.Rule {
|
||||
@@ -43,7 +43,7 @@ func SentryOrgToken() *config.Rule {
|
||||
r := config.Rule{
|
||||
RuleID: "sentry-org-token",
|
||||
Description: "Found a Sentry.io Organization Token, risking unauthorized access to error tracking services and sensitive application data.",
|
||||
Regex: regexp.MustCompile(`\bsntrys_eyJpYXQiO[a-zA-Z0-9+/]{10,200}(?:LCJyZWdpb25fdXJs|InJlZ2lvbl91cmwi|cmVnaW9uX3VybCI6)[a-zA-Z0-9+/]{10,200}={0,2}_[a-zA-Z0-9+/]{43}\b`),
|
||||
Regex: regexp.MustCompile(`\bsntrys_eyJpYXQiO[a-zA-Z0-9+/]{10,200}(?:LCJyZWdpb25fdXJs|InJlZ2lvbl91cmwi|cmVnaW9uX3VybCI6)[a-zA-Z0-9+/]{10,200}={0,2}_[a-zA-Z0-9+/]{43}(?:[^a-zA-Z0-9+/]|\z)`),
|
||||
Entropy: 4.5,
|
||||
Keywords: []string{"sntrys_eyJpYXQiO"},
|
||||
}
|
||||
@@ -52,6 +52,9 @@ func SentryOrgToken() *config.Rule {
|
||||
tps := utils.GenerateSampleSecrets("sentry",
|
||||
`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`, // gitleaks:allow
|
||||
)
|
||||
tps = append(tps, utils.GenerateSampleSecrets("sentry",
|
||||
`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`, // gitleaks:allow
|
||||
)...)
|
||||
tps = append(tps,
|
||||
` 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`, // gitleaks:allow
|
||||
)
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func ShopifySharedSecret() *config.Rule {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func SidekiqSecret() *config.Rule {
|
||||
|
||||
@@ -2,12 +2,11 @@ package rules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// https://api.slack.com/authentication/token-types#bot
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func Sonar() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "Uncovered a Sonar API token, potentially compromising software vulnerability scanning and code security.",
|
||||
RuleID: "sonar-api-token",
|
||||
Regex: utils.GenerateSemiGenericRegex([]string{"sonar[_.-]?(login|token)"}, utils.AlphaNumericExtended("40"), true),
|
||||
Keywords: []string{"sonar"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := utils.GenerateSampleSecrets("sonar", "12345678ABCDEFH1234567890ABCDEFH12345678")
|
||||
tps = append(tps,
|
||||
`const SONAR_LOGIN = "12345678ABCDEFH1234567890ABCDEFH12345678"`, // gitleaks:allow
|
||||
`SONAR_LOGIN := "12345678ABCDEFH1234567890ABCDEFH12345678"`, // gitleaks:allow
|
||||
`SONAR.LOGIN ::= "12345678ABCDEFH1234567890ABCDEFH12345678"`, // gitleaks:allow
|
||||
`SONAR.LOGIN :::= "12345678ABCDEFH1234567890ABCDEFH12345678"`, // gitleaks:allow
|
||||
`SONAR.LOGIN ?= "12345678ABCDEFH1234567890ABCDEFH12345678"`, // gitleaks:allow
|
||||
)
|
||||
return utils.Validate(r, tps, nil)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func SourceGraph() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
RuleID: "sourcegraph-access-token",
|
||||
Description: "Sourcegraph is a code search and navigation engine.",
|
||||
Regex: utils.GenerateUniqueTokenRegex(`\b(sgp_(?:[a-fA-F0-9]{16}|local)_[a-fA-F0-9]{40}|sgp_[a-fA-F0-9]{40}|[a-fA-F0-9]{40})\b`, true),
|
||||
Entropy: 3,
|
||||
Keywords: []string{"sgp_", "sourcegraph"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
`sgp_AaD80dc6E02eCAE1_d3cba16CC0F18fA14A2EFB61CbDFceEBf9fAD16b`,
|
||||
`sourcegraph: 6d2FabeB6ADd229Bc199FabA28fD3efb57dF0bD3`,
|
||||
`sgp_0D697F54cb24238EefB29af05Abf1b505E90950F`,
|
||||
`sgp_local_d7dfFD43cF2503B1da673EB560aAa3e80f16FA42`,
|
||||
`sgp_local_bcD1DA18de0d6476Be0f3BD7Ef9Da4f09b479aE5`,
|
||||
}
|
||||
fps := []string{
|
||||
`sgp_5555555dAAAAA7777777CcccCFaaaaaaaaaaaaaa`, // low entropy
|
||||
`sgp_local_d45b6G86aBb0F2Cee943902dbaDBCFCFDD1dA089`, // invalid case
|
||||
`sgp_652d9a2e48FC7E!FcDbEA1BC2E2A6CE23cFe7F7D`, // invalid character
|
||||
`sgp_78Ad84a5B6e8A2fE5B_4085FB0ccaDDd29DB66Fd7FE9bA2C1cdCE8400CD`, // invalid length
|
||||
`BcAeb6640ad7DAD46AD73687946Ce85047d5C9Bb`,
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func TeamsWebhook() *config.Rule {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func Twilio() *config.Rule {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,17 +19,16 @@ const (
|
||||
identifierCaseInsensitivePrefix = `[\w.-]{0,50}?(?i:`
|
||||
identifierCaseInsensitiveSuffix = `)`
|
||||
identifierPrefix = `[\w.-]{0,50}?(?:`
|
||||
identifierSuffix = `)(?:[ \t\w.-]{0,20})(?:[\s|']|[\s|"]){0,3}`
|
||||
identifierSuffix = `)(?:[ \t\w.-]{0,20})[\s'"]{0,3}`
|
||||
|
||||
// commonly used assignment operators or function call
|
||||
//language=regexp
|
||||
operator = `(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=|,)`
|
||||
operator = `(?:=|>|:{1,3}=|\|\||:|=>|\?=|,)`
|
||||
|
||||
// boundaries for the secret
|
||||
// \x60 = `
|
||||
secretPrefixUnique = `\b(`
|
||||
secretPrefix = `(?:'|\"|\s|=|\x60){0,5}(`
|
||||
secretSuffix = `)(?:['|\"|\n|\r|\s|\x60|;]|$)`
|
||||
secretPrefix = `[\x60'"\s=]{0,5}(`
|
||||
secretSuffix = `)(?:[\x60'"\s;]|\\[nr]|$)`
|
||||
)
|
||||
|
||||
func GenerateSemiGenericRegex(identifiers []string, secretRegex string, isCaseInsensitive bool) *regexp.Regexp {
|
||||
@@ -95,6 +94,7 @@ func GenerateSampleSecrets(identifier string, secret string) []string {
|
||||
"json - string": "{\n \"{i}_token\": \"{s}\"\n}",
|
||||
// TODO: "json - escaped string": "\\{\n \\\"{i}_token\\\": \\\"{s}\\\"\n\\}",
|
||||
// TODO: "json - string key/value": "{\n \"name\": \"{i}_token\",\n \"value\": \"{s}\"\n}",
|
||||
"json - escaped newline in string": `{"config.ini": "{I}_TOKEN={s}\nBACKUP_ENABLED=true"}`,
|
||||
// XML
|
||||
// TODO: "xml - element": "<{i}Token>{s}</{i}Token>",
|
||||
"xml - element multiline": "<{i}Token>\n {s}\n</{i}Token>",
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestGenerateSemiGenericRegex(t *testing.T) {
|
||||
"api_key\t\t\t\t\t=xxx",
|
||||
"api_key\n\n\n=xxx", // potentially invalid?,
|
||||
"api_key\r\n=xxx",
|
||||
"api_key|||=xxx",
|
||||
// "api_key|||=xxx",
|
||||
},
|
||||
invalidStrings: []string{
|
||||
"api_key&=xxx",
|
||||
@@ -89,8 +89,8 @@ func TestGenerateSemiGenericRegex(t *testing.T) {
|
||||
"<api_key>xxx",
|
||||
"api_key:=xxx",
|
||||
"api_key:::=xxx",
|
||||
"api_key||:=xxx",
|
||||
"api_key <= xxx",
|
||||
// "api_key||:=xxx", // this isn't anything
|
||||
// "api_key <= xxx",
|
||||
"api_key => xxx",
|
||||
"api_key ?= xxx",
|
||||
"api_key, xxx",
|
||||
|
||||
+27
-37
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/scm"
|
||||
"github.com/zricethezav/gitleaks/v8/detect"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
"github.com/zricethezav/gitleaks/v8/sources"
|
||||
@@ -12,6 +14,7 @@ import (
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(gitCmd)
|
||||
gitCmd.Flags().String("platform", "", "the target platform used to generate links (github, gitlab)")
|
||||
gitCmd.Flags().Bool("staged", false, "scan staged commits (good for pre-commit)")
|
||||
gitCmd.Flags().Bool("pre-commit", false, "scan using git diff")
|
||||
gitCmd.Flags().String("log-opts", "", "git log options")
|
||||
@@ -25,10 +28,8 @@ var gitCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func runGit(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
findings []report.Finding
|
||||
err error
|
||||
)
|
||||
// start timer
|
||||
start := time.Now()
|
||||
|
||||
// grab source
|
||||
source := "."
|
||||
@@ -39,55 +40,44 @@ func runGit(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
initConfig(source)
|
||||
|
||||
// setup config (aka, the thing that defines rules)
|
||||
initConfig(source)
|
||||
cfg := Config(cmd)
|
||||
|
||||
// start timer
|
||||
start := time.Now()
|
||||
|
||||
// grab source
|
||||
// create detector
|
||||
detector := Detector(cmd, cfg, source)
|
||||
|
||||
// set exit code
|
||||
exitCode, err := cmd.Flags().GetInt("exit-code")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not get exit code")
|
||||
}
|
||||
// parse flags
|
||||
exitCode := mustGetIntFlag(cmd, "exit-code")
|
||||
logOpts := mustGetStringFlag(cmd, "log-opts")
|
||||
staged := mustGetBoolFlag(cmd, "staged")
|
||||
preCommit := mustGetBoolFlag(cmd, "pre-commit")
|
||||
|
||||
var (
|
||||
gitCmd *sources.GitCmd
|
||||
logOpts string
|
||||
preCommit bool
|
||||
staged bool
|
||||
)
|
||||
logOpts, err = cmd.Flags().GetString("log-opts")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not call GetString() for log-opts")
|
||||
}
|
||||
staged, err = cmd.Flags().GetBool("staged")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not call GetBool() for staged")
|
||||
}
|
||||
preCommit, err = cmd.Flags().GetBool("pre-commit")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not call GetBool() for pre-commit")
|
||||
}
|
||||
findings []report.Finding
|
||||
err error
|
||||
|
||||
gitCmd *sources.GitCmd
|
||||
scmPlatform scm.Platform
|
||||
remote *detect.RemoteInfo
|
||||
)
|
||||
if preCommit || staged {
|
||||
gitCmd, err = sources.NewGitDiffCmd(source, staged)
|
||||
if err != nil {
|
||||
if gitCmd, err = sources.NewGitDiffCmd(source, staged); err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not create Git diff cmd")
|
||||
}
|
||||
// Remote info + links are irrelevant for staged changes.
|
||||
remote = &detect.RemoteInfo{Platform: scm.NoPlatform}
|
||||
} else {
|
||||
gitCmd, err = sources.NewGitLogCmd(source, logOpts)
|
||||
if err != nil {
|
||||
if gitCmd, err = sources.NewGitLogCmd(source, logOpts); err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not create Git log cmd")
|
||||
}
|
||||
if scmPlatform, err = scm.PlatformFromString(mustGetStringFlag(cmd, "platform")); err != nil {
|
||||
logging.Fatal().Err(err).Send()
|
||||
}
|
||||
remote = detect.NewRemoteInfo(scmPlatform, source)
|
||||
}
|
||||
|
||||
findings, err = detector.DetectGit(gitCmd)
|
||||
findings, err = detector.DetectGit(gitCmd, remote)
|
||||
if err != nil {
|
||||
// don't exit on error, just log it
|
||||
logging.Error().Err(err).Msg("failed to scan Git repository")
|
||||
|
||||
+28
-15
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/scm"
|
||||
"github.com/zricethezav/gitleaks/v8/detect"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
"github.com/zricethezav/gitleaks/v8/sources"
|
||||
@@ -25,27 +27,38 @@ var protectCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func runProtect(cmd *cobra.Command, args []string) {
|
||||
source, err := cmd.Flags().GetString("source")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not get source")
|
||||
}
|
||||
initConfig(source)
|
||||
// start timer
|
||||
start := time.Now()
|
||||
source := mustGetStringFlag(cmd, "source")
|
||||
|
||||
// setup config (aka, the thing that defines rules)
|
||||
initConfig(source)
|
||||
cfg := Config(cmd)
|
||||
|
||||
exitCode, _ := cmd.Flags().GetInt("exit-code")
|
||||
staged, _ := cmd.Flags().GetBool("staged")
|
||||
start := time.Now()
|
||||
// create detector
|
||||
detector := Detector(cmd, cfg, source)
|
||||
|
||||
// start git scan
|
||||
var findings []report.Finding
|
||||
gitCmd, err := sources.NewGitDiffCmd(source, staged)
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("")
|
||||
}
|
||||
findings, err = detector.DetectGit(gitCmd)
|
||||
// parse flags
|
||||
exitCode := mustGetIntFlag(cmd, "exit-code")
|
||||
staged := mustGetBoolFlag(cmd, "staged")
|
||||
|
||||
// start git scan
|
||||
var (
|
||||
findings []report.Finding
|
||||
err error
|
||||
|
||||
gitCmd *sources.GitCmd
|
||||
remote *detect.RemoteInfo
|
||||
)
|
||||
|
||||
if gitCmd, err = sources.NewGitDiffCmd(source, staged); err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not create Git diff cmd")
|
||||
}
|
||||
remote = &detect.RemoteInfo{Platform: scm.NoPlatform}
|
||||
|
||||
if findings, err = detector.DetectGit(gitCmd, remote); err != nil {
|
||||
// don't exit on error, just log it
|
||||
logging.Error().Err(err).Msg("failed to scan Git repository")
|
||||
}
|
||||
findingSummaryAndExit(detector, findings, exitCode, start, err)
|
||||
}
|
||||
+30
-11
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/detect"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
)
|
||||
|
||||
@@ -110,6 +111,8 @@ func initConfig(source string) {
|
||||
_, _ = fmt.Fprint(os.Stderr, banner)
|
||||
}
|
||||
|
||||
logging.Debug().Msgf("using %s regex engine", regexp.Version)
|
||||
|
||||
cfgPath, err := rootCmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
logging.Fatal().Msg(err.Error())
|
||||
@@ -276,7 +279,7 @@ func Detector(cmd *cobra.Command, cfg config.Config, source string) *detect.Dete
|
||||
}
|
||||
|
||||
// Validate report settings.
|
||||
reportPath := mustGetStringFlag("report-path")
|
||||
reportPath := mustGetStringFlag(cmd, "report-path")
|
||||
if reportPath != "" {
|
||||
if reportPath != report.StdoutReportPath {
|
||||
// Ensure the path is writable.
|
||||
@@ -291,8 +294,8 @@ func Detector(cmd *cobra.Command, cfg config.Config, source string) *detect.Dete
|
||||
// Build report writer.
|
||||
var (
|
||||
reporter report.Reporter
|
||||
reportFormat = mustGetStringFlag("report-format")
|
||||
reportTemplate = mustGetStringFlag("report-template")
|
||||
reportFormat = mustGetStringFlag(cmd, "report-format")
|
||||
reportTemplate = mustGetStringFlag(cmd, "report-template")
|
||||
)
|
||||
switch strings.TrimSpace(strings.ToLower(reportFormat)) {
|
||||
case "csv":
|
||||
@@ -325,14 +328,6 @@ func Detector(cmd *cobra.Command, cfg config.Config, source string) *detect.Dete
|
||||
return detector
|
||||
}
|
||||
|
||||
func mustGetStringFlag(name string) string {
|
||||
reportPath, err := rootCmd.Flags().GetString(name)
|
||||
if err != nil {
|
||||
logging.Fatal().Msg(err.Error())
|
||||
}
|
||||
return reportPath
|
||||
}
|
||||
|
||||
func bytesConvert(bytes uint64) string {
|
||||
unit := ""
|
||||
value := float32(bytes)
|
||||
@@ -442,3 +437,27 @@ func FormatDuration(d time.Duration) string {
|
||||
}
|
||||
return d.Round(scale / 100).String()
|
||||
}
|
||||
|
||||
func mustGetBoolFlag(cmd *cobra.Command, name string) bool {
|
||||
value, err := cmd.Flags().GetBool(name)
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msgf("could not get flag: %s", name)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func mustGetIntFlag(cmd *cobra.Command, name string) int {
|
||||
value, err := cmd.Flags().GetInt(name)
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msgf("could not get flag: %s", name)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func mustGetStringFlag(cmd *cobra.Command, name string) string {
|
||||
value, err := cmd.Flags().GetString(name)
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msgf("could not get flag: %s", name)
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package scm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Platform int
|
||||
|
||||
const (
|
||||
UnknownPlatform Platform = iota
|
||||
NoPlatform // Explicitly disable the feature
|
||||
GitHubPlatform
|
||||
GitLabPlatform
|
||||
// TODO: Add others.
|
||||
)
|
||||
|
||||
func (p Platform) String() string {
|
||||
return [...]string{
|
||||
"unknown",
|
||||
"none",
|
||||
"github",
|
||||
"gitlab",
|
||||
}[p]
|
||||
}
|
||||
|
||||
func PlatformFromString(s string) (Platform, error) {
|
||||
switch strings.ToLower(s) {
|
||||
case "", "unknown":
|
||||
return UnknownPlatform, nil
|
||||
case "none":
|
||||
return NoPlatform, nil
|
||||
case "github":
|
||||
return GitHubPlatform, nil
|
||||
case "gitlab":
|
||||
return GitLabPlatform, nil
|
||||
default:
|
||||
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
|
||||
}
|
||||
}
|
||||
+10
-17
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -20,27 +19,21 @@ var stdInCmd = &cobra.Command{
|
||||
Run: runStdIn,
|
||||
}
|
||||
|
||||
func runStdIn(cmd *cobra.Command, args []string) {
|
||||
initConfig(".")
|
||||
var (
|
||||
findings []report.Finding
|
||||
err error
|
||||
)
|
||||
|
||||
// setup config (aka, the thing that defines rules)
|
||||
cfg := Config(cmd)
|
||||
|
||||
func runStdIn(cmd *cobra.Command, _ []string) {
|
||||
// start timer
|
||||
start := time.Now()
|
||||
|
||||
// setup config (aka, the thing that defines rules)
|
||||
initConfig(".")
|
||||
cfg := Config(cmd)
|
||||
|
||||
// create detector
|
||||
detector := Detector(cmd, cfg, "")
|
||||
|
||||
// set exit code
|
||||
exitCode, err := cmd.Flags().GetInt("exit-code")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("could not get exit code")
|
||||
}
|
||||
// parse flag(s)
|
||||
exitCode := mustGetIntFlag(cmd, "exit-code")
|
||||
|
||||
findings, err = detector.DetectReader(os.Stdin, 10)
|
||||
findings, err := detector.DetectReader(os.Stdin, 10)
|
||||
if err != nil {
|
||||
// log fatal to exit, no need to continue since a report
|
||||
// will not be generated when scanning from a pipe...for now
|
||||
|
||||
+10
-8
@@ -4,8 +4,9 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
type AllowlistMatchCondition int
|
||||
@@ -56,16 +57,17 @@ type Allowlist struct {
|
||||
}
|
||||
|
||||
// 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, string) {
|
||||
if c == "" {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
|
||||
for _, commit := range a.Commits {
|
||||
if commit == c {
|
||||
return true
|
||||
return true, c
|
||||
}
|
||||
}
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// PathAllowed returns true if the path is allowed to be ignored.
|
||||
@@ -78,14 +80,14 @@ func (a *Allowlist) RegexAllowed(secret string) bool {
|
||||
return anyRegexMatch(secret, a.Regexes)
|
||||
}
|
||||
|
||||
func (a *Allowlist) ContainsStopWord(s string) bool {
|
||||
func (a *Allowlist) ContainsStopWord(s string) (bool, string) {
|
||||
s = strings.ToLower(s)
|
||||
for _, stopWord := range a.StopWords {
|
||||
if strings.Contains(s, strings.ToLower(stopWord)) {
|
||||
return true
|
||||
return true, stopWord
|
||||
}
|
||||
}
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
|
||||
func (a *Allowlist) Validate() error {
|
||||
|
||||
@@ -7,7 +7,8 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/stretchr/testify/assert"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func TestCommitAllowed(t *testing.T) {
|
||||
@@ -39,7 +40,8 @@ func TestCommitAllowed(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
assert.Equal(t, tt.commitAllowed, tt.allowlist.CommitAllowed(tt.commit))
|
||||
isAllowed, _ := tt.allowlist.CommitAllowed(tt.commit)
|
||||
assert.Equal(t, tt.commitAllowed, isAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -7,9 +7,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
//go:embed gitleaks.toml
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
const configPath = "../testdata/config/"
|
||||
|
||||
+214
-175
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
// Rules contain information that define details on how to detect secrets
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
)
|
||||
|
||||
func anyRegexMatch(f string, res []*regexp.Regexp) bool {
|
||||
|
||||
+128
-72
@@ -5,13 +5,14 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
|
||||
ahocorasick "github.com/BobuSumisu/aho-corasick"
|
||||
@@ -26,7 +27,10 @@ const (
|
||||
chunkSize = 100 * 1_000 // 100kb
|
||||
)
|
||||
|
||||
var newLineRegexp = regexp.MustCompile("\n")
|
||||
var (
|
||||
newLineRegexp = regexp.MustCompile("\n")
|
||||
isWindows = runtime.GOOS == "windows"
|
||||
)
|
||||
|
||||
// Detector is the main detector struct
|
||||
type Detector struct {
|
||||
@@ -80,7 +84,7 @@ type Detector struct {
|
||||
baselinePath string
|
||||
|
||||
// gitleaksIgnore
|
||||
gitleaksIgnore map[string]bool
|
||||
gitleaksIgnore map[string]struct{}
|
||||
|
||||
// Sema (https://github.com/fatih/semgroup) controls the concurrency
|
||||
Sema *semgroup.Group
|
||||
@@ -99,9 +103,13 @@ type Fragment struct {
|
||||
|
||||
Bytes []byte
|
||||
|
||||
// FilePath is the path to the file if applicable
|
||||
// FilePath is the path to the file, if applicable.
|
||||
// The path separator MUST be normalized to `/`.
|
||||
FilePath string
|
||||
SymlinkFile string
|
||||
// WindowsFilePath is the path with the original separator.
|
||||
// This provides a backwards-compatible solution to https://github.com/gitleaks/gitleaks/issues/1565.
|
||||
WindowsFilePath string `json:"-"` // TODO: remove this in v9.
|
||||
|
||||
// CommitSHA is the SHA of the commit if applicable
|
||||
CommitSHA string
|
||||
@@ -115,7 +123,7 @@ type Fragment struct {
|
||||
func NewDetector(cfg config.Config) *Detector {
|
||||
return &Detector{
|
||||
commitMap: make(map[string]bool),
|
||||
gitleaksIgnore: make(map[string]bool),
|
||||
gitleaksIgnore: make(map[string]struct{}),
|
||||
findingMutex: &sync.Mutex{},
|
||||
findings: make([]report.Finding, 0),
|
||||
Config: cfg,
|
||||
@@ -146,25 +154,41 @@ func NewDetectorDefaultConfig() (*Detector, error) {
|
||||
func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
|
||||
logging.Debug().Msgf("found .gitleaksignore file: %s", gitleaksIgnorePath)
|
||||
file, err := os.Open(gitleaksIgnorePath)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// https://github.com/securego/gosec/issues/512
|
||||
defer func() {
|
||||
// https://github.com/securego/gosec/issues/512
|
||||
if err := file.Close(); err != nil {
|
||||
logging.Warn().Msgf("Error closing .gitleaksignore file: %s\n", err)
|
||||
}
|
||||
}()
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
replacer := strings.NewReplacer("\\", "/")
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
// Skip lines that start with a comment
|
||||
if line != "" && !strings.HasPrefix(line, "#") {
|
||||
d.gitleaksIgnore[line] = true
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
|
||||
// Normalize the path.
|
||||
// TODO: Make this a breaking change in v9.
|
||||
s := strings.Split(line, ":")
|
||||
switch len(s) {
|
||||
case 3:
|
||||
// Global fingerprint.
|
||||
// `file:rule-id:start-line`
|
||||
s[0] = replacer.Replace(s[0])
|
||||
case 4:
|
||||
// Commit fingerprint.
|
||||
// `commit:file:rule-id:start-line`
|
||||
s[1] = replacer.Replace(s[1])
|
||||
default:
|
||||
logging.Warn().Str("fingerprint", line).Msg("Invalid .gitleaksignore entry")
|
||||
}
|
||||
d.gitleaksIgnore[strings.Join(s, ":")] = struct{}{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -191,9 +215,13 @@ func (d *Detector) Detect(fragment Fragment) []report.Finding {
|
||||
var findings []report.Finding
|
||||
|
||||
// check if filepath is allowed
|
||||
if fragment.FilePath != "" && (d.Config.Allowlist.PathAllowed(fragment.FilePath) ||
|
||||
fragment.FilePath == d.Config.Path || (d.baselinePath != "" && fragment.FilePath == d.baselinePath)) {
|
||||
return findings
|
||||
if fragment.FilePath != "" {
|
||||
// is the path our config or baseline file?
|
||||
if fragment.FilePath == d.Config.Path || (d.baselinePath != "" && fragment.FilePath == d.baselinePath) ||
|
||||
// is the path excluded by the global allowlist?
|
||||
(d.Config.Allowlist.PathAllowed(fragment.FilePath) || (fragment.WindowsFilePath != "" && d.Config.Allowlist.PathAllowed(fragment.WindowsFilePath))) {
|
||||
return findings
|
||||
}
|
||||
}
|
||||
|
||||
// add newline indices for location calculation in detectRule
|
||||
@@ -256,11 +284,10 @@ func (d *Detector) detectRule(fragment Fragment, currentRaw string, r config.Rul
|
||||
var (
|
||||
findings []report.Finding
|
||||
logger = func() zerolog.Logger {
|
||||
l := logging.With().Str("rule-id", r.RuleID)
|
||||
l := logging.With().Str("rule-id", r.RuleID).Str("path", fragment.FilePath)
|
||||
if fragment.CommitSHA != "" {
|
||||
l = l.Str("commit", fragment.CommitSHA)
|
||||
}
|
||||
l = l.Str("path", fragment.FilePath)
|
||||
return l.Logger()
|
||||
}()
|
||||
)
|
||||
@@ -268,9 +295,9 @@ func (d *Detector) detectRule(fragment Fragment, currentRaw string, r config.Rul
|
||||
// check if filepath or commit is allowed for this rule
|
||||
for _, a := range r.Allowlists {
|
||||
var (
|
||||
isAllowed bool
|
||||
commitAllowed = a.CommitAllowed(fragment.CommitSHA)
|
||||
pathAllowed = a.PathAllowed(fragment.FilePath)
|
||||
isAllowed bool
|
||||
commitAllowed, commit = a.CommitAllowed(fragment.CommitSHA)
|
||||
pathAllowed = a.PathAllowed(fragment.FilePath) || (fragment.WindowsFilePath != "" && a.PathAllowed(fragment.WindowsFilePath))
|
||||
)
|
||||
if a.MatchCondition == config.AllowlistMatchAnd {
|
||||
// Determine applicable checks.
|
||||
@@ -295,34 +322,39 @@ func (d *Detector) detectRule(fragment Fragment, currentRaw string, r config.Rul
|
||||
isAllowed = commitAllowed || pathAllowed
|
||||
}
|
||||
if isAllowed {
|
||||
logger.Trace().
|
||||
Str("condition", a.MatchCondition.String()).
|
||||
Bool("commit-allowed", commitAllowed).
|
||||
Bool("path-allowed", commitAllowed).
|
||||
Msg("Skipping fragment due to rule allowlist")
|
||||
event := logger.Trace().Str("condition", a.MatchCondition.String())
|
||||
if commitAllowed {
|
||||
event.Str("allowed-commit", commit)
|
||||
}
|
||||
if pathAllowed {
|
||||
event.Bool("allowed-path", pathAllowed)
|
||||
}
|
||||
event.Msg("skipping file: rule allowlist")
|
||||
return findings
|
||||
}
|
||||
}
|
||||
|
||||
if r.Path != nil && r.Regex == nil && len(encodedSegments) == 0 {
|
||||
// Path _only_ rule
|
||||
if r.Path.MatchString(fragment.FilePath) {
|
||||
finding := report.Finding{
|
||||
Description: r.Description,
|
||||
File: fragment.FilePath,
|
||||
SymlinkFile: fragment.SymlinkFile,
|
||||
RuleID: r.RuleID,
|
||||
Match: fmt.Sprintf("file detected: %s", fragment.FilePath),
|
||||
Tags: r.Tags,
|
||||
if r.Path != nil {
|
||||
if r.Regex == nil && len(encodedSegments) == 0 {
|
||||
// Path _only_ rule
|
||||
if r.Path.MatchString(fragment.FilePath) || (fragment.WindowsFilePath != "" && r.Path.MatchString(fragment.WindowsFilePath)) {
|
||||
finding := report.Finding{
|
||||
RuleID: r.RuleID,
|
||||
Description: r.Description,
|
||||
File: fragment.FilePath,
|
||||
SymlinkFile: fragment.SymlinkFile,
|
||||
Match: fmt.Sprintf("file detected: %s", fragment.FilePath),
|
||||
Tags: r.Tags,
|
||||
}
|
||||
return append(findings, finding)
|
||||
}
|
||||
} else {
|
||||
// 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 !(r.Path.MatchString(fragment.FilePath) || (fragment.WindowsFilePath != "" && r.Path.MatchString(fragment.WindowsFilePath))) {
|
||||
return findings
|
||||
}
|
||||
return append(findings, finding)
|
||||
}
|
||||
} else if r.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 !r.Path.MatchString(fragment.FilePath) {
|
||||
return findings
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +367,10 @@ func (d *Detector) detectRule(fragment Fragment, currentRaw string, r config.Rul
|
||||
if d.MaxTargetMegaBytes > 0 {
|
||||
rawLength := len(currentRaw) / 1000000
|
||||
if rawLength > d.MaxTargetMegaBytes {
|
||||
logging.Debug().Msgf("skipping file: %s scan due to size: %d", fragment.FilePath, rawLength)
|
||||
logger.Debug().
|
||||
Int("size", rawLength).
|
||||
Int("max-size", d.MaxTargetMegaBytes).
|
||||
Msg("skipping fragment: size")
|
||||
return findings
|
||||
}
|
||||
}
|
||||
@@ -377,25 +412,24 @@ MatchLoop:
|
||||
}
|
||||
|
||||
finding := report.Finding{
|
||||
Description: r.Description,
|
||||
File: fragment.FilePath,
|
||||
SymlinkFile: fragment.SymlinkFile,
|
||||
RuleID: r.RuleID,
|
||||
Description: r.Description,
|
||||
StartLine: loc.startLine,
|
||||
EndLine: loc.endLine,
|
||||
StartColumn: loc.startColumn,
|
||||
EndColumn: loc.endColumn,
|
||||
Secret: secret,
|
||||
Match: secret,
|
||||
Tags: append(r.Tags, metaTags...),
|
||||
Line: fragment.Raw[loc.startLineIndex:loc.endLineIndex],
|
||||
Match: secret,
|
||||
Secret: secret,
|
||||
File: fragment.FilePath,
|
||||
SymlinkFile: fragment.SymlinkFile,
|
||||
Tags: append(r.Tags, metaTags...),
|
||||
}
|
||||
|
||||
if !d.IgnoreGitleaksAllow &&
|
||||
strings.Contains(fragment.Raw[loc.startLineIndex:loc.endLineIndex], gitleaksAllowSignature) {
|
||||
if !d.IgnoreGitleaksAllow && strings.Contains(finding.Line, gitleaksAllowSignature) {
|
||||
logger.Trace().
|
||||
Str("finding", finding.Secret).
|
||||
Msg("Skipping finding due to 'gitleaks:allow' signature")
|
||||
Msg("skipping finding: 'gitleaks:allow' signature")
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -424,11 +458,12 @@ MatchLoop:
|
||||
entropy := shannonEntropy(finding.Secret)
|
||||
finding.Entropy = float32(entropy)
|
||||
if r.Entropy != 0.0 {
|
||||
// entropy is too low, skip this finding
|
||||
if entropy <= r.Entropy {
|
||||
logger.Trace().
|
||||
Str("finding", finding.Secret).
|
||||
Float32("entropy", finding.Entropy).
|
||||
Msg("Skipping finding due to low entropy")
|
||||
// entropy is too low, skip this finding
|
||||
Msg("skipping finding: low entropy")
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -444,12 +479,13 @@ MatchLoop:
|
||||
if d.Config.Allowlist.RegexAllowed(globalAllowlistTarget) {
|
||||
logger.Trace().
|
||||
Str("finding", globalAllowlistTarget).
|
||||
Msg("Skipping finding due to global allowlist regex")
|
||||
Msg("skipping finding: global allowlist regex")
|
||||
continue
|
||||
} else if d.Config.Allowlist.ContainsStopWord(finding.Secret) {
|
||||
} else if ok, word := d.Config.Allowlist.ContainsStopWord(finding.Secret); ok {
|
||||
logger.Trace().
|
||||
Str("finding", finding.Secret).
|
||||
Msg("Skipping finding due to global allowlist stopword")
|
||||
Str("allowed-stopword", word).
|
||||
Msg("skipping finding: global allowlist stopword")
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -464,19 +500,24 @@ MatchLoop:
|
||||
}
|
||||
|
||||
var (
|
||||
isAllowed bool
|
||||
regexAllowed = a.RegexAllowed(allowlistTarget)
|
||||
containsStopword = a.ContainsStopWord(finding.Secret)
|
||||
isAllowed bool
|
||||
commitAllowed bool
|
||||
commit string
|
||||
pathAllowed bool
|
||||
regexAllowed = a.RegexAllowed(allowlistTarget)
|
||||
containsStopword, word = a.ContainsStopWord(finding.Secret)
|
||||
)
|
||||
// check if the secret is in the list of stopwords
|
||||
if a.MatchCondition == config.AllowlistMatchAnd {
|
||||
// Determine applicable checks.
|
||||
var allowlistChecks []bool
|
||||
if len(a.Commits) > 0 {
|
||||
allowlistChecks = append(allowlistChecks, a.CommitAllowed(fragment.CommitSHA))
|
||||
commitAllowed, commit = a.CommitAllowed(fragment.CommitSHA)
|
||||
allowlistChecks = append(allowlistChecks, commitAllowed)
|
||||
}
|
||||
if len(a.Paths) > 0 {
|
||||
allowlistChecks = append(allowlistChecks, a.PathAllowed(fragment.FilePath))
|
||||
pathAllowed = a.PathAllowed(fragment.FilePath) || (fragment.WindowsFilePath != "" && a.PathAllowed(fragment.WindowsFilePath))
|
||||
allowlistChecks = append(allowlistChecks, pathAllowed)
|
||||
}
|
||||
if len(a.Regexes) > 0 {
|
||||
allowlistChecks = append(allowlistChecks, regexAllowed)
|
||||
@@ -492,12 +533,22 @@ MatchLoop:
|
||||
}
|
||||
|
||||
if isAllowed {
|
||||
logger.Trace().
|
||||
event := logger.Trace().
|
||||
Str("finding", finding.Secret).
|
||||
Str("condition", a.MatchCondition.String()).
|
||||
Bool("regex-allowed", regexAllowed).
|
||||
Bool("contains-stopword", containsStopword).
|
||||
Msg("Skipping finding due to rule allowlist")
|
||||
Str("condition", a.MatchCondition.String())
|
||||
if commitAllowed {
|
||||
event.Str("allowed-commit", commit)
|
||||
}
|
||||
if pathAllowed {
|
||||
event.Bool("allowed-path", pathAllowed)
|
||||
}
|
||||
if regexAllowed {
|
||||
event.Bool("allowed-regex", regexAllowed)
|
||||
}
|
||||
if containsStopword {
|
||||
event.Str("allowed-stopword", word)
|
||||
}
|
||||
event.Msg("skipping finding: rule allowlist")
|
||||
continue MatchLoop
|
||||
}
|
||||
}
|
||||
@@ -527,21 +578,26 @@ func (d *Detector) addFinding(finding report.Finding) {
|
||||
}
|
||||
|
||||
// check if we should ignore this finding
|
||||
logger := logging.With().Str("finding", finding.Secret).Logger()
|
||||
if _, ok := d.gitleaksIgnore[globalFingerprint]; ok {
|
||||
logging.Debug().Msgf("ignoring finding with global Fingerprint %s",
|
||||
finding.Fingerprint)
|
||||
logger.Debug().
|
||||
Str("fingerprint", globalFingerprint).
|
||||
Msg("skipping finding: global fingerprint")
|
||||
return
|
||||
} else if finding.Commit != "" {
|
||||
// Awkward nested if because I'm not sure how to chain these two conditions.
|
||||
if _, ok := d.gitleaksIgnore[finding.Fingerprint]; ok {
|
||||
logging.Debug().Msgf("ignoring finding with Fingerprint %s",
|
||||
finding.Fingerprint)
|
||||
logger.Debug().
|
||||
Str("fingerprint", finding.Fingerprint).
|
||||
Msgf("skipping finding: fingerprint")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if d.baseline != nil && !IsNew(finding, d.baseline) {
|
||||
logging.Debug().Msgf("baseline duplicate -- ignoring finding with Fingerprint %s", finding.Fingerprint)
|
||||
logger.Debug().
|
||||
Str("fingerprint", finding.Fingerprint).
|
||||
Msgf("skipping finding: baseline")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+440
-72
@@ -4,16 +4,21 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/scm"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/regexp"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
"github.com/zricethezav/gitleaks/v8/sources"
|
||||
)
|
||||
@@ -495,6 +500,12 @@ func TestDetect(t *testing.T) {
|
||||
|
||||
// TestFromGit tests the FromGit function
|
||||
func TestFromGit(t *testing.T) {
|
||||
// TODO: Fix this test on windows.
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skipf("TODO: this fails on Windows: [git] fatal: bad object refs/remotes/origin/main?")
|
||||
return
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
source string
|
||||
@@ -503,9 +514,10 @@ func TestFromGit(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
source: filepath.Join(repoBasePath, "small"),
|
||||
cfgName: "simple",
|
||||
cfgName: "simple", // the remote url is `git@github.com:gitleaks/test.git`
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
RuleID: "aws-access-key",
|
||||
Description: "AWS Access Key",
|
||||
StartLine: 20,
|
||||
EndLine: 20,
|
||||
@@ -514,18 +526,19 @@ func TestFromGit(t *testing.T) {
|
||||
Line: "\n awsToken := \"AKIALALEMEL33243OLIA\"",
|
||||
Secret: "AKIALALEMEL33243OLIA",
|
||||
Match: "AKIALALEMEL33243OLIA",
|
||||
Entropy: 3.0841837,
|
||||
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,
|
||||
Fingerprint: "1b6da43b82b22e4eaa10bcf8ee591e91abbfc587:main.go:aws-access-key:20",
|
||||
Link: "https://github.com/gitleaks/test/blob/1b6da43b82b22e4eaa10bcf8ee591e91abbfc587/main.go#L20",
|
||||
},
|
||||
{
|
||||
RuleID: "aws-access-key",
|
||||
Description: "AWS Access Key",
|
||||
StartLine: 9,
|
||||
EndLine: 9,
|
||||
@@ -540,10 +553,10 @@ func TestFromGit(t *testing.T) {
|
||||
Author: "Zach Rice",
|
||||
Email: "zricer@protonmail.com",
|
||||
Message: "adding foo package with secret",
|
||||
RuleID: "aws-access-key",
|
||||
Tags: []string{"key", "AWS"},
|
||||
Entropy: 3.0841837,
|
||||
Fingerprint: "491504d5a31946ce75e22554cc34203d8e5ff3ca:foo/foo.go:aws-access-key:9",
|
||||
Link: "https://github.com/gitleaks/test/blob/491504d5a31946ce75e22554cc34203d8e5ff3ca/foo/foo.go#L9",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -553,6 +566,7 @@ func TestFromGit(t *testing.T) {
|
||||
cfgName: "simple",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
RuleID: "aws-access-key",
|
||||
Description: "AWS Access Key",
|
||||
StartLine: 9,
|
||||
EndLine: 9,
|
||||
@@ -567,10 +581,10 @@ func TestFromGit(t *testing.T) {
|
||||
Author: "Zach Rice",
|
||||
Email: "zricer@protonmail.com",
|
||||
Message: "adding foo package with secret",
|
||||
RuleID: "aws-access-key",
|
||||
Tags: []string{"key", "AWS"},
|
||||
Entropy: 3.0841837,
|
||||
Fingerprint: "491504d5a31946ce75e22554cc34203d8e5ff3ca:foo/foo.go:aws-access-key:9",
|
||||
Link: "https://github.com/gitleaks/test/blob/491504d5a31946ce75e22554cc34203d8e5ff3ca/foo/foo.go#L9",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -580,43 +594,47 @@ func TestFromGit(t *testing.T) {
|
||||
defer moveDotGit(t, ".git", "dotGit")
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(strings.Join([]string{tt.cfgName, tt.source, tt.logOpts}, "/"), func(t *testing.T) {
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName("simple")
|
||||
viper.SetConfigType("toml")
|
||||
err := viper.ReadInConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName("simple")
|
||||
viper.SetConfigType("toml")
|
||||
err := viper.ReadInConfig()
|
||||
require.NoError(t, err)
|
||||
var vc config.ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
cfg, err := vc.Translate()
|
||||
require.NoError(t, err)
|
||||
detector := NewDetector(cfg)
|
||||
|
||||
var vc config.ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
cfg, err := vc.Translate()
|
||||
require.NoError(t, err)
|
||||
detector := NewDetector(cfg)
|
||||
var ignorePath string
|
||||
info, err := os.Stat(tt.source)
|
||||
require.NoError(t, err)
|
||||
|
||||
var ignorePath string
|
||||
info, err := os.Stat(tt.source)
|
||||
require.NoError(t, err)
|
||||
if info.IsDir() {
|
||||
ignorePath = filepath.Join(tt.source, ".gitleaksignore")
|
||||
} else {
|
||||
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
|
||||
}
|
||||
err = detector.AddGitleaksIgnore(ignorePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
if info.IsDir() {
|
||||
ignorePath = filepath.Join(tt.source, ".gitleaksignore")
|
||||
} else {
|
||||
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
|
||||
}
|
||||
err = detector.AddGitleaksIgnore(ignorePath)
|
||||
require.NoError(t, err)
|
||||
gitCmd, err := sources.NewGitLogCmd(tt.source, tt.logOpts)
|
||||
require.NoError(t, err)
|
||||
|
||||
gitCmd, err := sources.NewGitLogCmd(tt.source, tt.logOpts)
|
||||
require.NoError(t, err)
|
||||
findings, err := detector.DetectGit(gitCmd)
|
||||
require.NoError(t, err)
|
||||
remote := NewRemoteInfo(scm.UnknownPlatform, tt.source)
|
||||
findings, err := detector.DetectGit(gitCmd, remote)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, f := range findings {
|
||||
f.Match = "" // remove lines cause copying and pasting them has some wack formatting
|
||||
}
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
for _, f := range findings {
|
||||
f.Match = "" // remove lines cause copying and pasting them has some wack formatting
|
||||
}
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromGitStaged(t *testing.T) {
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
@@ -629,6 +647,7 @@ func TestFromGitStaged(t *testing.T) {
|
||||
cfgName: "simple",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
RuleID: "aws-access-key",
|
||||
Description: "AWS Access Key",
|
||||
StartLine: 7,
|
||||
EndLine: 7,
|
||||
@@ -649,8 +668,8 @@ func TestFromGitStaged(t *testing.T) {
|
||||
"key",
|
||||
"AWS",
|
||||
},
|
||||
RuleID: "aws-access-key",
|
||||
Fingerprint: "api/api.go:aws-access-key:7",
|
||||
Link: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -658,7 +677,6 @@ func TestFromGitStaged(t *testing.T) {
|
||||
|
||||
moveDotGit(t, "dotGit", ".git")
|
||||
defer moveDotGit(t, ".git", "dotGit")
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
viper.AddConfigPath(configPath)
|
||||
@@ -677,7 +695,8 @@ func TestFromGitStaged(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
gitCmd, err := sources.NewGitDiffCmd(tt.source, true)
|
||||
require.NoError(t, err)
|
||||
findings, err := detector.DetectGit(gitCmd)
|
||||
remote := NewRemoteInfo(scm.UnknownPlatform, tt.source)
|
||||
findings, err := detector.DetectGit(gitCmd, remote)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, f := range findings {
|
||||
@@ -699,17 +718,17 @@ func TestFromFiles(t *testing.T) {
|
||||
cfgName: "simple",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
RuleID: "aws-access-key",
|
||||
Description: "AWS Access Key",
|
||||
StartLine: 20,
|
||||
EndLine: 20,
|
||||
StartColumn: 16,
|
||||
EndColumn: 35,
|
||||
Line: "\n\tawsToken := \"AKIALALEMEL33243OLIA\"",
|
||||
Match: "AKIALALEMEL33243OLIA",
|
||||
Secret: "AKIALALEMEL33243OLIA",
|
||||
Line: "\n\tawsToken := \"AKIALALEMEL33243OLIA\"",
|
||||
File: "../testdata/repos/nogit/main.go",
|
||||
SymlinkFile: "",
|
||||
RuleID: "aws-access-key",
|
||||
Tags: []string{"key", "AWS"},
|
||||
Entropy: 3.0841837,
|
||||
Fingerprint: "../testdata/repos/nogit/main.go:aws-access-key:20",
|
||||
@@ -721,16 +740,16 @@ func TestFromFiles(t *testing.T) {
|
||||
cfgName: "simple",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
RuleID: "aws-access-key",
|
||||
Description: "AWS Access Key",
|
||||
StartLine: 20,
|
||||
EndLine: 20,
|
||||
StartColumn: 16,
|
||||
EndColumn: 35,
|
||||
Line: "\n\tawsToken := \"AKIALALEMEL33243OLIA\"",
|
||||
Match: "AKIALALEMEL33243OLIA",
|
||||
Secret: "AKIALALEMEL33243OLIA",
|
||||
Line: "\n\tawsToken := \"AKIALALEMEL33243OLIA\"",
|
||||
File: "../testdata/repos/nogit/main.go",
|
||||
RuleID: "aws-access-key",
|
||||
Tags: []string{"key", "AWS"},
|
||||
Entropy: 3.0841837,
|
||||
Fingerprint: "../testdata/repos/nogit/main.go:aws-access-key:20",
|
||||
@@ -747,16 +766,16 @@ func TestFromFiles(t *testing.T) {
|
||||
cfgName: "generic",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
RuleID: "generic-api-key",
|
||||
Description: "Generic API Key",
|
||||
StartLine: 4,
|
||||
EndLine: 4,
|
||||
StartColumn: 5,
|
||||
EndColumn: 35,
|
||||
Line: "\nDB_PASSWORD=8ae31cacf141669ddfb5da",
|
||||
Match: "PASSWORD=8ae31cacf141669ddfb5da",
|
||||
Secret: "8ae31cacf141669ddfb5da",
|
||||
Line: "\nDB_PASSWORD=8ae31cacf141669ddfb5da",
|
||||
File: "../testdata/repos/nogit/.env.prod",
|
||||
RuleID: "generic-api-key",
|
||||
Tags: []string{},
|
||||
Entropy: 3.5383105,
|
||||
Fingerprint: "../testdata/repos/nogit/.env.prod:generic-api-key:4",
|
||||
@@ -766,39 +785,64 @@ func TestFromFiles(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName(tt.cfgName)
|
||||
viper.SetConfigType("toml")
|
||||
err := viper.ReadInConfig()
|
||||
require.NoError(t, err)
|
||||
t.Run(tt.cfgName+" - "+tt.source, func(t *testing.T) {
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName(tt.cfgName)
|
||||
viper.SetConfigType("toml")
|
||||
err := viper.ReadInConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
var vc config.ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
cfg, _ := vc.Translate()
|
||||
detector := NewDetector(cfg)
|
||||
var vc config.ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
|
||||
var ignorePath string
|
||||
info, err := os.Stat(tt.source)
|
||||
require.NoError(t, err)
|
||||
cfg, _ := vc.Translate()
|
||||
detector := NewDetector(cfg)
|
||||
|
||||
if info.IsDir() {
|
||||
ignorePath = filepath.Join(tt.source, ".gitleaksignore")
|
||||
} else {
|
||||
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
|
||||
}
|
||||
err = detector.AddGitleaksIgnore(ignorePath)
|
||||
require.NoError(t, err)
|
||||
detector.FollowSymlinks = true
|
||||
paths, err := sources.DirectoryTargets(tt.source, detector.Sema, true, cfg.Allowlist.PathAllowed)
|
||||
require.NoError(t, err)
|
||||
findings, err := detector.DetectFiles(paths)
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
info, err := os.Stat(tt.source)
|
||||
require.NoError(t, err)
|
||||
|
||||
var ignorePath string
|
||||
if info.IsDir() {
|
||||
ignorePath = filepath.Join(tt.source, ".gitleaksignore")
|
||||
} else {
|
||||
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
|
||||
}
|
||||
err = detector.AddGitleaksIgnore(ignorePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
detector.FollowSymlinks = true
|
||||
paths, err := sources.DirectoryTargets(tt.source, detector.Sema, true, cfg.Allowlist.PathAllowed)
|
||||
require.NoError(t, err)
|
||||
|
||||
findings, err := detector.DetectFiles(paths)
|
||||
require.NoError(t, err)
|
||||
|
||||
// TODO: Temporary mitigation.
|
||||
// https://github.com/gitleaks/gitleaks/issues/1641
|
||||
normalizedFindings := make([]report.Finding, len(findings))
|
||||
for i, f := range findings {
|
||||
if strings.HasSuffix(f.Line, "\r") {
|
||||
f.Line = strings.ReplaceAll(f.Line, "\r", "")
|
||||
}
|
||||
if strings.HasSuffix(f.Match, "\r") {
|
||||
f.EndColumn = f.EndColumn - 1
|
||||
f.Match = strings.ReplaceAll(f.Match, "\r", "")
|
||||
}
|
||||
normalizedFindings[i] = f
|
||||
}
|
||||
assert.ElementsMatch(t, tt.expectedFindings, normalizedFindings)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectWithSymlinks(t *testing.T) {
|
||||
// TODO: Fix this test on windows.
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skipf("TODO: this returns no results on windows, I'm not sure why.")
|
||||
return
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
source string
|
||||
@@ -809,6 +853,7 @@ func TestDetectWithSymlinks(t *testing.T) {
|
||||
cfgName: "simple",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
RuleID: "apkey",
|
||||
Description: "Asymmetric Private Key",
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
@@ -819,7 +864,6 @@ func TestDetectWithSymlinks(t *testing.T) {
|
||||
Line: "-----BEGIN OPENSSH PRIVATE KEY-----",
|
||||
File: "../testdata/repos/symlinks/source_file/id_ed25519",
|
||||
SymlinkFile: "../testdata/repos/symlinks/file_symlink/symlinked_id_ed25519",
|
||||
RuleID: "apkey",
|
||||
Tags: []string{"key", "AsymmetricPrivateKey"},
|
||||
Entropy: 3.587164,
|
||||
Fingerprint: "../testdata/repos/symlinks/source_file/id_ed25519:apkey:1",
|
||||
@@ -838,11 +882,13 @@ func TestDetectWithSymlinks(t *testing.T) {
|
||||
var vc config.ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, _ := vc.Translate()
|
||||
detector := NewDetector(cfg)
|
||||
detector.FollowSymlinks = true
|
||||
paths, err := sources.DirectoryTargets(tt.source, detector.Sema, true, cfg.Allowlist.PathAllowed)
|
||||
require.NoError(t, err)
|
||||
|
||||
findings, err := detector.DetectFiles(paths)
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
@@ -1107,3 +1153,325 @@ func moveDotGit(t *testing.T, from, to string) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
// region Windows-specific tests[]
|
||||
func TestNormalizeGitleaksIgnorePaths(t *testing.T) {
|
||||
d, err := NewDetectorDefaultConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = d.AddGitleaksIgnore("../testdata/gitleaksignore/.windowspaths")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, d.gitleaksIgnore, 3)
|
||||
expected := map[string]struct{}{
|
||||
"foo/bar/gitleaks-false-positive.yaml:aws-access-token:4": {},
|
||||
"foo/bar/gitleaks-false-positive.yaml:aws-access-token:5": {},
|
||||
"b55d88dc151f7022901cda41a03d43e0e508f2b7:test_data/test_local_repo_three_leaks.json:aws-access-token:73": {},
|
||||
}
|
||||
assert.ElementsMatch(t, maps.Keys(d.gitleaksIgnore), maps.Keys(expected))
|
||||
}
|
||||
|
||||
func TestWindowsFileSeparator_RulePath(t *testing.T) {
|
||||
logging.Logger = logging.Logger.Level(zerolog.TraceLevel)
|
||||
unixRule := config.Rule{
|
||||
RuleID: "test-rule",
|
||||
Path: regexp.MustCompile(`(^|/)\.m2/settings\.xml`),
|
||||
}
|
||||
windowsRule := config.Rule{
|
||||
RuleID: "test-rule",
|
||||
Path: regexp.MustCompile(`(^|\\)\.m2\\settings\.xml`),
|
||||
}
|
||||
expected := []report.Finding{
|
||||
{
|
||||
RuleID: "test-rule",
|
||||
Match: "file detected: .m2/settings.xml",
|
||||
File: ".m2/settings.xml",
|
||||
},
|
||||
}
|
||||
tests := map[string]struct {
|
||||
fragment Fragment
|
||||
rule config.Rule
|
||||
expected []report.Finding
|
||||
}{
|
||||
// unix rule
|
||||
"unix rule - unix path separator": {
|
||||
fragment: Fragment{
|
||||
FilePath: `.m2/settings.xml`,
|
||||
},
|
||||
rule: unixRule,
|
||||
expected: expected,
|
||||
},
|
||||
"unix rule - windows path separator": {
|
||||
fragment: Fragment{
|
||||
FilePath: `.m2/settings.xml`,
|
||||
WindowsFilePath: `.m2\settings.xml`,
|
||||
},
|
||||
rule: unixRule,
|
||||
expected: expected,
|
||||
},
|
||||
"unix regex+path rule - windows path separator": {
|
||||
fragment: Fragment{
|
||||
Raw: `<password>s3cr3t</password>`,
|
||||
FilePath: `.m2/settings.xml`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "test-rule",
|
||||
Regex: regexp.MustCompile(`<password>(.+?)</password>`),
|
||||
Path: regexp.MustCompile(`(^|/)\.m2/settings\.xml`),
|
||||
},
|
||||
expected: []report.Finding{
|
||||
{
|
||||
RuleID: "test-rule",
|
||||
StartColumn: 1,
|
||||
EndColumn: 27,
|
||||
Line: "<password>s3cr3t</password>",
|
||||
Match: "<password>s3cr3t</password>",
|
||||
Secret: "s3cr3t",
|
||||
Entropy: 2.251629114151001,
|
||||
File: ".m2/settings.xml",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// windows rule
|
||||
"windows rule - unix path separator": {
|
||||
fragment: Fragment{
|
||||
FilePath: `.m2/settings.xml`,
|
||||
},
|
||||
rule: windowsRule,
|
||||
// This never worked, and continues not to work.
|
||||
// Paths should be normalized to use Unix file separators.
|
||||
expected: nil,
|
||||
},
|
||||
"windows rule - windows path separator": {
|
||||
fragment: Fragment{
|
||||
FilePath: `.m2/settings.xml`,
|
||||
WindowsFilePath: `.m2\settings.xml`,
|
||||
},
|
||||
rule: windowsRule,
|
||||
expected: expected,
|
||||
},
|
||||
"windows regex+path rule - windows path separator": {
|
||||
fragment: Fragment{
|
||||
Raw: `<password>s3cr3t</password>`,
|
||||
FilePath: `.m2/settings.xml`,
|
||||
WindowsFilePath: `.m2\settings.xml`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "test-rule",
|
||||
Regex: regexp.MustCompile(`<password>(.+?)</password>`),
|
||||
Path: regexp.MustCompile(`(^|\\)\.m2\\settings\.xml`),
|
||||
},
|
||||
expected: []report.Finding{
|
||||
{
|
||||
RuleID: "test-rule",
|
||||
StartColumn: 1,
|
||||
EndColumn: 27,
|
||||
Line: "<password>s3cr3t</password>",
|
||||
Match: "<password>s3cr3t</password>",
|
||||
Secret: "s3cr3t",
|
||||
Entropy: 2.251629114151001,
|
||||
File: ".m2/settings.xml",
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
d, err := NewDetectorDefaultConfig()
|
||||
require.NoError(t, err)
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
actual := d.detectRule(test.fragment, test.fragment.Raw, test.rule, []EncodedSegment{})
|
||||
if diff := cmp.Diff(test.expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-want +got)\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWindowsFileSeparator_RuleAllowlistPaths(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
fragment Fragment
|
||||
rule config.Rule
|
||||
expected []report.Finding
|
||||
}{
|
||||
// unix
|
||||
"unix path separator - unix rule - OR allowlist path-only": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "s3cr3t"`,
|
||||
FilePath: `ignoreme/unix.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "unix-rule",
|
||||
Regex: regexp.MustCompile(`s3cr3t`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|/)ignoreme(/.*)?$`)},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
"unix path separator - windows rule - OR allowlist path-only": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "s3cr3t"`,
|
||||
FilePath: `ignoreme/unix.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "windows-rule",
|
||||
Regex: regexp.MustCompile(`s3cr3t`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|\\)ignoreme(\\.*)?$`)},
|
||||
},
|
||||
},
|
||||
},
|
||||
// Windows separators in regex don't work for unix.
|
||||
expected: []report.Finding{
|
||||
{
|
||||
RuleID: "windows-rule",
|
||||
StartColumn: 9,
|
||||
EndColumn: 14,
|
||||
Line: `value: "s3cr3t"`,
|
||||
Match: `s3cr3t`,
|
||||
Secret: `s3cr3t`,
|
||||
File: "ignoreme/unix.txt",
|
||||
Entropy: 2.251629114151001,
|
||||
},
|
||||
},
|
||||
},
|
||||
"unix path separator - unix rule - AND allowlist path+stopwords": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "f4k3s3cr3t"`,
|
||||
FilePath: `ignoreme/unix.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "unix-rule",
|
||||
Regex: regexp.MustCompile(`value: "[^"]+"`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
MatchCondition: config.AllowlistMatchAnd,
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|/)ignoreme(/.*)?$`)},
|
||||
StopWords: []string{"f4k3"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
"unix path separator - windows rule - AND allowlist path+stopwords": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "f4k3s3cr3t"`,
|
||||
FilePath: `ignoreme/unix.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "windows-rule",
|
||||
Regex: regexp.MustCompile(`value: "[^"]+"`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
MatchCondition: config.AllowlistMatchAnd,
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|\\)ignoreme(\\.*)?$`)},
|
||||
StopWords: []string{"f4k3"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: []report.Finding{
|
||||
{
|
||||
RuleID: "windows-rule",
|
||||
StartColumn: 1,
|
||||
EndColumn: 19,
|
||||
Line: `value: "f4k3s3cr3t"`,
|
||||
Match: `value: "f4k3s3cr3t"`,
|
||||
Secret: `value: "f4k3s3cr3t"`,
|
||||
File: "ignoreme/unix.txt",
|
||||
Entropy: 3.892407178878784,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// windows
|
||||
"windows path separator - unix rule - OR allowlist path-only": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "s3cr3t"`,
|
||||
FilePath: `ignoreme/windows.txt`,
|
||||
WindowsFilePath: `ignoreme\windows.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "unix-rule",
|
||||
Regex: regexp.MustCompile(`s3cr3t`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|/)ignoreme(/.*)?$`)},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
"windows path separator - windows rule - OR allowlist path-only": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "s3cr3t"`,
|
||||
FilePath: `ignoreme/windows.txt`,
|
||||
WindowsFilePath: `ignoreme\windows.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "windows-rule",
|
||||
Regex: regexp.MustCompile(`s3cr3t`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|\\)ignoreme(\\.*)?$`)},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
"windows path separator - unix rule - AND allowlist path+stopwords": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "f4k3s3cr3t"`,
|
||||
FilePath: `ignoreme/unix.txt`,
|
||||
WindowsFilePath: `ignoreme\windows.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "unix-rule",
|
||||
Regex: regexp.MustCompile(`value: "[^"]+"`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
MatchCondition: config.AllowlistMatchAnd,
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|/)ignoreme(/.*)?$`)},
|
||||
StopWords: []string{"f4k3"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
"windows path separator - windows rule - AND allowlist path+stopwords": {
|
||||
fragment: Fragment{
|
||||
Raw: `value: "f4k3s3cr3t"`,
|
||||
FilePath: `ignoreme/unix.txt`,
|
||||
WindowsFilePath: `ignoreme\windows.txt`,
|
||||
},
|
||||
rule: config.Rule{
|
||||
RuleID: "windows-rule",
|
||||
Regex: regexp.MustCompile(`value: "[^"]+"`),
|
||||
Allowlists: []config.Allowlist{
|
||||
{
|
||||
MatchCondition: config.AllowlistMatchAnd,
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`(^|\\)ignoreme(\\.*)?$`)},
|
||||
StopWords: []string{"f4k3"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
}
|
||||
|
||||
d, err := NewDetectorDefaultConfig()
|
||||
require.NoError(t, err)
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
actual := d.detectRule(test.fragment, test.fragment.Raw, test.rule, []EncodedSegment{})
|
||||
if diff := cmp.Diff(test.expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-want +got)\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
+11
-3
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/h2non/filetype"
|
||||
@@ -83,13 +84,20 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
|
||||
linesInChunk := strings.Count(chunk, "\n")
|
||||
totalLines += linesInChunk
|
||||
fragment := Fragment{
|
||||
Raw: chunk,
|
||||
Bytes: peekBuf.Bytes(),
|
||||
FilePath: pa.Path,
|
||||
Raw: chunk,
|
||||
Bytes: peekBuf.Bytes(),
|
||||
}
|
||||
if pa.Symlink != "" {
|
||||
fragment.SymlinkFile = pa.Symlink
|
||||
}
|
||||
if isWindows {
|
||||
fragment.FilePath = filepath.ToSlash(pa.Path)
|
||||
fragment.SymlinkFile = filepath.ToSlash(fragment.SymlinkFile)
|
||||
fragment.WindowsFilePath = pa.Path
|
||||
} else {
|
||||
fragment.FilePath = pa.Path
|
||||
}
|
||||
|
||||
for _, finding := range d.Detect(fragment) {
|
||||
// need to add 1 since line counting starts at 1
|
||||
finding.StartLine += (totalLines - linesInChunk) + 1
|
||||
|
||||
+109
-6
@@ -1,17 +1,28 @@
|
||||
package detect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/scm"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
"github.com/zricethezav/gitleaks/v8/sources"
|
||||
)
|
||||
|
||||
func (d *Detector) DetectGit(gitCmd *sources.GitCmd) ([]report.Finding, error) {
|
||||
defer gitCmd.Wait()
|
||||
diffFilesCh := gitCmd.DiffFilesCh()
|
||||
errCh := gitCmd.ErrCh()
|
||||
func (d *Detector) DetectGit(cmd *sources.GitCmd, remote *RemoteInfo) ([]report.Finding, error) {
|
||||
defer cmd.Wait()
|
||||
var (
|
||||
diffFilesCh = cmd.DiffFilesCh()
|
||||
errCh = cmd.ErrCh()
|
||||
)
|
||||
|
||||
// loop to range over both DiffFiles (stdout) and ErrCh (stderr)
|
||||
for diffFilesCh != nil || errCh != nil {
|
||||
@@ -31,7 +42,8 @@ func (d *Detector) DetectGit(gitCmd *sources.GitCmd) ([]report.Finding, error) {
|
||||
commitSHA := ""
|
||||
if gitdiffFile.PatchHeader != nil {
|
||||
commitSHA = gitdiffFile.PatchHeader.SHA
|
||||
if d.Config.Allowlist.CommitAllowed(gitdiffFile.PatchHeader.SHA) {
|
||||
if ok, c := d.Config.Allowlist.CommitAllowed(gitdiffFile.PatchHeader.SHA); ok {
|
||||
logging.Trace().Str("allowed-commit", c).Msg("skipping commit: global allowlist")
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -50,7 +62,7 @@ func (d *Detector) DetectGit(gitCmd *sources.GitCmd) ([]report.Finding, error) {
|
||||
}
|
||||
|
||||
for _, finding := range d.Detect(fragment) {
|
||||
d.addFinding(augmentGitFinding(finding, textFragment, gitdiffFile))
|
||||
d.addFinding(augmentGitFinding(remote, finding, textFragment, gitdiffFile))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -72,3 +84,94 @@ func (d *Detector) DetectGit(gitCmd *sources.GitCmd) ([]report.Finding, error) {
|
||||
logging.Debug().Msg("Note: this number might be smaller than expected due to commits with no additions")
|
||||
return d.findings, nil
|
||||
}
|
||||
|
||||
type RemoteInfo struct {
|
||||
Platform scm.Platform
|
||||
Url string
|
||||
}
|
||||
|
||||
func NewRemoteInfo(platform scm.Platform, source string) *RemoteInfo {
|
||||
if platform == scm.NoPlatform {
|
||||
return &RemoteInfo{Platform: platform}
|
||||
}
|
||||
|
||||
remoteUrl, err := getRemoteUrl(source)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "No remote configured") {
|
||||
logging.Debug().Msg("skipping finding links: repository has no configured remote.")
|
||||
platform = scm.NoPlatform
|
||||
} else {
|
||||
logging.Error().Err(err).Msg("skipping finding links: unable to parse remote URL")
|
||||
}
|
||||
goto End
|
||||
}
|
||||
|
||||
if platform == scm.UnknownPlatform {
|
||||
platform = platformFromHost(remoteUrl)
|
||||
if platform == scm.UnknownPlatform {
|
||||
logging.Info().
|
||||
Str("host", remoteUrl.Hostname()).
|
||||
Msg("Unknown SCM platform. Use --platform to include links in findings.")
|
||||
} else {
|
||||
logging.Debug().
|
||||
Str("host", remoteUrl.Hostname()).
|
||||
Str("platform", platform.String()).
|
||||
Msg("SCM platform parsed from host")
|
||||
}
|
||||
}
|
||||
|
||||
End:
|
||||
var rUrl string
|
||||
if remoteUrl != nil {
|
||||
rUrl = remoteUrl.String()
|
||||
}
|
||||
return &RemoteInfo{
|
||||
Platform: platform,
|
||||
Url: rUrl,
|
||||
}
|
||||
}
|
||||
|
||||
var sshUrlpat = regexp.MustCompile(`^git@([a-zA-Z0-9.-]+):([\w/.-]+?)(?:\.git)?$`)
|
||||
|
||||
func getRemoteUrl(source string) (*url.URL, error) {
|
||||
// This will return the first remote — typically, "origin".
|
||||
cmd := exec.Command("git", "ls-remote", "--quiet", "--get-url")
|
||||
if source != "." {
|
||||
cmd.Dir = source
|
||||
}
|
||||
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
var exitError *exec.ExitError
|
||||
if errors.As(err, &exitError) {
|
||||
return nil, fmt.Errorf("command failed (%d): %w, stderr: %s", exitError.ExitCode(), err, string(bytes.TrimSpace(exitError.Stderr)))
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
remoteUrl := string(bytes.TrimSpace(stdout))
|
||||
if matches := sshUrlpat.FindStringSubmatch(remoteUrl); matches != nil {
|
||||
remoteUrl = fmt.Sprintf("https://%s/%s", matches[1], matches[2])
|
||||
}
|
||||
remoteUrl = strings.TrimSuffix(remoteUrl, ".git")
|
||||
|
||||
parsedUrl, err := url.Parse(remoteUrl)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse remote URL: %w", err)
|
||||
}
|
||||
|
||||
// Remove any user info.
|
||||
parsedUrl.User = nil
|
||||
return parsedUrl, nil
|
||||
}
|
||||
|
||||
func platformFromHost(u *url.URL) scm.Platform {
|
||||
switch strings.ToLower(u.Hostname()) {
|
||||
case "github.com":
|
||||
return scm.GitHubPlatform
|
||||
case "gitlab.com":
|
||||
return scm.GitLabPlatform
|
||||
default:
|
||||
return scm.UnknownPlatform
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package detect
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
@@ -47,3 +48,80 @@ func (d *Detector) DetectReader(r io.Reader, bufSize int) ([]report.Finding, err
|
||||
|
||||
return findings, nil
|
||||
}
|
||||
|
||||
// StreamDetectReader streams the detection results from the provided io.Reader.
|
||||
// It reads data using the specified buffer size (in KB) and processes each chunk through
|
||||
// the existing detection logic. Findings are sent down the returned findings channel as soon as
|
||||
// they are detected, while a separate error channel signals a terminal error (or nil upon successful completion).
|
||||
// The function returns two channels:
|
||||
// - findingsCh: a receive-only channel that emits report.Finding objects as they are found.
|
||||
// - errCh: a receive-only channel that emits a single final error (or nil if no error occurred)
|
||||
// once the stream ends.
|
||||
//
|
||||
// Recommended Usage:
|
||||
//
|
||||
// Since there will only ever be a single value on the errCh, it is recommended to consume the findingsCh
|
||||
// first. Once findingsCh is closed, the consumer should then read from errCh to determine
|
||||
// if the stream completed successfully or if an error occurred.
|
||||
//
|
||||
// This design avoids the need for a select loop, keeping client code simple.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // Assume detector is an instance of *Detector and myReader implements io.Reader.
|
||||
// findingsCh, errCh := detector.StreamDetectReader(myReader, 64) // using 64 KB buffer size
|
||||
//
|
||||
// // Process findings as they arrive.
|
||||
// for finding := range findingsCh {
|
||||
// fmt.Printf("Found secret: %+v\n", finding)
|
||||
// }
|
||||
//
|
||||
// // After the findings channel is closed, check the final error.
|
||||
// if err := <-errCh; err != nil {
|
||||
// log.Fatalf("StreamDetectReader encountered an error: %v", err)
|
||||
// } else {
|
||||
// fmt.Println("Scanning completed successfully.")
|
||||
// }
|
||||
func (d *Detector) StreamDetectReader(r io.Reader, bufSize int) (<-chan report.Finding, <-chan error) {
|
||||
findingsCh := make(chan report.Finding, 1)
|
||||
errCh := make(chan error, 1)
|
||||
|
||||
go func() {
|
||||
defer close(findingsCh)
|
||||
defer close(errCh)
|
||||
|
||||
reader := bufio.NewReader(r)
|
||||
buf := make([]byte, 1000*bufSize)
|
||||
|
||||
for {
|
||||
n, err := reader.Read(buf)
|
||||
|
||||
if n > 0 {
|
||||
peekBuf := bytes.NewBuffer(buf[:n])
|
||||
if readErr := readUntilSafeBoundary(reader, n, maxPeekSize, peekBuf); readErr != nil {
|
||||
errCh <- readErr
|
||||
return
|
||||
}
|
||||
|
||||
fragment := Fragment{Raw: peekBuf.String()}
|
||||
for _, finding := range d.Detect(fragment) {
|
||||
findingsCh <- finding
|
||||
if d.Verbose {
|
||||
printFinding(finding, d.NoColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
errCh <- nil
|
||||
return
|
||||
}
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return findingsCh, errCh
|
||||
}
|
||||
+97
-2
@@ -1,13 +1,16 @@
|
||||
package detect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing/iotest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
)
|
||||
|
||||
const secret = "AKIAIRYLJVKMPEGZMPJS"
|
||||
@@ -15,6 +18,8 @@ const secret = "AKIAIRYLJVKMPEGZMPJS"
|
||||
type mockReader struct {
|
||||
data []byte
|
||||
read bool
|
||||
|
||||
errToReturn error
|
||||
}
|
||||
|
||||
func (r *mockReader) Read(p []byte) (n int, err error) {
|
||||
@@ -25,6 +30,9 @@ func (r *mockReader) Read(p []byte) (n int, err error) {
|
||||
// Copy data to the provided buffer.
|
||||
n = copy(p, r.data)
|
||||
r.read = true
|
||||
if r.errToReturn != nil {
|
||||
return n, r.errToReturn
|
||||
}
|
||||
|
||||
// Return io.EOF along with the bytes.
|
||||
return n, io.EOF
|
||||
@@ -66,3 +74,90 @@ func TestDetectReader(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamDetectReader(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
reader io.Reader
|
||||
bufSize int
|
||||
expectedCount int
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
name: "Single secret streaming",
|
||||
bufSize: 10,
|
||||
expectedCount: 1,
|
||||
reader: strings.NewReader(secret),
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "Empty reader",
|
||||
bufSize: 10,
|
||||
expectedCount: 0,
|
||||
reader: strings.NewReader(""),
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "Reader returns error",
|
||||
bufSize: 10,
|
||||
expectedCount: 0,
|
||||
reader: iotest.ErrReader(errors.New("simulated read error")),
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
name: "Multiple secrets with larger buffer",
|
||||
bufSize: 20,
|
||||
expectedCount: 2,
|
||||
reader: strings.NewReader(secret + "\n" + secret),
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "Mock reader with EOF",
|
||||
bufSize: 10,
|
||||
expectedCount: 1,
|
||||
reader: &mockReader{data: []byte(secret)},
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "Secret split across boundary",
|
||||
bufSize: 1, // 1KB buffer forces multiple reads
|
||||
expectedCount: 1,
|
||||
reader: io.MultiReader(
|
||||
strings.NewReader(secret[:len(secret)/2]),
|
||||
strings.NewReader(secret[len(secret)/2:])),
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "Reader returns error after first read",
|
||||
bufSize: 1,
|
||||
expectedCount: 0,
|
||||
reader: &mockReader{
|
||||
data: append(bytes.Repeat([]byte("blah"), 1000), []byte(secret)...),
|
||||
errToReturn: errors.New("simulated read error"),
|
||||
},
|
||||
expectError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
detector, err := NewDetectorDefaultConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
findingsCh, errCh := detector.StreamDetectReader(test.reader, test.bufSize)
|
||||
var findings []report.Finding
|
||||
for f := range findingsCh {
|
||||
findings = append(findings, f)
|
||||
}
|
||||
finalErr := <-errCh
|
||||
|
||||
if test.expectError {
|
||||
require.Error(t, finalErr)
|
||||
} else {
|
||||
require.NoError(t, finalErr)
|
||||
}
|
||||
|
||||
assert.Equal(t, test.expectedCount, len(findings))
|
||||
})
|
||||
}
|
||||
}
|
||||
+56
-4
@@ -4,20 +4,21 @@ import (
|
||||
// "encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/scm"
|
||||
"github.com/zricethezav/gitleaks/v8/logging"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
func augmentGitFinding(remote *RemoteInfo, 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)
|
||||
@@ -25,16 +26,64 @@ func augmentGitFinding(finding report.Finding, textFragment *gitdiff.TextFragmen
|
||||
|
||||
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)
|
||||
finding.Message = f.PatchHeader.Message()
|
||||
// Results from `git diff` shouldn't have a link.
|
||||
if finding.Commit != "" {
|
||||
finding.Link = createScmLink(remote.Platform, remote.Url, finding)
|
||||
}
|
||||
}
|
||||
return finding
|
||||
}
|
||||
|
||||
var linkCleaner = strings.NewReplacer(
|
||||
" ", "%20",
|
||||
"%", "%25",
|
||||
)
|
||||
|
||||
func createScmLink(scmPlatform scm.Platform, remoteUrl string, finding report.Finding) string {
|
||||
if scmPlatform == scm.UnknownPlatform || scmPlatform == scm.NoPlatform {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Clean the path.
|
||||
var (
|
||||
filePath = linkCleaner.Replace(finding.File)
|
||||
ext = strings.ToLower(filepath.Ext(filePath))
|
||||
)
|
||||
|
||||
switch scmPlatform {
|
||||
case scm.GitHubPlatform:
|
||||
link := fmt.Sprintf("%s/blob/%s/%s", remoteUrl, finding.Commit, filePath)
|
||||
if ext == ".ipynb" || ext == ".md" {
|
||||
link += "?plain=1"
|
||||
}
|
||||
if finding.StartLine != 0 {
|
||||
link += fmt.Sprintf("#L%d", finding.StartLine)
|
||||
}
|
||||
if finding.EndLine != finding.StartLine {
|
||||
link += fmt.Sprintf("-L%d", finding.EndLine)
|
||||
}
|
||||
return link
|
||||
case scm.GitLabPlatform:
|
||||
link := fmt.Sprintf("%s/blob/%s/%s", remoteUrl, finding.Commit, filePath)
|
||||
if finding.StartLine != 0 {
|
||||
link += fmt.Sprintf("#L%d", finding.StartLine)
|
||||
}
|
||||
if finding.EndLine != finding.StartLine {
|
||||
link += fmt.Sprintf("-%d", finding.EndLine)
|
||||
}
|
||||
return link
|
||||
default:
|
||||
// This should never happen.
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -177,6 +226,9 @@ func printFinding(f report.Finding, noColor bool) {
|
||||
fmt.Printf("%-12s %s\n", "Email:", f.Email)
|
||||
fmt.Printf("%-12s %s\n", "Date:", f.Date)
|
||||
fmt.Printf("%-12s %s\n", "Fingerprint:", f.Fingerprint)
|
||||
if f.Link != "" {
|
||||
fmt.Printf("%-12s %s\n", "Link:", f.Link)
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package detect
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/scm"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
)
|
||||
|
||||
func Test_createScmLink(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
platform scm.Platform
|
||||
url string
|
||||
finding report.Finding
|
||||
want string
|
||||
}{
|
||||
// None
|
||||
"no platform": {
|
||||
platform: scm.NoPlatform,
|
||||
want: "",
|
||||
},
|
||||
|
||||
// GitHub
|
||||
"github - single line": {
|
||||
platform: scm.GitHubPlatform,
|
||||
url: "https://github.com/gitleaks/test",
|
||||
finding: report.Finding{
|
||||
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
|
||||
File: "metrics/% of sales/.env",
|
||||
StartLine: 25,
|
||||
EndLine: 25,
|
||||
},
|
||||
want: "https://github.com/gitleaks/test/blob/20553ad96a4a080c94a54d677db97eed8ce2560d/metrics/%25%20of%20sales/.env#L25",
|
||||
},
|
||||
"github - multi line": {
|
||||
platform: scm.GitHubPlatform,
|
||||
url: "https://github.com/gitleaks/test",
|
||||
finding: report.Finding{
|
||||
Commit: "7bad9f7654cf9701b62400281748c0e8efd97666",
|
||||
File: "config.json",
|
||||
StartLine: 235,
|
||||
EndLine: 238,
|
||||
},
|
||||
want: "https://github.com/gitleaks/test/blob/7bad9f7654cf9701b62400281748c0e8efd97666/config.json#L235-L238",
|
||||
},
|
||||
"github - markdown": {
|
||||
platform: scm.GitHubPlatform,
|
||||
url: "https://github.com/gitleaks/test",
|
||||
finding: report.Finding{
|
||||
Commit: "1fc8961d172f39ffb671766e472aa76f8d713e87",
|
||||
File: "docs/guides/ecosystem/discordjs.MD",
|
||||
StartLine: 34,
|
||||
EndLine: 34,
|
||||
},
|
||||
want: "https://github.com/gitleaks/test/blob/1fc8961d172f39ffb671766e472aa76f8d713e87/docs/guides/ecosystem/discordjs.MD?plain=1#L34",
|
||||
},
|
||||
"github - jupyter notebook": {
|
||||
platform: scm.GitHubPlatform,
|
||||
url: "https://github.com/gitleaks/test",
|
||||
finding: report.Finding{
|
||||
Commit: "8f56bd2369595bcadbb007e88ba294630fb05c7b",
|
||||
File: "Cloud/IPYNB/Overlapping Recommendation algorithm _OCuLaR_.ipynb",
|
||||
StartLine: 293,
|
||||
EndLine: 293,
|
||||
},
|
||||
want: "https://github.com/gitleaks/test/blob/8f56bd2369595bcadbb007e88ba294630fb05c7b/Cloud/IPYNB/Overlapping%20Recommendation%20algorithm%20_OCuLaR_.ipynb?plain=1#L293",
|
||||
},
|
||||
|
||||
// GitLab
|
||||
"gitlab - single line": {
|
||||
platform: scm.GitLabPlatform,
|
||||
url: "https://gitlab.com/example-org/example-group/gitleaks",
|
||||
finding: report.Finding{
|
||||
Commit: "213ffd1c9bfa906eb4c7731771132c58a4ca0139",
|
||||
File: ".gitlab-ci.yml",
|
||||
StartLine: 41,
|
||||
EndLine: 41,
|
||||
},
|
||||
want: "https://gitlab.com/example-org/example-group/gitleaks/blob/213ffd1c9bfa906eb4c7731771132c58a4ca0139/.gitlab-ci.yml#L41",
|
||||
},
|
||||
"gitlab - multi line": {
|
||||
platform: scm.GitLabPlatform,
|
||||
url: "https://gitlab.com/example-org/example-group/gitleaks",
|
||||
finding: report.Finding{
|
||||
Commit: "63410f74e23a4e51e1f60b9feb073b5d325af878",
|
||||
File: ".vscode/launchSettings.json",
|
||||
StartLine: 6,
|
||||
EndLine: 8,
|
||||
},
|
||||
want: "https://gitlab.com/example-org/example-group/gitleaks/blob/63410f74e23a4e51e1f60b9feb073b5d325af878/.vscode/launchSettings.json#L6-8",
|
||||
},
|
||||
}
|
||||
for name, tt := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
actual := createScmLink(tt.platform, tt.url, tt.finding)
|
||||
assert.Equal(t, tt.want, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ require (
|
||||
github.com/rs/zerolog v1.26.1
|
||||
github.com/spf13/cobra v1.2.1
|
||||
github.com/spf13/viper v1.8.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/stretchr/testify v1.10.0
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
|
||||
)
|
||||
|
||||
@@ -35,13 +35,13 @@ require (
|
||||
github.com/muesli/termenv v0.15.1 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/shopspring/decimal v1.4.0 // indirect
|
||||
github.com/tetratelabs/wazero v1.8.2 // indirect
|
||||
github.com/tetratelabs/wazero v1.9.0 // indirect
|
||||
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
|
||||
golang.org/x/crypto v0.29.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
@@ -49,15 +49,15 @@ require (
|
||||
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/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/spf13/afero v1.6.0 // indirect
|
||||
github.com/spf13/cast v1.7.0 // 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
|
||||
github.com/wasilibs/go-re2 v1.8.0
|
||||
github.com/wasilibs/go-re2 v1.9.0
|
||||
golang.org/x/sync v0.9.0 // indirect
|
||||
golang.org/x/sys v0.27.0 // indirect
|
||||
golang.org/x/sys v0.29.0 // indirect
|
||||
golang.org/x/text v0.20.0 // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
|
||||
@@ -71,8 +71,9 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
|
||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
@@ -250,8 +251,9 @@ github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
@@ -294,14 +296,14 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/tetratelabs/wazero v1.8.2 h1:yIgLR/b2bN31bjxwXHD8a3d+BogigR952csSDdLYEv4=
|
||||
github.com/tetratelabs/wazero v1.8.2/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
|
||||
github.com/wasilibs/go-re2 v1.8.0 h1:6wpqZ31vdoJRSOM41bWEd1AbSmRe161yQkTzoihqwEg=
|
||||
github.com/wasilibs/go-re2 v1.8.0/go.mod h1:RjA3Y/yW6xFL8Iyz8f5sVhttLq5b5DRF8baZ7Sh+elk=
|
||||
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
|
||||
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
|
||||
github.com/wasilibs/go-re2 v1.9.0 h1:kjAd8qbNvV4Ve2Uf+zrpTCrDHtqH4dlsRXktywo73JQ=
|
||||
github.com/wasilibs/go-re2 v1.9.0/go.mod h1:0sRtscWgpUdNA137bmr1IUgrRX0Su4dcn9AEe61y+yI=
|
||||
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4=
|
||||
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
@@ -477,8 +479,8 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
// TODO: Should this be a pointer?
|
||||
// https://github.com/rs/zerolog/issues/1
|
||||
var Logger zerolog.Logger
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//go:build stdregex
|
||||
|
||||
package regexp
|
||||
|
||||
import (
|
||||
re "regexp"
|
||||
)
|
||||
|
||||
const Version = "stdlib"
|
||||
|
||||
type Regexp = re.Regexp
|
||||
|
||||
func MustCompile(str string) *re.Regexp {
|
||||
return re.MustCompile(str)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//go:build !stdregex
|
||||
|
||||
package regexp
|
||||
|
||||
import (
|
||||
re "github.com/wasilibs/go-re2"
|
||||
)
|
||||
|
||||
const Version = "github.com/wasilibs/go-re2"
|
||||
|
||||
type Regexp = re.Regexp
|
||||
|
||||
func MustCompile(str string) *re.Regexp {
|
||||
return re.MustCompile(str)
|
||||
}
|
||||
+19
-7
@@ -17,8 +17,11 @@ func (r *CsvReporter) Write(w io.WriteCloser, findings []Finding) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
cw := csv.NewWriter(w)
|
||||
err := cw.Write([]string{"RuleID",
|
||||
var (
|
||||
cw = csv.NewWriter(w)
|
||||
err error
|
||||
)
|
||||
columns := []string{"RuleID",
|
||||
"Commit",
|
||||
"File",
|
||||
"SymlinkFile",
|
||||
@@ -34,12 +37,17 @@ func (r *CsvReporter) Write(w io.WriteCloser, findings []Finding) error {
|
||||
"Email",
|
||||
"Fingerprint",
|
||||
"Tags",
|
||||
})
|
||||
if err != nil {
|
||||
}
|
||||
// A miserable attempt at "omitempty" so tests don't yell at me.
|
||||
if findings[0].Link != "" {
|
||||
columns = append(columns, "Link")
|
||||
}
|
||||
|
||||
if err = cw.Write(columns); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range findings {
|
||||
err = cw.Write([]string{f.RuleID,
|
||||
row := []string{f.RuleID,
|
||||
f.Commit,
|
||||
f.File,
|
||||
f.SymlinkFile,
|
||||
@@ -55,8 +63,12 @@ func (r *CsvReporter) Write(w io.WriteCloser, findings []Finding) error {
|
||||
f.Email,
|
||||
f.Fingerprint,
|
||||
strings.Join(f.Tags, " "),
|
||||
})
|
||||
if err != nil {
|
||||
}
|
||||
if findings[0].Link != "" {
|
||||
row = append(row, f.Link)
|
||||
}
|
||||
|
||||
if err = cw.Write(row); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -53,6 +53,7 @@ func TestWriteCSV(t *testing.T) {
|
||||
t.Run(test.testReportName, func(t *testing.T) {
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".csv"))
|
||||
require.NoError(t, err)
|
||||
defer tmpfile.Close()
|
||||
|
||||
err = reporter.Write(tmpfile, test.findings)
|
||||
require.NoError(t, err)
|
||||
@@ -67,7 +68,10 @@ func TestWriteCSV(t *testing.T) {
|
||||
|
||||
want, err := os.ReadFile(test.expected)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, string(want), string(got))
|
||||
|
||||
wantStr := lineEndingReplacer.Replace(string(want))
|
||||
gotStr := lineEndingReplacer.Replace(string(got))
|
||||
assert.Equal(t, wantStr, gotStr)
|
||||
})
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -8,7 +8,10 @@ import (
|
||||
// Finding contains information about strings that
|
||||
// have been captured by a tree-sitter query.
|
||||
type Finding struct {
|
||||
// Rule is the name of the rule that was matched
|
||||
RuleID string
|
||||
Description string
|
||||
|
||||
StartLine int
|
||||
EndLine int
|
||||
StartColumn int
|
||||
@@ -26,6 +29,7 @@ type Finding struct {
|
||||
File string
|
||||
SymlinkFile string
|
||||
Commit string
|
||||
Link string `json:",omitempty"`
|
||||
|
||||
// Entropy is the shannon entropy of Value
|
||||
Entropy float32
|
||||
@@ -36,9 +40,6 @@ type Finding struct {
|
||||
Message string
|
||||
Tags []string
|
||||
|
||||
// Rule is the name of the rule that was matched
|
||||
RuleID string
|
||||
|
||||
// unique identifier
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
+8
-1
@@ -53,18 +53,25 @@ func TestWriteJSON(t *testing.T) {
|
||||
t.Run(test.testReportName, func(t *testing.T) {
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".json"))
|
||||
require.NoError(t, err)
|
||||
defer tmpfile.Close()
|
||||
|
||||
err = reporter.Write(tmpfile, test.findings)
|
||||
require.NoError(t, err)
|
||||
assert.FileExists(t, tmpfile.Name())
|
||||
|
||||
got, err := os.ReadFile(tmpfile.Name())
|
||||
require.NoError(t, err)
|
||||
if test.wantEmpty {
|
||||
assert.Empty(t, got)
|
||||
return
|
||||
}
|
||||
|
||||
want, err := os.ReadFile(test.expected)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, string(want), string(got))
|
||||
|
||||
wantStr := lineEndingReplacer.Replace(string(want))
|
||||
gotStr := lineEndingReplacer.Replace(string(got))
|
||||
assert.Equal(t, wantStr, gotStr)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ func TestWriteJunit(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".xml"))
|
||||
require.NoError(t, err)
|
||||
defer tmpfile.Close()
|
||||
|
||||
err = reporter.Write(tmpfile, test.findings)
|
||||
require.NoError(t, err)
|
||||
@@ -83,6 +84,9 @@ func TestWriteJunit(t *testing.T) {
|
||||
|
||||
want, err := os.ReadFile(test.expected)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, string(want), string(got))
|
||||
|
||||
wantStr := lineEndingReplacer.Replace(string(want))
|
||||
gotStr := lineEndingReplacer.Replace(string(got))
|
||||
assert.Equal(t, wantStr, gotStr)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package report
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -9,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
const expectPath = "../testdata/expected/"
|
||||
const configPath = "../testdata/config/"
|
||||
const templatePath = "../testdata/report/"
|
||||
|
||||
func TestWriteStdout(t *testing.T) {
|
||||
@@ -40,3 +40,10 @@ type testWriter struct {
|
||||
func (t testWriter) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// lineEndingReplacer normalizes CRLF to LF so tests pass on Windows.
|
||||
var lineEndingReplacer = strings.NewReplacer(
|
||||
"\\r\\n", "\\n",
|
||||
"\r", "",
|
||||
"\\r", "",
|
||||
)
|
||||
@@ -49,6 +49,7 @@ func TestWriteSarif(t *testing.T) {
|
||||
t.Run(test.cfgName, func(t *testing.T) {
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".json"))
|
||||
require.NoError(t, err)
|
||||
defer tmpfile.Close()
|
||||
|
||||
reporter := SarifReporter{
|
||||
OrderedRules: []config.Rule{
|
||||
@@ -76,7 +77,10 @@ func TestWriteSarif(t *testing.T) {
|
||||
|
||||
want, err := os.ReadFile(test.expected)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, string(want), string(got))
|
||||
|
||||
wantStr := lineEndingReplacer.Replace(string(want))
|
||||
gotStr := lineEndingReplacer.Replace(string(got))
|
||||
assert.Equal(t, wantStr, gotStr)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ func TestWriteTemplate(t *testing.T) {
|
||||
|
||||
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+filepath.Ext(test.expected)))
|
||||
require.NoError(t, err)
|
||||
defer tmpfile.Close()
|
||||
|
||||
err = reporter.Write(tmpfile, test.findings)
|
||||
require.NoError(t, err)
|
||||
@@ -88,7 +89,10 @@ func TestWriteTemplate(t *testing.T) {
|
||||
|
||||
want, err := os.ReadFile(test.expected)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, string(want), string(got))
|
||||
|
||||
wantStr := lineEndingReplacer.Replace(string(want))
|
||||
gotStr := lineEndingReplacer.Replace(string(got))
|
||||
assert.Equal(t, wantStr, gotStr)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/fatih/semgroup"
|
||||
|
||||
@@ -15,6 +16,8 @@ type ScanTarget struct {
|
||||
Symlink string
|
||||
}
|
||||
|
||||
var isWindows = runtime.GOOS == "windows"
|
||||
|
||||
func DirectoryTargets(source string, s *semgroup.Group, followSymlinks bool, shouldSkip func(string) bool) (<-chan ScanTarget, error) {
|
||||
paths := make(chan ScanTarget)
|
||||
s.Go(func() error {
|
||||
@@ -63,7 +66,10 @@ func DirectoryTargets(source string, s *semgroup.Group, followSymlinks bool, sho
|
||||
}
|
||||
|
||||
// TODO: Also run this check against the resolved symlink?
|
||||
skip := shouldSkip(path)
|
||||
skip := shouldSkip(path) ||
|
||||
// TODO: Remove this in v9.
|
||||
// This is an awkward hack to mitigate https://github.com/gitleaks/gitleaks/issues/1641.
|
||||
(isWindows && shouldSkip(filepath.ToSlash(path)))
|
||||
if fInfo.IsDir() {
|
||||
// Directory
|
||||
if skip {
|
||||
|
||||
+8
-1
@@ -158,6 +158,9 @@ func listenForStdErr(stderr io.ReadCloser, errCh chan<- error) {
|
||||
// you may want to set your diff.renameLimit variable to at least
|
||||
// (some large number) and retry the command.
|
||||
//
|
||||
// Auto packing the repository in background for optimum performance.
|
||||
// See "git help gc" for manual housekeeping.
|
||||
//
|
||||
// we skip exiting the program as git log -p/git diff will continue
|
||||
// to send data to stdout and finish executing. This next bit of
|
||||
// code prevents gitleaks from stopping mid scan if this error is
|
||||
@@ -167,7 +170,11 @@ func listenForStdErr(stderr io.ReadCloser, errCh chan<- error) {
|
||||
strings.Contains(scanner.Text(),
|
||||
"inexact rename detection was skipped") ||
|
||||
strings.Contains(scanner.Text(),
|
||||
"you may want to set your diff.renameLimit") {
|
||||
"you may want to set your diff.renameLimit") ||
|
||||
strings.Contains(scanner.Text(),
|
||||
"See \"git help gc\" for manual housekeeping") ||
|
||||
strings.Contains(scanner.Text(),
|
||||
"Auto packing the repository in background for optimum performance") {
|
||||
logging.Warn().Msg(scanner.Text())
|
||||
} else {
|
||||
logging.Error().Msgf("[git] %s", scanner.Text())
|
||||
|
||||
+1
-1
@@ -1,5 +1,6 @@
|
||||
[
|
||||
{
|
||||
"RuleID": "test-rule",
|
||||
"Description": "",
|
||||
"StartLine": 1,
|
||||
"EndLine": 2,
|
||||
@@ -16,7 +17,6 @@
|
||||
"Date": "10-19-2003",
|
||||
"Message": "opps",
|
||||
"Tags": [],
|
||||
"RuleID": "test-rule",
|
||||
"Fingerprint": ""
|
||||
}
|
||||
]
|
||||
+2
-2
@@ -2,10 +2,10 @@
|
||||
<testsuites>
|
||||
<testsuite failures="2" name="gitleaks" tests="2" time="">
|
||||
<testcase classname="Test Rule" file="auth.py" name="test-rule has detected a secret in file auth.py, line 1, at commit 0000000000000000." time="">
|
||||
<failure message="test-rule has detected a secret in file auth.py, line 1, at commit 0000000000000000." type="Test Rule">{
	"Description": "Test Rule",
	"StartLine": 1,
	"EndLine": 2,
	"StartColumn": 1,
	"EndColumn": 2,
	"Match": "line containing secret",
	"Secret": "a secret",
	"File": "auth.py",
	"SymlinkFile": "",
	"Commit": "0000000000000000",
	"Entropy": 0,
	"Author": "John Doe",
	"Email": "johndoe@gmail.com",
	"Date": "10-19-2003",
	"Message": "opps",
	"Tags": [],
	"RuleID": "test-rule",
	"Fingerprint": ""
}</failure>
|
||||
<failure message="test-rule has detected a secret in file auth.py, line 1, at commit 0000000000000000." type="Test Rule">{
	"RuleID": "test-rule",
	"Description": "Test Rule",
	"StartLine": 1,
	"EndLine": 2,
	"StartColumn": 1,
	"EndColumn": 2,
	"Match": "line containing secret",
	"Secret": "a secret",
	"File": "auth.py",
	"SymlinkFile": "",
	"Commit": "0000000000000000",
	"Entropy": 0,
	"Author": "John Doe",
	"Email": "johndoe@gmail.com",
	"Date": "10-19-2003",
	"Message": "opps",
	"Tags": [],
	"Fingerprint": ""
}</failure>
|
||||
</testcase>
|
||||
<testcase classname="Test Rule" file="auth.py" name="test-rule has detected a secret in file auth.py, line 2." time="">
|
||||
<failure message="test-rule has detected a secret in file auth.py, line 2." type="Test Rule">{
	"Description": "Test Rule",
	"StartLine": 2,
	"EndLine": 3,
	"StartColumn": 1,
	"EndColumn": 2,
	"Match": "line containing secret",
	"Secret": "a secret",
	"File": "auth.py",
	"SymlinkFile": "",
	"Commit": "",
	"Entropy": 0,
	"Author": "",
	"Email": "",
	"Date": "",
	"Message": "",
	"Tags": [],
	"RuleID": "test-rule",
	"Fingerprint": ""
}</failure>
|
||||
<failure message="test-rule has detected a secret in file auth.py, line 2." type="Test Rule">{
	"RuleID": "test-rule",
	"Description": "Test Rule",
	"StartLine": 2,
	"EndLine": 3,
	"StartColumn": 1,
	"EndColumn": 2,
	"Match": "line containing secret",
	"Secret": "a secret",
	"File": "auth.py",
	"SymlinkFile": "",
	"Commit": "",
	"Entropy": 0,
	"Author": "",
	"Email": "",
	"Date": "",
	"Message": "",
	"Tags": [],
	"Fingerprint": ""
}</failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
foo\bar\gitleaks-false-positive.yaml:aws-access-token:4
|
||||
b55d88dc151f7022901cda41a03d43e0e508f2b7:test_data\test_local_repo_three_leaks.json:aws-access-token:73
|
||||
foo/bar/gitleaks-false-positive.yaml:aws-access-token:5
|
||||
# comment
|
||||
Reference in new issue
Block a user