mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-27 11:44:23 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b5e8e1829 | ||
|
|
343e69399b | ||
|
|
0060ab636a | ||
|
|
025908808f | ||
|
|
088f8b8074 | ||
|
|
afdccad46f | ||
|
|
e002920355 | ||
|
|
d805fb9144 | ||
|
|
391d4d75f6 | ||
|
|
f77493274a | ||
|
|
7f229faf12 | ||
|
|
d0733f96f3 | ||
|
|
6ef704f28f | ||
|
|
7cfebca510 | ||
|
|
6d801ed61c | ||
|
|
e15ab0dc2a | ||
|
|
c39e7640e2 | ||
|
|
c0caab0355 | ||
|
|
81c92c78ca | ||
|
|
bf031592b8 | ||
|
|
acce01f233 | ||
|
|
2678a54290 | ||
|
|
289b757158 | ||
|
|
c02d830494 | ||
|
|
67b0a29ab6 | ||
|
|
f710d680dd | ||
|
|
eb2bfe5e16 | ||
|
|
55d1da131a | ||
|
|
177e9f4fc2 | ||
|
|
e93d8cb696 | ||
|
|
db43f9a342 |
No files matched your search
+11
-11
@@ -9,18 +9,18 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.18
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.19
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: make test
|
||||
- name: Test
|
||||
run: make test
|
||||
|
||||
- name: Validate Config
|
||||
run: cd cmd/generate/config && go run main.go
|
||||
- name: Validate Config
|
||||
run: cd cmd/generate/config && go run main.go
|
||||
+9
-1
@@ -652,7 +652,9 @@ bc26e979c5911cf647c1bede0b3700ebaaa454c8:checks_test.go:aws-access-token:36
|
||||
8f352bd840f028b481dc725b77d2f4904b77913b:checks_test.go:aws-access-token:34
|
||||
ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29:checks_test.go:aws-access-token:37
|
||||
06c9e824d5985c8e8789321ae70de7ace3b093dc:main.go:aws-access-token:15
|
||||
|
||||
6d801ed61cf4d75d176cbf9062ec6ad706c9d1eb:detect/detect_test.go:private-key:567
|
||||
6d801ed61cf4d75d176cbf9062ec6ad706c9d1eb:testdata/repos/symlinks/source_file/id_ed25519:private-key:1
|
||||
acce01f2338434a78f6a4a06a097b0fd23280484:README.md:aws-access-token:218
|
||||
README.md:aws-access-token:204
|
||||
README.md:aws-access-token:205
|
||||
README.md:aws-access-token:244
|
||||
@@ -742,3 +744,9 @@ testdata/repos/nogit/main.go:aws-access-token:20
|
||||
96eed6aa0f507fe0c21bb46bec32637dc4cb1a9f:detect/detect_test.go:aws-access-token:513
|
||||
bfbc39eb185a217ead81a7174026f1c55f963660:cmd/generate/config/rules/jwt.go:jwt:17
|
||||
bfbc39eb185a217ead81a7174026f1c55f963660:cmd/generate/config/rules/jwt.go:jwt:19
|
||||
acce01f2338434a78f6a4a06a097b0fd23280484:README.md:aws-access-token:220
|
||||
99d620c719020fa24baa831299f0c964da79875e:detect/detect_test.go:aws-access-token:514
|
||||
111c8b47b65627db117bd20be85ff0aee8961eb9:detect/detect_test.go:private-key:567
|
||||
99d620c719020fa24baa831299f0c964da79875e:detect/detect_test.go:aws-access-token:512
|
||||
99d620c719020fa24baa831299f0c964da79875e:detect/detect_test.go:aws-access-token:513
|
||||
69f161c0a0cc0f7858f7d0609d656f4edcedd84c:detect/detect_test.go:discord-api-token:326
|
||||
+1
-1
@@ -28,7 +28,7 @@ If you want to add a new rule to the [default Gitleaks configuration](https://gi
|
||||
func Beamer() *config.Rule {
|
||||
// Define Rule
|
||||
r := config.Rule{
|
||||
// Human redable description of the rule
|
||||
// Human readable description of the rule
|
||||
Description: "Beamer API token",
|
||||
|
||||
// Unique ID for the rule
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.18 AS build
|
||||
FROM golang:1.19 AS build
|
||||
WORKDIR /go/src/github.com/zricethezav/gitleaks
|
||||
COPY . .
|
||||
RUN VERSION=$(git describe --tags --abbrev=0) && \
|
||||
|
||||
@@ -77,7 +77,7 @@ cd gitleaks
|
||||
make build
|
||||
```
|
||||
|
||||
### Github Action
|
||||
### GitHub Action
|
||||
|
||||
Check out the official [Gitleaks GitHub Action](https://github.com/gitleaks/gitleaks-action)
|
||||
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
```
|
||||
repos:
|
||||
- repo: https://github.com/zricethezav/gitleaks
|
||||
rev: v8.12.0
|
||||
rev: v8.15.3
|
||||
hooks:
|
||||
- id: gitleaks
|
||||
```
|
||||
@@ -138,28 +138,29 @@ Usage:
|
||||
|
||||
Available Commands:
|
||||
completion generate the autocompletion script for the specified shell
|
||||
detect Detect secrets in code
|
||||
detect detect secrets in code
|
||||
help Help about any command
|
||||
protect Protect secrets in code
|
||||
version Display gitleaks version
|
||||
protect protect secrets in code
|
||||
version display gitleaks version
|
||||
|
||||
Flags:
|
||||
-c, --config string config file path
|
||||
order of precedence:
|
||||
1. --config/-c
|
||||
2. env var GITLEAKS_CONFIG
|
||||
3. (--source/-s)/.gitleaks.toml
|
||||
If none of the three options are used, then gitleaks will use the default config
|
||||
--exit-code string exit code when leaks have been encountered (default: 1)
|
||||
-h, --help help for gitleaks
|
||||
-l, --log-level string log level (debug, info, warn, error, fatal) (default "info")
|
||||
--no-banner suppress banner
|
||||
--redact redact secrets from logs and stdout
|
||||
-f, --report-format string output format (json, csv, sarif)
|
||||
-r, --report-path string report file
|
||||
-b, --baseline-path path to a previously generated report with known issues that gitleaks should ignore
|
||||
-s, --source string path to source (git repo, directory, file)
|
||||
-v, --verbose show verbose output from scan
|
||||
-b, --baseline-path string path to baseline with issues that can be ignored
|
||||
-c, --config string config file path
|
||||
order of precedence:
|
||||
1. --config/-c
|
||||
2. env var GITLEAKS_CONFIG
|
||||
3. (--source/-s)/.gitleaks.toml
|
||||
If none of the three options are used, then gitleaks will use the default config
|
||||
--exit-code int exit code when leaks have been encountered (default 1)
|
||||
-h, --help help for gitleaks
|
||||
-l, --log-level string log level (trace, debug, info, warn, error, fatal) (default "info")
|
||||
--max-target-megabytes int files larger than this will be skipped
|
||||
--no-banner suppress banner
|
||||
--redact redact secrets from logs and stdout
|
||||
-f, --report-format string output format (json, csv, sarif) (default "json")
|
||||
-r, --report-path string report file
|
||||
-s, --source string path to source (default: $PWD) (default ".")
|
||||
-v, --verbose show verbose output from scan
|
||||
|
||||
Use "gitleaks [command] --help" for more information about a command.
|
||||
```
|
||||
@@ -194,8 +195,8 @@ as a pre-commit.
|
||||
|
||||
### Creating a baseline
|
||||
|
||||
When scanning large repositories or repositories with a long history, it can be convenient to use a baseline. When using a baseline,
|
||||
gitleaks will ignore any old findings that are present in the baseline. A baseline can be any gitleaks report. To create a gitleaks report, run gitleaks with the `--report-path` parameter.
|
||||
When scanning large repositories or repositories with a long history, it can be convenient to use a baseline. When using a baseline,
|
||||
gitleaks will ignore any old findings that are present in the baseline. A baseline can be any gitleaks report. To create a gitleaks report, run gitleaks with the `--report-path` parameter.
|
||||
|
||||
```
|
||||
gitleaks detect --report-path gitleaks-report.json # This will save the report in a file called gitleaks-report.json
|
||||
@@ -215,25 +216,17 @@ You can verify a finding found by gitleaks using a `git log` command.
|
||||
Example output:
|
||||
|
||||
```
|
||||
{
|
||||
"Description": "AWS",
|
||||
"StartLine": 37,
|
||||
"EndLine": 37,
|
||||
"StartColumn": 19,
|
||||
"EndColumn": 38,
|
||||
"Match": "\t\t\"aws_secret= \\\"AKIAIMNOJVGFDXXXE4OA\\\"\": true,",
|
||||
"Secret": "AKIAIMNOJVGFDXXXE4OA",
|
||||
"File": "checks_test.go",
|
||||
"Commit": "ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29",
|
||||
"Entropy": 0,
|
||||
"Author": "zricethezav",
|
||||
"Email": "thisispublicanyways@gmail.com",
|
||||
"Date": "2018-01-28 17:39:00 -0500 -0500",
|
||||
"Message": "[update] entropy check",
|
||||
"Tags": [],
|
||||
"RuleID": "aws-access-token"
|
||||
}
|
||||
|
||||
Finding: aws_secret="AKIAIMNOJVGFDXXXE4OA"
|
||||
RuleID: aws-access-token
|
||||
Secret AKIAIMNOJVGFDXXXE4OA
|
||||
Entropy: 3.65
|
||||
File: checks_test.go
|
||||
Line: 37
|
||||
Commit: ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
|
||||
Author: Zachary Rice
|
||||
Email: z@email.com
|
||||
Date: 2018-01-28T17:39:00Z
|
||||
Fingerprint: ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29:checks_test.go:aws-access-token:37
|
||||
```
|
||||
|
||||
We can use the following format to verify the leak:
|
||||
@@ -342,6 +335,10 @@ paths = [
|
||||
'''go\.mod''',
|
||||
'''go\.sum'''
|
||||
]
|
||||
# note: (rule) regexTarget defaults to check the _Secret_ in the finding.
|
||||
# if regexTarget is not specified then _Secret_ will be used.
|
||||
# Acceptable values for regexTarget are "match" and "line"
|
||||
regexTarget = "match"
|
||||
regexes = [
|
||||
'''process''',
|
||||
'''getenv''',
|
||||
@@ -364,6 +361,12 @@ paths = [
|
||||
'''gitleaks\.toml''',
|
||||
'''(.*?)(jpg|gif|doc)'''
|
||||
]
|
||||
|
||||
# note: (global) regexTarget defaults to check the _Secret_ in the finding.
|
||||
# if regexTarget is not specified then _Secret_ will be used.
|
||||
# Acceptable values for regexTarget are "match" and "line"
|
||||
regexTarget = "match"
|
||||
|
||||
regexes = [
|
||||
'''219-09-9999''',
|
||||
'''078-05-1120''',
|
||||
@@ -376,12 +379,16 @@ stopwords = [
|
||||
'''endpoint''',
|
||||
]
|
||||
```
|
||||
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples or follow the [contributing guidelines](https://github.com/zricethezav/gitleaks/blob/master/README.md).
|
||||
|
||||
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples or follow the [contributing guidelines](https://github.com/zricethezav/gitleaks/blob/master/README.md) if you would like to contribute to the default configuration. Additionally, you can check out [this gitleaks blog post](https://blog.gitleaks.io/stop-leaking-secrets-configuration-2-3-aeed293b1fbf) which covers advanced configuration setups.
|
||||
|
||||
### Additional Configuration
|
||||
|
||||
#### gitleaks:allow
|
||||
|
||||
If you are knowingly committing a test secret that gitleaks will catch you can add a `gitleaks:allow` comment to that line which will instruct gitleaks
|
||||
to ignore that secret. Ex:
|
||||
|
||||
```
|
||||
class CustomClass:
|
||||
discord_client_secret = '8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ' #gitleaks:allow
|
||||
@@ -389,8 +396,8 @@ class CustomClass:
|
||||
```
|
||||
|
||||
#### .gitleaksignore
|
||||
You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is expirmental and is subject to change in the future.
|
||||
|
||||
You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is experimental and is subject to change in the future.
|
||||
|
||||
## Secured by Jit
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
## Who uses Gitleaks?
|
||||
|
||||
As the Gitleaks Community grows, we'd like to keep a list of our users.
|
||||
|
||||
Here's a running list of some organizations using Gitleaks[^1]:
|
||||
|
||||
1. [GitLab](https://docs.gitlab.com/ee/user/application_security/secret_detection/)
|
||||
1. [Gitleaks](https://gitleaks.io)
|
||||
1. [GoReleaser](https://goreleaser.com)
|
||||
2. [Trendyol](https://trendyol.com)
|
||||
|
||||
Feel free to [add yours](https://github.com/zricethezav/gitleaks/edit/master/USERS.md)!
|
||||
|
||||
<!--
|
||||
Hey! Thanks for looking into this file!
|
||||
If you're going to edit it, please:
|
||||
- keep a-z ordering :)
|
||||
- edit only the USERS.md file at the repository's root folder
|
||||
-->
|
||||
|
||||
[^1]: Entries were either added by the companies themselves or by the maintainers after seeing it in the wild.
|
||||
You can see all public repositories using Gitleaks or Gitleaks-Action by [searching on GitHub](https://github.com/search?q=gitleaks).
|
||||
|
||||
<!--
|
||||
Shout out to GoReleaser for this template: https://github.com/goreleaser/goreleaser/blob/main/USERS.md
|
||||
-->
|
||||
+35
-12
@@ -18,6 +18,9 @@ func init() {
|
||||
rootCmd.AddCommand(detectCmd)
|
||||
detectCmd.Flags().String("log-opts", "", "git log options")
|
||||
detectCmd.Flags().Bool("no-git", false, "treat git repo as a regular directory and scan those files, --log-opts has no effect on the scan when --no-git is set")
|
||||
detectCmd.Flags().Bool("pipe", false, "scan input from stdin, ex: `cat some_file | gitleaks detect --pipe`")
|
||||
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
|
||||
|
||||
}
|
||||
|
||||
var detectCmd = &cobra.Command{
|
||||
@@ -51,11 +54,11 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
detector := detect.NewDetector(cfg)
|
||||
detector.Config.Path, err = cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
source, err := cmd.Flags().GetString("source")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
// if config path is not set, then use the {source}/.gitleaks.toml path.
|
||||
// note that there may not be a `{source}/.gitleaks.toml` file, this is ok.
|
||||
@@ -64,36 +67,50 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
// set verbose flag
|
||||
if detector.Verbose, err = cmd.Flags().GetBool("verbose"); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
// set redact flag
|
||||
if detector.Redact, err = cmd.Flags().GetBool("redact"); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||
detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore"))
|
||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||
}
|
||||
}
|
||||
|
||||
// ignore findings from the baseline (an existing report in json format generated earlier)
|
||||
baselinePath, _ := cmd.Flags().GetString("baseline-path")
|
||||
if baselinePath != "" {
|
||||
err = detector.AddBaseline(baselinePath)
|
||||
err = detector.AddBaseline(baselinePath, source)
|
||||
if err != nil {
|
||||
log.Error().Msgf("Could not load baseline. The path must point of a gitleaks report generated using the default format: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// set follow symlinks flag
|
||||
if detector.FollowSymlinks, err = cmd.Flags().GetBool("follow-symlinks"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
// set exit code
|
||||
exitCode, err := cmd.Flags().GetInt("exit-code")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("could not get exit code")
|
||||
}
|
||||
|
||||
// determine what type of scan:
|
||||
// - git: scan the history of the repo
|
||||
// - no-git: scan files by treating the repo as a plain directory
|
||||
noGit, err := cmd.Flags().GetBool("no-git")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not call GetBool() for no-git")
|
||||
}
|
||||
fromPipe, err := cmd.Flags().GetBool("pipe")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
@@ -103,19 +120,25 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
findings, err = detector.DetectFiles(source)
|
||||
if err != nil {
|
||||
// don't exit on error, just log it
|
||||
log.Error().Msg(err.Error())
|
||||
log.Error().Err(err).Msg("")
|
||||
}
|
||||
} else if fromPipe {
|
||||
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
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
} else {
|
||||
var logOpts string
|
||||
logOpts, err = cmd.Flags().GetString("log-opts")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
findings, err = detector.DetectGit(source, logOpts, detect.DetectType)
|
||||
if err != nil {
|
||||
// don't exit on error, just log it
|
||||
log.Error().Msg(err.Error())
|
||||
log.Error().Err(err).Msg("")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +164,7 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
ext, _ := cmd.Flags().GetString("report-format")
|
||||
if reportPath != "" {
|
||||
if err := report.Write(findings, cfg, ext, reportPath); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("could not write")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
)
|
||||
|
||||
func main() {
|
||||
configRules := []*config.Rule{}
|
||||
var configRules []*config.Rule
|
||||
configRules = append(configRules, rules.AdafruitAPIKey())
|
||||
configRules = append(configRules, rules.AdobeClientID())
|
||||
configRules = append(configRules, rules.AdobeClientSecret())
|
||||
@@ -41,6 +41,9 @@ func main() {
|
||||
configRules = append(configRules, rules.Contentful())
|
||||
configRules = append(configRules, rules.Databricks())
|
||||
configRules = append(configRules, rules.DatadogtokenAccessToken())
|
||||
configRules = append(configRules, rules.DigitalOceanPAT())
|
||||
configRules = append(configRules, rules.DigitalOceanOAuthToken())
|
||||
configRules = append(configRules, rules.DigitalOceanRefreshToken())
|
||||
configRules = append(configRules, rules.DiscordAPIToken())
|
||||
configRules = append(configRules, rules.DiscordClientID())
|
||||
configRules = append(configRules, rules.DiscordClientSecret())
|
||||
@@ -70,10 +73,13 @@ func main() {
|
||||
// configRules = append(configRules, rules.GCPServiceAccount())
|
||||
configRules = append(configRules, rules.GCPAPIKey())
|
||||
configRules = append(configRules, rules.GitHubPat())
|
||||
configRules = append(configRules, rules.GitHubFineGrainedPat())
|
||||
configRules = append(configRules, rules.GitHubOauth())
|
||||
configRules = append(configRules, rules.GitHubApp())
|
||||
configRules = append(configRules, rules.GitHubRefresh())
|
||||
configRules = append(configRules, rules.Gitlab())
|
||||
configRules = append(configRules, rules.GitlabPat())
|
||||
configRules = append(configRules, rules.GitlabPipelineTriggerToken())
|
||||
configRules = append(configRules, rules.GitlabRunnerRegistrationToken())
|
||||
configRules = append(configRules, rules.GitterAccessToken())
|
||||
configRules = append(configRules, rules.GrafanaApiKey())
|
||||
configRules = append(configRules, rules.GrafanaCloudApiToken())
|
||||
@@ -171,9 +177,7 @@ func main() {
|
||||
// nasty dereferencing.
|
||||
ruleLookUp[rule.RuleID] = *rule
|
||||
}
|
||||
config := config.Config{
|
||||
Rules: ruleLookUp,
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(templatePath)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to parse template")
|
||||
@@ -183,6 +187,9 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to create rules.toml")
|
||||
}
|
||||
tmpl.Execute(f, config)
|
||||
|
||||
if err = tmpl.Execute(f, config.Config{Rules: ruleLookUp}); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not execute template")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ paths = [
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket)$''',
|
||||
'''(go.mod|go.sum)$''',
|
||||
'''node_modules''',
|
||||
'''package-lock.json''',
|
||||
'''vendor''',
|
||||
]
|
||||
|
||||
@@ -57,4 +58,4 @@ keywords = [
|
||||
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
|
||||
]
|
||||
|
||||
{{end}}{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -0,0 +1,51 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func DigitalOceanPAT() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "DigitalOcean Personal Access Token",
|
||||
RuleID: "digitalocean-pat",
|
||||
SecretGroup: 1,
|
||||
Regex: generateUniqueTokenRegex(`dop_v1_[a-f0-9]{64}`),
|
||||
Keywords: []string{"dop_v1_"},
|
||||
}
|
||||
|
||||
tps := []string{
|
||||
generateSampleSecret("do", "dop_v1_"+secrets.NewSecret(hex("64"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func DigitalOceanOAuthToken() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "DigitalOcean OAuth Access Token",
|
||||
RuleID: "digitalocean-access-token",
|
||||
SecretGroup: 1,
|
||||
Regex: generateUniqueTokenRegex(`doo_v1_[a-f0-9]{64}`),
|
||||
Keywords: []string{"doo_v1_"},
|
||||
}
|
||||
|
||||
tps := []string{
|
||||
generateSampleSecret("do", "doo_v1_"+secrets.NewSecret(hex("64"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func DigitalOceanRefreshToken() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "DigitalOcean OAuth Refresh Token",
|
||||
RuleID: "digitalocean-refresh-token",
|
||||
SecretGroup: 1,
|
||||
Regex: generateUniqueTokenRegex(`dor_v1_[a-f0-9]{64}`),
|
||||
Keywords: []string{"dor_v1_"},
|
||||
}
|
||||
|
||||
tps := []string{
|
||||
generateSampleSecret("do", "dor_v1_"+secrets.NewSecret(hex("64"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -23,6 +23,22 @@ func GitHubPat() *config.Rule {
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitHubFineGrainedPat() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitHub Fine-Grained Personal Access Token",
|
||||
RuleID: "github-fine-grained-pat",
|
||||
Regex: regexp.MustCompile(`github_pat_[0-9a-zA-Z_]{82}`),
|
||||
Keywords: []string{"github_pat_"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
generateSampleSecret("github", "github_pat_"+secrets.NewSecret(alphaNumeric("82"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitHubOauth() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
func Gitlab() *config.Rule {
|
||||
func GitlabPat() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitLab Personal Access Token",
|
||||
@@ -22,3 +22,35 @@ func Gitlab() *config.Rule {
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitlabPipelineTriggerToken() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitLab Pipeline Trigger Token",
|
||||
RuleID: "gitlab-ptt",
|
||||
Regex: regexp.MustCompile(`glptt-[0-9a-f]{40}`),
|
||||
Keywords: []string{"glptt-"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
generateSampleSecret("gitlab", "glptt-"+secrets.NewSecret(hex("40"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
|
||||
func GitlabRunnerRegistrationToken() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
Description: "GitLab Runner Registration Token",
|
||||
RuleID: "gitlab-rrt",
|
||||
Regex: regexp.MustCompile(`GR1348941[0-9a-zA-Z\-\_]{20}`),
|
||||
Keywords: []string{"GR1348941"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
generateSampleSecret("gitlab", "GR1348941"+secrets.NewSecret(alphaNumeric("20"))),
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -9,12 +9,12 @@ func JWT() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "JSON Web Token",
|
||||
RuleID: "jwt",
|
||||
Regex: generateUniqueTokenRegex(`ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200}`),
|
||||
Regex: generateUniqueTokenRegex(`ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200}={0,2}`),
|
||||
Keywords: []string{"ey"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{`eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0`, // gitleaks:allow
|
||||
tps := []string{`eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0==`, // gitleaks:allow
|
||||
`JWT := eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0`, // gitleaks:allow
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
|
||||
@@ -11,7 +11,7 @@ func PrivateKey() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "Private Key",
|
||||
RuleID: "private-key",
|
||||
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----`),
|
||||
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----`),
|
||||
Keywords: []string{"-----BEGIN"},
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ anything
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`,
|
||||
`-----BEGIN PRIVATE KEY BLOCK-----
|
||||
anything
|
||||
-----END PRIVATE KEY BLOCK-----`,
|
||||
} // gitleaks:allow
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func SlackWebHook() *config.Rule {
|
||||
Description: "Slack Webhook",
|
||||
RuleID: "slack-web-hook",
|
||||
Regex: regexp.MustCompile(
|
||||
`https:\/\/hooks.slack.com\/services\/[A-Za-z0-9+\/]{44,46}`),
|
||||
`https:\/\/hooks.slack.com\/(services|workflows)\/[A-Za-z0-9+\/]{44,46}`),
|
||||
Keywords: []string{
|
||||
"hooks.slack.com",
|
||||
},
|
||||
@@ -44,7 +44,8 @@ func SlackWebHook() *config.Rule {
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
"https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
|
||||
"https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
|
||||
"https://hooks.slack.com/workflows/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
@@ -26,4 +26,4 @@ func TeamsWebhook() *config.Rule {
|
||||
"https://mycompany.webhook.office.com/webhookb2/" + secrets.NewSecret(`[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}@[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\/IncomingWebhook\/[a-z0-9]{32}\/[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}`), // gitleaks:allow
|
||||
}
|
||||
return validate(r, tps, nil)
|
||||
}
|
||||
}
|
||||
+12
-7
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
func init() {
|
||||
protectCmd.Flags().Bool("staged", false, "detect secrets in a --staged state")
|
||||
protectCmd.Flags().String("log-opts", "", "git log options")
|
||||
rootCmd.AddCommand(protectCmd)
|
||||
}
|
||||
|
||||
@@ -46,11 +47,11 @@ func runProtect(cmd *cobra.Command, args []string) {
|
||||
detector := detect.NewDetector(cfg)
|
||||
detector.Config.Path, err = cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
source, err := cmd.Flags().GetString("source")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
// if config path is not set, then use the {source}/.gitleaks.toml path.
|
||||
// note that there may not be a `{source}/.gitleaks.toml` file, this is ok.
|
||||
@@ -59,17 +60,21 @@ func runProtect(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
// set verbose flag
|
||||
if detector.Verbose, err = cmd.Flags().GetBool("verbose"); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
// set redact flag
|
||||
if detector.Redact, err = cmd.Flags().GetBool("redact"); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
// get log options for git scan
|
||||
logOpts, err := cmd.Flags().GetString("log-opts")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
// start git scan
|
||||
@@ -81,7 +86,7 @@ func runProtect(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
if err != nil {
|
||||
// don't exit on error, just log it
|
||||
log.Error().Err(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
}
|
||||
|
||||
// log info about the scan
|
||||
@@ -96,7 +101,7 @@ func runProtect(cmd *cobra.Command, args []string) {
|
||||
ext, _ := cmd.Flags().GetString("report-format")
|
||||
if reportPath != "" {
|
||||
if err = report.Write(findings, cfg, ext, reportPath); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
}
|
||||
if len(findings) != 0 {
|
||||
|
||||
+5
-1
@@ -45,6 +45,7 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringP("baseline-path", "b", "", "path to baseline with issues that can be ignored")
|
||||
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal)")
|
||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
||||
rootCmd.PersistentFlags().Int("max-target-megabytes", 0, "files larger than this will be skipped")
|
||||
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
||||
rootCmd.PersistentFlags().Bool("no-banner", false, "suppress banner")
|
||||
err := viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
|
||||
@@ -79,8 +80,11 @@ func initLog() {
|
||||
|
||||
func initConfig() {
|
||||
hideBanner, err := rootCmd.Flags().GetBool("no-banner")
|
||||
if err != nil {
|
||||
log.Fatal().Msg(err.Error())
|
||||
}
|
||||
if !hideBanner {
|
||||
fmt.Fprint(os.Stderr, banner)
|
||||
_, _ = fmt.Fprint(os.Stderr, banner)
|
||||
}
|
||||
cfgPath, err := rootCmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
|
||||
@@ -14,6 +14,9 @@ type Allowlist struct {
|
||||
// Regexes is slice of content regular expressions that are allowed to be ignored.
|
||||
Regexes []*regexp.Regexp
|
||||
|
||||
// RegexTarget
|
||||
RegexTarget string
|
||||
|
||||
// Paths is a slice of path regular expressions that are allowed to be ignored.
|
||||
Paths []*regexp.Regexp
|
||||
|
||||
|
||||
+20
-16
@@ -36,17 +36,19 @@ type ViperConfig struct {
|
||||
Tags []string
|
||||
|
||||
Allowlist struct {
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
RegexTarget string
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
}
|
||||
}
|
||||
Allowlist struct {
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
RegexTarget string
|
||||
Regexes []string
|
||||
Paths []string
|
||||
Commits []string
|
||||
StopWords []string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +124,11 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
Tags: r.Tags,
|
||||
Keywords: r.Keywords,
|
||||
Allowlist: Allowlist{
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: r.Allowlist.Commits,
|
||||
StopWords: r.Allowlist.StopWords,
|
||||
RegexTarget: r.Allowlist.RegexTarget,
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: r.Allowlist.Commits,
|
||||
StopWords: r.Allowlist.StopWords,
|
||||
},
|
||||
}
|
||||
orderedRules = append(orderedRules, r.RuleID)
|
||||
@@ -148,10 +151,11 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
Extend: vc.Extend,
|
||||
Rules: rulesMap,
|
||||
Allowlist: Allowlist{
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: vc.Allowlist.Commits,
|
||||
StopWords: vc.Allowlist.StopWords,
|
||||
RegexTarget: vc.Allowlist.RegexTarget,
|
||||
Regexes: allowlistRegexes,
|
||||
Paths: allowlistPaths,
|
||||
Commits: vc.Allowlist.Commits,
|
||||
StopWords: vc.Allowlist.StopWords,
|
||||
},
|
||||
Keywords: keywords,
|
||||
orderedRules: orderedRules,
|
||||
|
||||
+58
-3
@@ -17,6 +17,7 @@ paths = [
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket)$''',
|
||||
'''(go.mod|go.sum)$''',
|
||||
'''node_modules''',
|
||||
'''package-lock.json''',
|
||||
'''vendor''',
|
||||
]
|
||||
|
||||
@@ -238,6 +239,33 @@ keywords = [
|
||||
"datadog",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "DigitalOcean OAuth Access Token"
|
||||
id = "digitalocean-access-token"
|
||||
regex = '''(?i)\b(doo_v1_[a-f0-9]{64})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
secretGroup = 1
|
||||
keywords = [
|
||||
"doo_v1_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "DigitalOcean Personal Access Token"
|
||||
id = "digitalocean-pat"
|
||||
regex = '''(?i)\b(dop_v1_[a-f0-9]{64})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
secretGroup = 1
|
||||
keywords = [
|
||||
"dop_v1_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "DigitalOcean OAuth Refresh Token"
|
||||
id = "digitalocean-refresh-token"
|
||||
regex = '''(?i)\b(dor_v1_[a-f0-9]{64})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
secretGroup = 1
|
||||
keywords = [
|
||||
"dor_v1_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Discord API key"
|
||||
id = "discord-api-token"
|
||||
@@ -462,6 +490,9 @@ keywords = [
|
||||
"key","api","token","secret","client","passwd","password","auth","access",
|
||||
]
|
||||
[rules.allowlist]
|
||||
paths = [
|
||||
'''Database.refactorlog'''
|
||||
]
|
||||
stopwords= [
|
||||
"client",
|
||||
"endpoint",
|
||||
@@ -1946,6 +1977,14 @@ keywords = [
|
||||
"ghu_","ghs_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitHub Fine-Grained Personal Access Token"
|
||||
id = "github-fine-grained-pat"
|
||||
regex = '''github_pat_[0-9a-zA-Z_]{82}'''
|
||||
keywords = [
|
||||
"github_pat_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitHub OAuth Access Token"
|
||||
id = "github-oauth"
|
||||
@@ -1978,6 +2017,22 @@ keywords = [
|
||||
"glpat-",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitLab Pipeline Trigger Token"
|
||||
id = "gitlab-ptt"
|
||||
regex = '''glptt-[0-9a-f]{40}'''
|
||||
keywords = [
|
||||
"glptt-",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "GitLab Runner Registration Token"
|
||||
id = "gitlab-rrt"
|
||||
regex = '''GR1348941[0-9a-zA-Z\-\_]{20}'''
|
||||
keywords = [
|
||||
"gr1348941",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Gitter Access Token"
|
||||
id = "gitter-access-token"
|
||||
@@ -2061,7 +2116,7 @@ keywords = [
|
||||
[[rules]]
|
||||
description = "JSON Web Token"
|
||||
id = "jwt"
|
||||
regex = '''(?i)\b(ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
regex = '''(?i)\b(ey[0-9a-z]{30,34}\.ey[0-9a-z-\/_]{30,500}\.[0-9a-zA-Z-\/_]{10,200}={0,2})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
keywords = [
|
||||
"ey",
|
||||
]
|
||||
@@ -2373,7 +2428,7 @@ keywords = [
|
||||
[[rules]]
|
||||
description = "Private Key"
|
||||
id = "private-key"
|
||||
regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----'''
|
||||
regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----'''
|
||||
keywords = [
|
||||
"-----begin",
|
||||
]
|
||||
@@ -2537,7 +2592,7 @@ keywords = [
|
||||
[[rules]]
|
||||
description = "Slack Webhook"
|
||||
id = "slack-web-hook"
|
||||
regex = '''https:\/\/hooks.slack.com\/services\/[A-Za-z0-9+\/]{44,46}'''
|
||||
regex = '''https:\/\/hooks.slack.com\/(services|workflows)\/[A-Za-z0-9+\/]{44,46}'''
|
||||
keywords = [
|
||||
"hooks.slack.com",
|
||||
]
|
||||
|
||||
+10
-3
@@ -3,9 +3,11 @@ package detect
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
)
|
||||
|
||||
@@ -43,8 +45,13 @@ func LoadBaseline(baselinePath string) ([]report.Finding, error) {
|
||||
return nil, fmt.Errorf("could not open %s", baselinePath)
|
||||
}
|
||||
|
||||
bytes, err := ioutil.ReadAll(jsonFile)
|
||||
jsonFile.Close()
|
||||
defer func() {
|
||||
if cerr := jsonFile.Close(); cerr != nil {
|
||||
log.Warn().Err(cerr).Msg("problem closing jsonFile handle")
|
||||
}
|
||||
}()
|
||||
|
||||
bytes, err := io.ReadAll(jsonFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read data from the file %s", baselinePath)
|
||||
}
|
||||
|
||||
+122
-11
@@ -4,19 +4,21 @@ import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/h2non/filetype"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/detect/git"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
|
||||
"github.com/fatih/semgroup"
|
||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||
"github.com/h2non/filetype"
|
||||
ahocorasick "github.com/petar-dambovaliev/aho-corasick"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
@@ -49,6 +51,12 @@ type Detector struct {
|
||||
// verbose is a flag to print findings
|
||||
Verbose bool
|
||||
|
||||
// files larger than this will be skipped
|
||||
MaxTargetMegaBytes int
|
||||
|
||||
// followSymlinks is a flag to enable scanning symlink files
|
||||
FollowSymlinks bool
|
||||
|
||||
// commitMap is used to keep track of commits that have been scanned.
|
||||
// This is only used for logging purposes and git scans.
|
||||
commitMap map[string]bool
|
||||
@@ -82,7 +90,8 @@ type Fragment struct {
|
||||
Raw string
|
||||
|
||||
// FilePath is the path to the file if applicable
|
||||
FilePath string
|
||||
FilePath string
|
||||
SymlinkFile string
|
||||
|
||||
// CommitSHA is the SHA of the commit if applicable
|
||||
CommitSHA string
|
||||
@@ -151,14 +160,33 @@ func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Detector) AddBaseline(baselinePath string) error {
|
||||
func (d *Detector) AddBaseline(baselinePath string, source string) error {
|
||||
if baselinePath != "" {
|
||||
absoluteSource, err := filepath.Abs(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
absoluteBaseline, err := filepath.Abs(baselinePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
relativeBaseline, err := filepath.Rel(absoluteSource, absoluteBaseline)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
baseline, err := LoadBaseline(baselinePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.baseline = baseline
|
||||
baselinePath = relativeBaseline
|
||||
|
||||
}
|
||||
|
||||
d.baselinePath = baselinePath
|
||||
return nil
|
||||
}
|
||||
@@ -191,6 +219,7 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
||||
finding := report.Finding{
|
||||
Description: rule.Description,
|
||||
File: fragment.FilePath,
|
||||
SymlinkFile: fragment.SymlinkFile,
|
||||
RuleID: rule.RuleID,
|
||||
Match: fmt.Sprintf("file detected: %s", fragment.FilePath),
|
||||
Tags: rule.Tags,
|
||||
@@ -211,6 +240,15 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
||||
return findings
|
||||
}
|
||||
|
||||
// If flag configure and raw data size bigger then the flag
|
||||
if d.MaxTargetMegaBytes > 0 {
|
||||
rawLength := len(fragment.Raw) / 1000000
|
||||
if rawLength > d.MaxTargetMegaBytes {
|
||||
log.Debug().Msgf("skipping file: %s scan due to size: %d", fragment.FilePath, rawLength)
|
||||
return findings
|
||||
}
|
||||
}
|
||||
|
||||
matchIndices := rule.Regex.FindAllStringIndex(fragment.Raw, -1)
|
||||
for _, matchIndex := range matchIndices {
|
||||
// extract secret from match
|
||||
@@ -229,6 +267,7 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
||||
finding := report.Finding{
|
||||
Description: rule.Description,
|
||||
File: fragment.FilePath,
|
||||
SymlinkFile: fragment.SymlinkFile,
|
||||
RuleID: rule.RuleID,
|
||||
StartLine: loc.startLine,
|
||||
EndLine: loc.endLine,
|
||||
@@ -245,9 +284,24 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
||||
continue
|
||||
}
|
||||
|
||||
// check if the secret is in the allowlist
|
||||
if rule.Allowlist.RegexAllowed(finding.Secret) ||
|
||||
d.Config.Allowlist.RegexAllowed(finding.Secret) {
|
||||
// check if the regexTarget is defined in the allowlist "regexes" entry
|
||||
allowlistTarget := finding.Secret
|
||||
switch rule.Allowlist.RegexTarget {
|
||||
case "match":
|
||||
allowlistTarget = finding.Match
|
||||
case "line":
|
||||
allowlistTarget = finding.Line
|
||||
}
|
||||
|
||||
globalAllowlistTarget := finding.Secret
|
||||
switch d.Config.Allowlist.RegexTarget {
|
||||
case "match":
|
||||
globalAllowlistTarget = finding.Match
|
||||
case "line":
|
||||
globalAllowlistTarget = finding.Line
|
||||
}
|
||||
if rule.Allowlist.RegexAllowed(allowlistTarget) ||
|
||||
d.Config.Allowlist.RegexAllowed(globalAllowlistTarget) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -364,18 +418,24 @@ func (d *Detector) DetectGit(source string, logOpts string, gitScanType GitScanT
|
||||
if err := s.Wait(); err != nil {
|
||||
return d.findings, err
|
||||
}
|
||||
log.Debug().Msgf("%d commits scanned. Note: this number might be smaller than expected due to commits with no additions", len(d.commitMap))
|
||||
log.Info().Msgf("%d commits scanned.", len(d.commitMap))
|
||||
log.Debug().Msg("Note: this number might be smaller than expected due to commits with no additions")
|
||||
if git.ErrEncountered {
|
||||
return d.findings, fmt.Errorf("%s", "git error encountered, see logs")
|
||||
}
|
||||
return d.findings, nil
|
||||
}
|
||||
|
||||
type scanTarget struct {
|
||||
Path string
|
||||
Symlink string
|
||||
}
|
||||
|
||||
// DetectFiles accepts a path to a source directory or file and begins a scan of the
|
||||
// file or directory.
|
||||
func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
|
||||
s := semgroup.NewGroup(context.Background(), 4)
|
||||
paths := make(chan string)
|
||||
paths := make(chan scanTarget)
|
||||
s.Go(func() error {
|
||||
defer close(paths)
|
||||
return filepath.Walk(source,
|
||||
@@ -390,7 +450,25 @@ func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
|
||||
return nil
|
||||
}
|
||||
if fInfo.Mode().IsRegular() {
|
||||
paths <- path
|
||||
paths <- scanTarget{
|
||||
Path: path,
|
||||
Symlink: "",
|
||||
}
|
||||
}
|
||||
if fInfo.Mode().Type() == fs.ModeSymlink && d.FollowSymlinks {
|
||||
realPath, err := filepath.EvalSymlinks(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
realPathFileInfo, _ := os.Stat(realPath)
|
||||
if realPathFileInfo.IsDir() {
|
||||
log.Debug().Msgf("found symlinked directory: %s -> %s [skipping]", path, realPath)
|
||||
return nil
|
||||
}
|
||||
paths <- scanTarget{
|
||||
Path: realPath,
|
||||
Symlink: path,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -398,7 +476,7 @@ func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
|
||||
for pa := range paths {
|
||||
p := pa
|
||||
s.Go(func() error {
|
||||
b, err := os.ReadFile(p)
|
||||
b, err := os.ReadFile(p.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -413,7 +491,10 @@ func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
|
||||
|
||||
fragment := Fragment{
|
||||
Raw: string(b),
|
||||
FilePath: p,
|
||||
FilePath: p.Path,
|
||||
}
|
||||
if p.Symlink != "" {
|
||||
fragment.SymlinkFile = p.Symlink
|
||||
}
|
||||
for _, finding := range d.Detect(fragment) {
|
||||
// need to add 1 since line counting starts at 1
|
||||
@@ -433,6 +514,36 @@ func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
|
||||
return d.findings, nil
|
||||
}
|
||||
|
||||
// DetectReader accepts an io.Reader and a buffer size for the reader in KB
|
||||
func (d *Detector) DetectReader(r io.Reader, bufSize int) ([]report.Finding, error) {
|
||||
reader := bufio.NewReader(r)
|
||||
buf := make([]byte, 0, 1000*bufSize)
|
||||
findings := []report.Finding{}
|
||||
|
||||
for {
|
||||
n, err := reader.Read(buf[:cap(buf)])
|
||||
buf = buf[:n]
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
return findings, err
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
fragment := Fragment{
|
||||
Raw: string(buf),
|
||||
}
|
||||
for _, finding := range d.Detect(fragment) {
|
||||
findings = append(findings, finding)
|
||||
if d.Verbose {
|
||||
printFinding(finding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return findings, nil
|
||||
}
|
||||
|
||||
// Detect scans the given fragment and returns a list of findings
|
||||
func (d *Detector) Detect(fragment Fragment) []report.Finding {
|
||||
var findings []report.Finding
|
||||
|
||||
+90
-17
@@ -18,8 +18,14 @@ const repoBasePath = "../testdata/repos/"
|
||||
|
||||
func TestDetect(t *testing.T) {
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
fragment Fragment
|
||||
cfgName string
|
||||
baselinePath string
|
||||
fragment Fragment
|
||||
// NOTE: for expected findings, all line numbers will be 0
|
||||
// because line deltas are added _after_ the finding is created.
|
||||
// I.e, if the finding is from a --no-git file, the line number will be
|
||||
// increase by 1 in DetectFromFiles(). If the finding is from git,
|
||||
// the line number will be increased by the patch delta.
|
||||
expectedFindings []report.Finding
|
||||
wantError error
|
||||
}{
|
||||
@@ -85,8 +91,8 @@ func TestDetect(t *testing.T) {
|
||||
File: "tmp.go",
|
||||
RuleID: "pypi-upload-token",
|
||||
Tags: []string{"key", "pypi"},
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 1,
|
||||
EndColumn: 86,
|
||||
Entropy: 1.9606875,
|
||||
@@ -108,8 +114,8 @@ func TestDetect(t *testing.T) {
|
||||
File: "tmp.go",
|
||||
RuleID: "aws-access-key",
|
||||
Tags: []string{"key", "AWS"},
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 15,
|
||||
EndColumn: 34,
|
||||
Entropy: 3.0841837,
|
||||
@@ -132,8 +138,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "sidekiq-secret",
|
||||
Tags: []string{},
|
||||
Entropy: 2.6098502,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 8,
|
||||
EndColumn: 60,
|
||||
},
|
||||
@@ -155,8 +161,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "sidekiq-secret",
|
||||
Tags: []string{},
|
||||
Entropy: 2.6098502,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 21,
|
||||
EndColumn: 74,
|
||||
},
|
||||
@@ -178,8 +184,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "sidekiq-sensitive-url",
|
||||
Tags: []string{},
|
||||
Entropy: 2.984234,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 8,
|
||||
EndColumn: 58,
|
||||
},
|
||||
@@ -226,8 +232,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "discord-api-key",
|
||||
Tags: []string{},
|
||||
Entropy: 3.7906237,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 7,
|
||||
EndColumn: 93,
|
||||
},
|
||||
@@ -257,8 +263,8 @@ func TestDetect(t *testing.T) {
|
||||
RuleID: "generic-api-key",
|
||||
Tags: []string{},
|
||||
Entropy: 3.7906237,
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartLine: 0,
|
||||
EndLine: 0,
|
||||
StartColumn: 22,
|
||||
EndColumn: 93,
|
||||
},
|
||||
@@ -313,6 +319,15 @@ func TestDetect(t *testing.T) {
|
||||
},
|
||||
expectedFindings: []report.Finding{},
|
||||
},
|
||||
{
|
||||
cfgName: "path_only",
|
||||
baselinePath: ".baseline.json",
|
||||
fragment: Fragment{
|
||||
Raw: `const Discord_Public_Key = "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"`,
|
||||
FilePath: ".baseline.json",
|
||||
},
|
||||
expectedFindings: []report.Finding{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -339,6 +354,7 @@ func TestDetect(t *testing.T) {
|
||||
assert.Equal(t, tt.wantError, err)
|
||||
}
|
||||
d := NewDetector(cfg)
|
||||
d.baselinePath = tt.baselinePath
|
||||
|
||||
findings := d.Detect(tt.fragment)
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
@@ -470,7 +486,7 @@ func TestFromGit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestFromGit tests the FromGit function
|
||||
// TestFromFiles tests the FromFiles function
|
||||
func TestFromFiles(t *testing.T) {
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
@@ -491,6 +507,7 @@ func TestFromFiles(t *testing.T) {
|
||||
Secret: "AKIALALEMEL33243OLIA",
|
||||
Line: "\n\tawsToken := \"AKIALALEMEL33243OLIA\"",
|
||||
File: "../testdata/repos/nogit/main.go",
|
||||
SymlinkFile: "",
|
||||
RuleID: "aws-access-key",
|
||||
Tags: []string{"key", "AWS"},
|
||||
Entropy: 3.0841837,
|
||||
@@ -537,6 +554,7 @@ func TestFromFiles(t *testing.T) {
|
||||
}
|
||||
cfg, _ := vc.Translate()
|
||||
detector := NewDetector(cfg)
|
||||
detector.FollowSymlinks = true
|
||||
findings, err := detector.DetectFiles(tt.source)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -546,6 +564,61 @@ func TestFromFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectWithSymlinks(t *testing.T) {
|
||||
tests := []struct {
|
||||
cfgName string
|
||||
source string
|
||||
expectedFindings []report.Finding
|
||||
}{
|
||||
{
|
||||
source: filepath.Join(repoBasePath, "symlinks/file_symlink"),
|
||||
cfgName: "simple",
|
||||
expectedFindings: []report.Finding{
|
||||
{
|
||||
Description: "Asymmetric Private Key",
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartColumn: 1,
|
||||
EndColumn: 35,
|
||||
Match: "-----BEGIN OPENSSH PRIVATE KEY-----",
|
||||
Secret: "-----BEGIN OPENSSH PRIVATE KEY-----",
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName("simple")
|
||||
viper.SetConfigType("toml")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
var vc config.ViperConfig
|
||||
err = viper.Unmarshal(&vc)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg, _ := vc.Translate()
|
||||
detector := NewDetector(cfg)
|
||||
detector.FollowSymlinks = true
|
||||
findings, err := detector.DetectFiles(tt.source)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.ElementsMatch(t, tt.expectedFindings, findings)
|
||||
}
|
||||
}
|
||||
|
||||
func moveDotGit(from, to string) error {
|
||||
repoDirs, err := os.ReadDir("../testdata/repos")
|
||||
if err != nil {
|
||||
|
||||
@@ -24,6 +24,16 @@ func location(fragment Fragment, matchIndex []int) Location {
|
||||
// default startLineIndex to 0
|
||||
location.startLineIndex = 0
|
||||
|
||||
// Fixes: https://github.com/zricethezav/gitleaks/issues/1037
|
||||
// When a fragment does NOT have any newlines, a default "newline"
|
||||
// will be counted to make the subsequent location calculation logic work
|
||||
// for fragments will no newlines.
|
||||
if len(fragment.newlineIndices) == 0 {
|
||||
fragment.newlineIndices = [][]int{
|
||||
{len(fragment.Raw), len(fragment.Raw) + 1},
|
||||
}
|
||||
}
|
||||
|
||||
for lineNum, pair := range fragment.newlineIndices {
|
||||
_lineNum = lineNum
|
||||
newLineByteIndex := pair[0]
|
||||
|
||||
+18
-1
@@ -102,6 +102,13 @@ func printFinding(f report.Finding) {
|
||||
matchInLineIDX := strings.Index(f.Line, f.Match)
|
||||
secretInMatchIdx := strings.Index(f.Match, f.Secret)
|
||||
|
||||
skipColor := false
|
||||
|
||||
if matchInLineIDX == -1 {
|
||||
skipColor = true
|
||||
matchInLineIDX = 0
|
||||
}
|
||||
|
||||
start := f.Line[0:matchInLineIDX]
|
||||
startMatchIdx := 0
|
||||
if matchInLineIDX > 20 {
|
||||
@@ -127,10 +134,20 @@ func printFinding(f report.Finding) {
|
||||
}
|
||||
|
||||
finding := fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
|
||||
fmt.Printf("%-12s %s", "Finding:", finding)
|
||||
|
||||
if skipColor {
|
||||
fmt.Printf("%-12s %s\n", "Finding:", f.Match)
|
||||
} else {
|
||||
fmt.Printf("%-12s %s", "Finding:", finding)
|
||||
}
|
||||
|
||||
fmt.Printf("%-12s %s\n", "Secret:", secret)
|
||||
fmt.Printf("%-12s %s\n", "RuleID:", f.RuleID)
|
||||
fmt.Printf("%-12s %f\n", "Entropy:", f.Entropy)
|
||||
if f.File == "" {
|
||||
fmt.Println("")
|
||||
return
|
||||
}
|
||||
fmt.Printf("%-12s %s\n", "File:", f.File)
|
||||
fmt.Printf("%-12s %d\n", "Line:", f.StartLine)
|
||||
if f.Commit == "" {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
module github.com/zricethezav/gitleaks/v8
|
||||
|
||||
go 1.17
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/lipgloss v0.5.0
|
||||
github.com/fatih/semgroup v1.2.0
|
||||
github.com/gitleaks/go-gitdiff v0.8.0
|
||||
github.com/h2non/filetype v1.1.3
|
||||
@@ -13,7 +14,6 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/lipgloss v0.5.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
|
||||
@@ -16,6 +16,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
|
||||
err := cw.Write([]string{"RuleID",
|
||||
"Commit",
|
||||
"File",
|
||||
"SymlinkFile",
|
||||
"Secret",
|
||||
"Match",
|
||||
"StartLine",
|
||||
@@ -35,6 +36,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
|
||||
err = cw.Write([]string{f.RuleID,
|
||||
f.Commit,
|
||||
f.File,
|
||||
f.SymlinkFile,
|
||||
f.Secret,
|
||||
f.Match,
|
||||
strconv.Itoa(f.StartLine),
|
||||
|
||||
@@ -28,6 +28,7 @@ func TestWriteCSV(t *testing.T) {
|
||||
EndColumn: 2,
|
||||
Message: "opps",
|
||||
File: "auth.py",
|
||||
SymlinkFile: "",
|
||||
Commit: "0000000000000000",
|
||||
Author: "John Doe",
|
||||
Email: "johndoe@gmail.com",
|
||||
|
||||
+3
-3
@@ -22,9 +22,9 @@ type Finding struct {
|
||||
Secret string
|
||||
|
||||
// File is the name of the file containing the finding
|
||||
File string
|
||||
|
||||
Commit string
|
||||
File string
|
||||
SymlinkFile string
|
||||
Commit string
|
||||
|
||||
// Entropy is the shannon entropy of Value
|
||||
Entropy float32
|
||||
|
||||
@@ -30,6 +30,7 @@ func TestWriteJSON(t *testing.T) {
|
||||
EndColumn: 2,
|
||||
Message: "opps",
|
||||
File: "auth.py",
|
||||
SymlinkFile: "",
|
||||
Commit: "0000000000000000",
|
||||
Author: "John Doe",
|
||||
Email: "johndoe@gmail.com",
|
||||
|
||||
+5
-1
@@ -109,11 +109,15 @@ func getResults(findings []Finding) []Results {
|
||||
}
|
||||
|
||||
func getLocation(f Finding) []Locations {
|
||||
uri := f.File
|
||||
if f.SymlinkFile != "" {
|
||||
uri = f.SymlinkFile
|
||||
}
|
||||
return []Locations{
|
||||
{
|
||||
PhysicalLocation: PhysicalLocation{
|
||||
ArtifactLocation: ArtifactLocation{
|
||||
URI: f.File,
|
||||
URI: uri,
|
||||
},
|
||||
Region: Region{
|
||||
StartLine: f.StartLine,
|
||||
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
RuleID,Commit,File,Secret,Match,StartLine,EndLine,StartColumn,EndColumn,Author,Message,Date,Email,Fingerprint
|
||||
test-rule,0000000000000000,auth.py,a secret,line containing secret,1,2,1,2,John Doe,opps,10-19-2003,johndoe@gmail.com,fingerprint
|
||||
RuleID,Commit,File,SymlinkFile,Secret,Match,StartLine,EndLine,StartColumn,EndColumn,Author,Message,Date,Email,Fingerprint
|
||||
test-rule,0000000000000000,auth.py,,a secret,line containing secret,1,2,1,2,John Doe,opps,10-19-2003,johndoe@gmail.com,fingerprint
|
||||
|
+1
@@ -8,6 +8,7 @@
|
||||
"Match": "line containing secret",
|
||||
"Secret": "a secret",
|
||||
"File": "auth.py",
|
||||
"SymlinkFile": "",
|
||||
"Commit": "0000000000000000",
|
||||
"Entropy": 0,
|
||||
"Author": "John Doe",
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
../source_file/id_ed25519
|
||||
@@ -0,0 +1,7 @@
|
||||
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
|
||||
QyNTUxOQAAACA8YWKYztuuvxUIMomc3zv0OdXCT57Cc2cRYu3TMbX9XAAAAJDiKO3C4ijt
|
||||
wgAAAAtzc2gtZWQyNTUxOQAAACA8YWKYztuuvxUIMomc3zv0OdXCT57Cc2cRYu3TMbX9XA
|
||||
AAAECzmj8DGxg5YHtBK4AmBttMXDQHsPAaCyYHQjJ4YujRBTxhYpjO266/FQgyiZzfO/Q5
|
||||
1cJPnsJzZxFi7dMxtf1cAAAADHJvb3RAZGV2aG9zdAE=
|
||||
-----END OPENSSH PRIVATE KEY-----
|
||||
Reference in new issue
Block a user