mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45266551ba | ||
|
|
b1a2ce7296 | ||
|
|
34e67229e6 | ||
|
|
61513d6772 | ||
|
|
f0dcd4d9cf | ||
|
|
06db3b91d7 | ||
|
|
7804d652c0 | ||
|
|
7911ac60d7 | ||
|
|
463d24618f | ||
|
|
86197b0848 | ||
|
|
3f894cbafc | ||
|
|
7f53b033fe | ||
|
|
7dc9ba40a7 | ||
|
|
c101fa88d2 | ||
|
|
257c703add | ||
|
|
b1d59bf890 | ||
|
|
fab4f4e97d | ||
|
|
289062acd8 | ||
|
|
91ff8f9b70 | ||
|
|
0dbdde837f | ||
|
|
bc599446dc | ||
|
|
a685551299 | ||
|
|
ab5fc21e82 | ||
|
|
d6fccc87d3 | ||
|
|
6f75511665 | ||
|
|
190ac977be | ||
|
|
6dbb0c5af5 | ||
|
|
6705461b33 | ||
|
|
9869eab4c2 | ||
|
|
16f1ec0f1e | ||
|
|
8d80a5a5a2 | ||
|
|
146f69e51b | ||
|
|
51ca0f89b9 | ||
|
|
81cf30855c | ||
|
|
bd8b145bea | ||
|
|
839f114f2b |
No files matched your search
@@ -27,3 +27,11 @@ If applicable, add screenshots to help explain your problem.
|
|||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
|
|
||||||
cc @zricethezav
|
cc @zricethezav
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Check out the Secret Scanning Discord Server for live discussions:
|
||||||
|
|
||||||
|
https://discord.gg/sydS6AHTUP
|
||||||
|
|
||||||
|
--->
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
name: Test
|
name: Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- "*"
|
- "*"
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ build
|
|||||||
.gitleaks.toml
|
.gitleaks.toml
|
||||||
cmd/generate/config/gitleaks.toml
|
cmd/generate/config/gitleaks.toml
|
||||||
|
|
||||||
|
# test results
|
||||||
|
testdata/expected/report/*.got.*
|
||||||
|
|
||||||
# Test binary
|
# Test binary
|
||||||
*.out
|
*.out
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -716,6 +716,9 @@ testdata/expected/git/small-branch-foo.txt:aws-access-token:15
|
|||||||
testdata/expected/git/small.txt:aws-access-token:15
|
testdata/expected/git/small.txt:aws-access-token:15
|
||||||
testdata/expected/git/small.txt:aws-access-token:44
|
testdata/expected/git/small.txt:aws-access-token:44
|
||||||
testdata/repos/nogit/main.go:aws-access-token:20
|
testdata/repos/nogit/main.go:aws-access-token:20
|
||||||
|
testdata/repos/nogit/api.go:aws-access-token:20
|
||||||
|
testdata/repos/small/api/ignoreCommit.go:aws-access-token:20
|
||||||
|
testdata/repos/small/api/ignoreGlobal.go:aws-access-token:20
|
||||||
3df8c3deb7bc1e34210bdbce114f1c6165bc6ac8:detect/detect_test.go:aws-access-token:513
|
3df8c3deb7bc1e34210bdbce114f1c6165bc6ac8:detect/detect_test.go:aws-access-token:513
|
||||||
3df8c3deb7bc1e34210bdbce114f1c6165bc6ac8:detect/detect_test.go:aws-access-token:492
|
3df8c3deb7bc1e34210bdbce114f1c6165bc6ac8:detect/detect_test.go:aws-access-token:492
|
||||||
3df8c3deb7bc1e34210bdbce114f1c6165bc6ac8:detect/detect_test.go:aws-access-token:414
|
3df8c3deb7bc1e34210bdbce114f1c6165bc6ac8:detect/detect_test.go:aws-access-token:414
|
||||||
@@ -756,5 +759,10 @@ acce01f2338434a78f6a4a06a097b0fd23280484:README.md:aws-access-token:220
|
|||||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:detect/detect_test.go:aws-access-token:507
|
9701bf1724d822c0d5bbb7627535dd639a37bf56:detect/detect_test.go:aws-access-token:507
|
||||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:testdata/repos/staged/api/api.go:aws-access-token:6
|
9701bf1724d822c0d5bbb7627535dd639a37bf56:testdata/repos/staged/api/api.go:aws-access-token:6
|
||||||
9701bf1724d822c0d5bbb7627535dd639a37bf56:testdata/repos/staged/api/api.go:aws-access-token:7
|
9701bf1724d822c0d5bbb7627535dd639a37bf56:testdata/repos/staged/api/api.go:aws-access-token:7
|
||||||
|
91ff8f9b7020a16dac9b8b9ef98560ea1cb464f8:testdata/repos/small/api/ignoreCommit.go:aws-access-token:20
|
||||||
|
91ff8f9b7020a16dac9b8b9ef98560ea1cb464f8:testdata/repos/small/api/ignoreGlobal.go:aws-access-token:20
|
||||||
|
91ff8f9b7020a16dac9b8b9ef98560ea1cb464f8:testdata/repos/nogit/api.go:aws-access-token:20
|
||||||
|
adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/nogit/api.go:aws-access-token:20
|
||||||
|
adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/small/api/ignoreGlobal.go:aws-access-token:20
|
||||||
|
adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/small/api/ignoreCommit.go:aws-access-token:20
|
||||||
|
|
||||||
+1
-1
@@ -78,7 +78,7 @@ If you want to add a new rule to the [default Gitleaks configuration](https://gi
|
|||||||
token that is unique enough not to require an identifier then you can use
|
token that is unique enough not to require an identifier then you can use
|
||||||
this function. For example, Pulumi's API Token has the prefix `pul-` which is
|
this function. For example, Pulumi's API Token has the prefix `pul-` which is
|
||||||
unique enough to use `generateUniqueToken`. But something like Beamer's API
|
unique enough to use `generateUniqueToken`. But something like Beamer's API
|
||||||
token that has a `b_` prefix is not unqiue enough to use `generateUniqueToken`,
|
token that has a `b_` prefix is not unique enough to use `generateUniqueToken`,
|
||||||
so instead we use `generateSemiGenericRegex` and require a `beamer`
|
so instead we use `generateSemiGenericRegex` and require a `beamer`
|
||||||
identifier is part of the rule.
|
identifier is part of the rule.
|
||||||
If a token's prefix has more than `3` characters then you could
|
If a token's prefix has more than `3` characters then you could
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
</p>
|
</p>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
### Join our Discord! [](https://discord.gg/sydS6AHTUP)
|
||||||
|
|
||||||
Gitleaks is a SAST tool for **detecting** and **preventing** hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks is an **easy-to-use, all-in-one solution** for detecting secrets, past or present, in your code.
|
Gitleaks is a SAST tool for **detecting** and **preventing** hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks is an **easy-to-use, all-in-one solution** for detecting secrets, past or present, in your code.
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -66,7 +68,7 @@ docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [
|
|||||||
|
|
||||||
# Docker (ghcr.io)
|
# Docker (ghcr.io)
|
||||||
docker pull ghcr.io/gitleaks/gitleaks:latest
|
docker pull ghcr.io/gitleaks/gitleaks:latest
|
||||||
docker run -v ${path_to_host_folder_to_scan}:/path gitleaks/gitleaks:latest [COMMAND] --source="/path" [OPTIONS]
|
docker run -v ${path_to_host_folder_to_scan}:/path ghcr.io/gitleaks/gitleaks:latest [COMMAND] --source="/path" [OPTIONS]
|
||||||
|
|
||||||
# From Source
|
# From Source
|
||||||
git clone https://github.com/gitleaks/gitleaks.git
|
git clone https://github.com/gitleaks/gitleaks.git
|
||||||
@@ -155,7 +157,7 @@ Flags:
|
|||||||
--no-color turn off color for verbose output
|
--no-color turn off color for verbose output
|
||||||
--no-banner suppress banner
|
--no-banner suppress banner
|
||||||
--redact redact secrets from logs and stdout
|
--redact redact secrets from logs and stdout
|
||||||
-f, --report-format string output format (json, csv, sarif) (default "json")
|
-f, --report-format string output format (json, csv, junit, sarif) (default "json")
|
||||||
-r, --report-path string report file
|
-r, --report-path string report file
|
||||||
-s, --source string path to source (default ".")
|
-s, --source string path to source (default ".")
|
||||||
-v, --verbose show verbose output from scan
|
-v, --verbose show verbose output from scan
|
||||||
@@ -182,7 +184,7 @@ You can scan files and directories by using the `--no-git` option.
|
|||||||
|
|
||||||
#### Protect
|
#### Protect
|
||||||
|
|
||||||
The `protect` command is used to uncommitted changes in a git repo. This command should be used on developer machines in accordance with
|
The `protect` command is used to scan uncommitted changes in a git repo. This command should be used on developer machines in accordance with
|
||||||
[shifting left on security](https://cloud.google.com/architecture/devops/devops-tech-shifting-left-on-security).
|
[shifting left on security](https://cloud.google.com/architecture/devops/devops-tech-shifting-left-on-security).
|
||||||
When running `protect` on a git repository, gitleaks will parse the output of a `git diff` command (you can see how this executed
|
When running `protect` on a git repository, gitleaks will parse the output of a `git diff` command (you can see how this executed
|
||||||
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L48-L49)). You can set the
|
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L48-L49)). You can set the
|
||||||
@@ -270,7 +272,7 @@ Gitleaks offers a configuration format you can follow to write your own secret d
|
|||||||
title = "Gitleaks title"
|
title = "Gitleaks title"
|
||||||
|
|
||||||
# Extend the base (this) configuration. When you extend a configuration
|
# Extend the base (this) configuration. When you extend a configuration
|
||||||
# the base rules take precendence over the extended rules. I.e, if there are
|
# the base rules take precedence over the extended rules. I.e., if there are
|
||||||
# duplicate rules in both the base configuration and the extended configuration
|
# duplicate rules in both the base configuration and the extended configuration
|
||||||
# the base rules will override the extended rules.
|
# the base rules will override the extended rules.
|
||||||
# Another thing to know with extending configurations is you can chain together
|
# Another thing to know with extending configurations is you can chain together
|
||||||
|
|||||||
+18
-1
@@ -20,7 +20,7 @@ func init() {
|
|||||||
detectCmd.Flags().Bool("no-git", false, "treat git repo as a regular directory and scan those files, --log-opts has no effect on the scan when --no-git is set")
|
detectCmd.Flags().Bool("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("pipe", false, "scan input from stdin, ex: `cat some_file | gitleaks detect --pipe`")
|
||||||
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
|
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
|
||||||
|
detectCmd.Flags().StringP("gitleaks-ignore-path", "i", ".", "path to .gitleaksignore file or folder containing one")
|
||||||
}
|
}
|
||||||
|
|
||||||
var detectCmd = &cobra.Command{
|
var detectCmd = &cobra.Command{
|
||||||
@@ -81,6 +81,23 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gitleaksIgnorePath, err := cmd.Flags().GetString("gitleaks-ignore-path")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not get .gitleaksignore path")
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(gitleaksIgnorePath) {
|
||||||
|
if err = detector.AddGitleaksIgnore(gitleaksIgnorePath); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")) {
|
||||||
|
if err = detector.AddGitleaksIgnore(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ func main() {
|
|||||||
configRules = append(configRules, rules.Heroku())
|
configRules = append(configRules, rules.Heroku())
|
||||||
configRules = append(configRules, rules.HubSpot())
|
configRules = append(configRules, rules.HubSpot())
|
||||||
configRules = append(configRules, rules.Intercom())
|
configRules = append(configRules, rules.Intercom())
|
||||||
|
configRules = append(configRules, rules.JFrogAPIKey())
|
||||||
|
configRules = append(configRules, rules.JFrogIdentityToken())
|
||||||
configRules = append(configRules, rules.JWT())
|
configRules = append(configRules, rules.JWT())
|
||||||
configRules = append(configRules, rules.KrakenAccessToken())
|
configRules = append(configRules, rules.KrakenAccessToken())
|
||||||
configRules = append(configRules, rules.KucoinAccessToken())
|
configRules = append(configRules, rules.KucoinAccessToken())
|
||||||
@@ -116,6 +118,7 @@ func main() {
|
|||||||
configRules = append(configRules, rules.NPM())
|
configRules = append(configRules, rules.NPM())
|
||||||
configRules = append(configRules, rules.NytimesAccessToken())
|
configRules = append(configRules, rules.NytimesAccessToken())
|
||||||
configRules = append(configRules, rules.OktaAccessToken())
|
configRules = append(configRules, rules.OktaAccessToken())
|
||||||
|
configRules = append(configRules, rules.OpenAI())
|
||||||
configRules = append(configRules, rules.PlaidAccessID())
|
configRules = append(configRules, rules.PlaidAccessID())
|
||||||
configRules = append(configRules, rules.PlaidSecretKey())
|
configRules = append(configRules, rules.PlaidSecretKey())
|
||||||
configRules = append(configRules, rules.PlaidAccessToken())
|
configRules = append(configRules, rules.PlaidAccessToken())
|
||||||
@@ -142,8 +145,16 @@ func main() {
|
|||||||
configRules = append(configRules, rules.ShopifySharedSecret())
|
configRules = append(configRules, rules.ShopifySharedSecret())
|
||||||
configRules = append(configRules, rules.SidekiqSecret())
|
configRules = append(configRules, rules.SidekiqSecret())
|
||||||
configRules = append(configRules, rules.SidekiqSensitiveUrl())
|
configRules = append(configRules, rules.SidekiqSensitiveUrl())
|
||||||
configRules = append(configRules, rules.SlackAccessToken())
|
configRules = append(configRules, rules.SlackBotToken())
|
||||||
configRules = append(configRules, rules.SlackWebHook())
|
configRules = append(configRules, rules.SlackUserToken())
|
||||||
|
configRules = append(configRules, rules.SlackAppLevelToken())
|
||||||
|
configRules = append(configRules, rules.SlackConfigurationToken())
|
||||||
|
configRules = append(configRules, rules.SlackConfigurationRefreshToken())
|
||||||
|
configRules = append(configRules, rules.SlackLegacyBotToken())
|
||||||
|
configRules = append(configRules, rules.SlackLegacyWorkspaceToken())
|
||||||
|
configRules = append(configRules, rules.SlackLegacyToken())
|
||||||
|
configRules = append(configRules, rules.SlackWebHookUrl())
|
||||||
|
configRules = append(configRules, rules.Snyk())
|
||||||
configRules = append(configRules, rules.StripeAccessToken())
|
configRules = append(configRules, rules.StripeAccessToken())
|
||||||
configRules = append(configRules, rules.SquareAccessToken())
|
configRules = append(configRules, rules.SquareAccessToken())
|
||||||
configRules = append(configRules, rules.SquareSpaceAccessToken())
|
configRules = append(configRules, rules.SquareSpaceAccessToken())
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ func Authress() *config.Rule {
|
|||||||
Description: "Authress Service Client Access Key",
|
Description: "Authress Service Client Access Key",
|
||||||
RuleID: "authress-service-client-access-key",
|
RuleID: "authress-service-client-access-key",
|
||||||
SecretGroup: 1,
|
SecretGroup: 1,
|
||||||
Regex: generateUniqueTokenRegex(`(?:sc|ext|scauth|authress)_[a-z0-9]{5,30}\.[a-z0-9]{4,6}\.acc_[a-z0-9-]{10,32}\.[a-z0-9+/_=-]{30,120}`),
|
Regex: generateUniqueTokenRegex(`(?:sc|ext|scauth|authress)_[a-z0-9]{5,30}\.[a-z0-9]{4,6}\.acc_[a-z0-9-]{10,32}\.[a-z0-9+/_=-]{30,120}`),
|
||||||
Keywords: []string{"sc_", "ext_", "scauth_", "authress_"},
|
Keywords: []string{"sc_", "ext_", "scauth_", "authress_"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ title = "gitleaks config"
|
|||||||
description = "global allow lists"
|
description = "global allow lists"
|
||||||
paths = [
|
paths = [
|
||||||
'''gitleaks.toml''',
|
'''gitleaks.toml''',
|
||||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket)$''',
|
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe)$''',
|
||||||
'''(go.mod|go.sum)$''',
|
'''(go.mod|go.sum)$''',
|
||||||
'''gradle.lockfile''',
|
'''gradle.lockfile''',
|
||||||
'''node_modules''',
|
'''node_modules''',
|
||||||
@@ -25,40 +25,39 @@ paths = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
{{ range $i, $rule := .Rules }}[[rules]]
|
{{ range $i, $rule := .Rules }}[[rules]]
|
||||||
{{ if and $rule.SecretGroup $rule.Entropy $rule.Allowlist.StopWords }}description = "{{$rule.Description}}"
|
|
||||||
id = "{{$rule.RuleID}}"
|
id = "{{$rule.RuleID}}"
|
||||||
|
description = "{{$rule.Description}}"
|
||||||
regex = '''{{$rule.Regex}}'''
|
regex = '''{{$rule.Regex}}'''
|
||||||
secretGroup = {{ $rule.SecretGroup }}
|
{{- with $rule.Path }}
|
||||||
entropy = {{ $rule.Entropy}}
|
path = '''{{ . }}'''{{ end -}}
|
||||||
|
{{- with $rule.SecretGroup }}
|
||||||
|
secretGroup = {{ . }}{{ end -}}
|
||||||
|
{{- with $rule.Entropy }}
|
||||||
|
entropy = {{ . }}{{ end -}}
|
||||||
|
{{- with $rule.Keywords }}
|
||||||
keywords = [
|
keywords = [
|
||||||
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
|
{{ range $j, $keyword := . }}"{{ $keyword }}",{{ end }}
|
||||||
]
|
]{{ end }}
|
||||||
|
{{- with $rule.Tags }}
|
||||||
|
tags = [
|
||||||
|
{{ range $j, $tag := . }}"{{ $tag }}",{{ end }}
|
||||||
|
]{{ end }}
|
||||||
|
{{ if or $rule.Allowlist.Regexes $rule.Allowlist.Paths $rule.Allowlist.Commits $rule.Allowlist.StopWords }}
|
||||||
[rules.allowlist]
|
[rules.allowlist]
|
||||||
stopwords= [{{ range $j, $stopword := $rule.Allowlist.StopWords }}
|
{{ with $rule.Allowlist.RegexTarget }}
|
||||||
"{{$stopword}}",{{end}}
|
regexTarget = "{{ . }}"{{ end -}}
|
||||||
]
|
{{- with $rule.Allowlist.Regexes }}
|
||||||
{{ else if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}"
|
regexes = [
|
||||||
id = "{{$rule.RuleID}}"
|
{{ range $j, $regex := . }}"{{ $regex }}",{{ end }}
|
||||||
regex = '''{{$rule.Regex}}'''
|
]{{ end }}
|
||||||
secretGroup = {{ $rule.SecretGroup }}
|
{{- with $rule.Allowlist.Paths }}paths = [
|
||||||
entropy = {{ $rule.Entropy}}
|
{{ range $j, $path := . }}"{{ $path }}",{{ end }}
|
||||||
keywords = [
|
]{{ end }}
|
||||||
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
|
{{- with $rule.Allowlist.Commits }}commits = [
|
||||||
]
|
{{ range $j, $commit := . }}"{{ $commit }}",{{ end }}
|
||||||
|
]{{ end }}
|
||||||
{{ else if $rule.SecretGroup }}description = "{{$rule.Description}}"
|
{{- with $rule.Allowlist.StopWords }}stopwords = [{{ range $j, $stopword := . }}
|
||||||
id = "{{$rule.RuleID}}"
|
"{{ $stopword }}",{{ end }}
|
||||||
regex = '''{{$rule.Regex}}'''
|
]{{ end }}
|
||||||
secretGroup = {{ $rule.SecretGroup }}
|
{{ end }}
|
||||||
keywords = [
|
{{ end }}
|
||||||
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
|
|
||||||
]
|
|
||||||
|
|
||||||
{{ else }}description = "{{$rule.Description}}"
|
|
||||||
id = "{{$rule.RuleID}}"
|
|
||||||
regex = '''{{$rule.Regex}}'''
|
|
||||||
keywords = [
|
|
||||||
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
|
|
||||||
]
|
|
||||||
|
|
||||||
{{end}}{{end}}
|
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package rules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||||
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func JFrogAPIKey() *config.Rule {
|
||||||
|
keywords := []string{"jfrog", "artifactory", "bintray", "xray"}
|
||||||
|
|
||||||
|
// Define Rule
|
||||||
|
r := config.Rule{
|
||||||
|
// Human readable description of the rule
|
||||||
|
Description: "JFrog API Key",
|
||||||
|
|
||||||
|
// Unique ID for the rule
|
||||||
|
RuleID: "jfrog-api-key",
|
||||||
|
|
||||||
|
// Regex capture group for the actual secret
|
||||||
|
SecretGroup: 1,
|
||||||
|
|
||||||
|
// Regex used for detecting secrets. See regex section below for more details
|
||||||
|
Regex: generateSemiGenericRegex(keywords, alphaNumeric("73")),
|
||||||
|
|
||||||
|
// Keywords used for string matching on fragments (think of this as a prefilter)
|
||||||
|
Keywords: keywords,
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
fmt.Sprintf("--set imagePullSecretJfrog.password=%s", secrets.NewSecret(alphaNumeric("73"))),
|
||||||
|
}
|
||||||
|
return validate(r, tps, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func JFrogIdentityToken() *config.Rule {
|
||||||
|
keywords := []string{"jfrog", "artifactory", "bintray", "xray"}
|
||||||
|
|
||||||
|
// Define Rule
|
||||||
|
r := config.Rule{
|
||||||
|
// Human readable description of the rule
|
||||||
|
Description: "JFrog Identity Token",
|
||||||
|
|
||||||
|
// Unique ID for the rule
|
||||||
|
RuleID: "jfrog-identity-token",
|
||||||
|
|
||||||
|
// Regex capture group for the actual secret
|
||||||
|
SecretGroup: 1,
|
||||||
|
|
||||||
|
// Regex used for detecting secrets. See regex section below for more details
|
||||||
|
Regex: generateSemiGenericRegex(keywords, alphaNumeric("64")),
|
||||||
|
|
||||||
|
// Keywords used for string matching on fragments (think of this as a prefilter)
|
||||||
|
Keywords: keywords,
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
generateSampleSecret("jfrog", secrets.NewSecret(alphaNumeric("64"))),
|
||||||
|
generateSampleSecret("artifactory", secrets.NewSecret(alphaNumeric("64"))),
|
||||||
|
generateSampleSecret("bintray", secrets.NewSecret(alphaNumeric("64"))),
|
||||||
|
generateSampleSecret("xray", secrets.NewSecret(alphaNumeric("64"))),
|
||||||
|
}
|
||||||
|
return validate(r, tps, nil)
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package rules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||||
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OpenAI() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
RuleID: "openai-api-key",
|
||||||
|
Description: "OpenAI API Key",
|
||||||
|
Regex: generateUniqueTokenRegex(`sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20}`),
|
||||||
|
SecretGroup: 1,
|
||||||
|
Keywords: []string{
|
||||||
|
"T3BlbkFJ",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
generateSampleSecret("openaiApiKey", "sk-"+secrets.NewSecret(alphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(alphaNumeric("20"))),
|
||||||
|
}
|
||||||
|
return validate(r, tps, nil)
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ func PlaidAccessID() *config.Rule {
|
|||||||
Description: "Plaid Client ID",
|
Description: "Plaid Client ID",
|
||||||
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("24")),
|
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("24")),
|
||||||
SecretGroup: 1,
|
SecretGroup: 1,
|
||||||
|
Entropy: 3.5,
|
||||||
Keywords: []string{
|
Keywords: []string{
|
||||||
"plaid",
|
"plaid",
|
||||||
},
|
},
|
||||||
@@ -33,6 +34,7 @@ func PlaidSecretKey() *config.Rule {
|
|||||||
Description: "Plaid Secret key",
|
Description: "Plaid Secret key",
|
||||||
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("30")),
|
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("30")),
|
||||||
SecretGroup: 1,
|
SecretGroup: 1,
|
||||||
|
Entropy: 3.5,
|
||||||
Keywords: []string{
|
Keywords: []string{
|
||||||
"plaid",
|
"plaid",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const (
|
|||||||
identifierSuffix = `)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}`
|
identifierSuffix = `)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}`
|
||||||
|
|
||||||
// commonly used assignment operators or function call
|
// commonly used assignment operators or function call
|
||||||
operator = `(?:=|>|:=|\|\|:|<=|=>|:)`
|
operator = `(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)`
|
||||||
|
|
||||||
// boundaries for the secret
|
// boundaries for the secret
|
||||||
// \x60 = `
|
// \x60 = `
|
||||||
@@ -75,7 +75,7 @@ func validate(r config.Rule, truePositives []string, falsePositives []string) *c
|
|||||||
}
|
}
|
||||||
for _, fp := range falsePositives {
|
for _, fp := range falsePositives {
|
||||||
if len(d.DetectString(fp)) != 0 {
|
if len(d.DetectString(fp)) != 0 {
|
||||||
log.Fatal().Msgf("Failed to validate (fp) [%s]", r.RuleID)
|
log.Fatal().Msgf("Failed to validate. For rule ID [%s], false positive [%s] was detected by regexp [%s]", r.RuleID, fp, r.Regex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &r
|
return &r
|
||||||
|
|||||||
@@ -1,42 +1,264 @@
|
|||||||
package rules
|
package rules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||||
"github.com/zricethezav/gitleaks/v8/config"
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SlackAccessToken() *config.Rule {
|
// https://api.slack.com/authentication/token-types#bot
|
||||||
|
func SlackBotToken() *config.Rule {
|
||||||
// define rule
|
// define rule
|
||||||
r := config.Rule{
|
r := config.Rule{
|
||||||
Description: "Slack token",
|
Description: "Slack Bot token",
|
||||||
RuleID: "slack-access-token",
|
RuleID: "slack-bot-token",
|
||||||
Regex: regexp.MustCompile(
|
Regex: regexp.MustCompile(
|
||||||
"xox[baprs]-([0-9a-zA-Z]{10,48})"),
|
`(xoxb-[0-9]{10,13}\-[0-9]{10,13}[a-zA-Z0-9-]*)`),
|
||||||
Keywords: []string{
|
Keywords: []string{
|
||||||
"xoxb",
|
"xoxb",
|
||||||
"xoxa",
|
|
||||||
"xoxp",
|
|
||||||
"xoxr",
|
|
||||||
"xoxs",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
tps := []string{
|
tps := []string{
|
||||||
"\"slackToken\": \"xoxb-" + secrets.NewSecret(alphaNumeric("30")) + "\"",
|
// https://github.com/metabase/metabase/blob/74cfb332140680425c7d37d347854160cc997ea8/frontend/src/metabase/admin/settings/slack/components/SlackForm/SlackForm.tsx#L47
|
||||||
|
`"bot_token1": "xoxb-781236542736-2364535789652-GkwFDQoHqzXDVsC6GzqYUypD"`, // gitleaks:allow
|
||||||
|
// https://github.com/jonz-secops/TokenTester/blob/978e9f3eabc7e9978769cfbba10735afa3bf627e/slack#LL44C27-L44C86
|
||||||
|
`"bot_token2": "xoxb-263594206564-2343594206574-FGqddMF8t08v8N7Oq4i57vs1MBS"`, // gitleaks:allow
|
||||||
|
`"bot_token3": "xoxb-4614724432022-5152386766518-O5WzjWGLG0wcCm2WPrjEmnys"`, // gitleaks:allow
|
||||||
|
`"bot_token4": ` + fmt.Sprintf(`"xoxb-%s-%s-%s"`, secrets.NewSecret(numeric("13")), secrets.NewSecret(numeric("12")), secrets.NewSecret(alphaNumeric("24"))),
|
||||||
|
}
|
||||||
|
fps := []string{
|
||||||
|
"xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx",
|
||||||
|
"xoxb-xxx",
|
||||||
|
"xoxb-12345-abcd234",
|
||||||
|
"xoxb-xoxb-my-bot-token",
|
||||||
|
}
|
||||||
|
return validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://api.slack.com/authentication/token-types#user
|
||||||
|
func SlackUserToken() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Slack User",
|
||||||
|
RuleID: "slack-user-token",
|
||||||
|
// The last segment seems to be consistently 32 characters. I've made it 28-34 just in case.
|
||||||
|
Regex: regexp.MustCompile(`(xox[pe](?:-[0-9]{10,13}){3}-[a-zA-Z0-9-]{28,34})`),
|
||||||
|
Keywords: []string{"xoxp-", "xoxe-"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
// https://github.com/jonz-secops/TokenTester/blob/978e9f3eabc7e9978769cfbba10735afa3bf627e/slack#L25
|
||||||
|
`"user_token1": "xoxp-41684372915-1320496754-45609968301-e708ba56e1517a99f6b5fb07349476ef"`, // gitleaks:allow
|
||||||
|
// https://github.com/praetorian-inc/noseyparker/blob/16e0e5768fd14ea54f6c9a058566184d88343bb4/crates/noseyparker/data/default/rules/slack.yml#L29
|
||||||
|
`"user_token2": "xoxp-283316862324-298911817009-298923149681-44f585044dace54f5701618e97cd1c0b"`, // gitleaks:allow
|
||||||
|
// https://github.com/CloudBoost/cloudboost/blob/7ba2ed17099fa85e6fc652302822601283c6fa13/user-service/services/mailService.js#LL248C17-L248C92
|
||||||
|
`"user_token3": "xoxp-11873098179-111402824422-234336993777-b96c9fb3b69f82ebb79d12f280779de1"`, // gitleaks:allow
|
||||||
|
// https://github.com/evanyeung/terminal-slack/blob/b068f77808de72424d08b525d6cbf814849acd08/readme.md?plain=1#L66
|
||||||
|
`"user_token4": "xoxp-254112160503-252950188691-252375361712-6cbf56aada30951a9d310a5f23d032a0"`, // gitleaks:allow
|
||||||
|
`"user_token5": "xoxp-4614724432022-4621207627011-5182682871568-1ddad9823e8528ad0f4944dfa3c6fc6c"`, // gitleaks:allow
|
||||||
|
`"user_token6": ` + fmt.Sprintf(`"xoxp-%s-%s-%s-%s"`, secrets.NewSecret(numeric("12")), secrets.NewSecret(numeric("13")), secrets.NewSecret(numeric("13")), secrets.NewSecret(alphaNumeric("32"))),
|
||||||
|
// It's unclear what the `xoxe-` token means in this context, however, the format is similar to a user token.
|
||||||
|
`"url_private": "https:\/\/files.slack.com\/files-pri\/T04MCQMEXQ9-F04MAA1PKE3\/image.png?t=xoxe-4726837507825-4848681849303-4856614048758-e0b1f3d4cb371f92260edb0d9444d206"`,
|
||||||
|
}
|
||||||
|
fps := []string{
|
||||||
|
`https://docs.google.com/document/d/1W7KCxOxP-1Fy5EyF2lbJGE2WuKmu5v0suYqoHas1jRM`,
|
||||||
|
`"token1": "xoxp-1234567890"`, // gitleaks:allow
|
||||||
|
`"token2": "xoxp-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"`, // gitleaks:allow
|
||||||
|
`"token3": "xoxp-1234-1234-1234-4ddbc191d40ee098cbaae6f3523ada2d"`, // gitleaks:allow
|
||||||
|
`"token4": "xoxp-572370529330-573807301142-572331691188-####################"`, // gitleaks:allow
|
||||||
|
// This technically matches the pattern but is an obvious false positive.
|
||||||
|
// `"token5": "xoxp-000000000000-000000000000-000000000000-00000000000000000000000000000000"`, // gitleaks:allow
|
||||||
|
}
|
||||||
|
return validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference: https://api.slack.com/authentication/token-types#app
|
||||||
|
func SlackAppLevelToken() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Slack App-level token",
|
||||||
|
RuleID: "slack-app-token",
|
||||||
|
// This regex is based on a limited number of examples and may not be 100% accurate.
|
||||||
|
Regex: regexp.MustCompile(`(?i)(xapp-\d-[A-Z0-9]+-\d+-[a-z0-9]+)`),
|
||||||
|
Keywords: []string{"xapp"},
|
||||||
|
}
|
||||||
|
|
||||||
|
tps := []string{
|
||||||
|
// https://github.com/jonz-secops/TokenTester/blob/978e9f3eabc7e9978769cfbba10735afa3bf627e/slack#L17
|
||||||
|
`"token1": "xapp-1-A052FGTS2DL-5171572773297-610b6a11f4b7eb819e87b767d80e6575a3634791acb9a9ead051da879eb5b55e"`, // gitleaks:allow
|
||||||
|
`"token2": "xapp-1-IEMF8IMY1OQ-4037076220459-85c370b433e366de369c4ef5abdf41253519266982439a75af74a3d68d543fb6"`, // gitleaks:allow
|
||||||
|
`"token3": "xapp-1-BM3V7LC51DA-1441525068281-86641a2582cd0903402ab523e5bcc53b8253098c31591e529b55b41974d2e82f"`, // gitleaks:allow
|
||||||
|
`"token4": ` + fmt.Sprintf(`"xapp-1-A%s-%s-%s"`, secrets.NewSecret(numeric("10")), secrets.NewSecret(numeric("13")), secrets.NewSecret(alphaNumeric("64"))),
|
||||||
}
|
}
|
||||||
return validate(r, tps, nil)
|
return validate(r, tps, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SlackWebHook() *config.Rule {
|
// Reference: https://api.slack.com/authentication/config-tokens
|
||||||
|
func SlackConfigurationToken() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Slack Configuration access token",
|
||||||
|
RuleID: "slack-config-access-token",
|
||||||
|
Regex: regexp.MustCompile(`(?i)(xoxe.xox[bp]-\d-[A-Z0-9]{163,166})`),
|
||||||
|
Keywords: []string{"xoxe.xoxb-", "xoxe.xoxp-"},
|
||||||
|
}
|
||||||
|
|
||||||
|
tps := []string{
|
||||||
|
`"access_token1": "xoxe.xoxp-1-Mi0yLTM0MTQwNDE0MDE3Ni0zNjU5NDY0Njg4MTctNTE4MjA3NTQ5NjA4MC01NDEyOTYyODY5NzUxLThhMTBjZmI1ZWIzMGIwNTg0ZDdmMDI5Y2UxNzVlZWVhYzU2ZWQyZTZiODNjNDZiMGUxMzRlNmNjNDEwYmQxMjQ"`, // gitleaks:allow
|
||||||
|
`"access_token2": "xoxe.xoxp-1-Mi0yLTMxNzcwMjQ0MTcxMy0zNjU5NDY0Njg4MTctNTE1ODE1MjY5MTcxNC01MTU4MDI0MTgyOTc5LWRmY2YwY2U4ODhhNzY5ZGU5MTAyNDU4MDJjMGQ0ZDliMTZhMjNkMmEyYzliNjkzMDRlN2VjZTI4MWNiMzRkNGQ"`, // gitleaks:allow
|
||||||
|
`"access_token3": "xoxe.xoxp-1-` + secrets.NewSecret(alphaNumeric("163")) + `"`,
|
||||||
|
`"access_token4": "xoxe.xoxb-1-Mi0yLTMxNzcwMjQ0MTcxMy0zNjU5NDY0Njg4MTctNTE1ODE1MjY5MTcxNC01MTU4MDI0MTgyOTc5LWRmY2YwY2U4ODhhNzY5ZGU5MTAyNDU4MDJjMGQ0ZDliMTZhMjNkMmEyYzliNjkzMDRlN2VjZTI4MWNiMzRkNGQ"`,
|
||||||
|
`"access_token5": "xoxe.xoxb-1-` + secrets.NewSecret(alphaNumeric("165")) + `"`,
|
||||||
|
}
|
||||||
|
fps := []string{
|
||||||
|
"xoxe.xoxp-1-SlackAppConfigurationAccessTokenHere",
|
||||||
|
"xoxe.xoxp-1-RANDOMSTRINGHERE",
|
||||||
|
"xoxe.xoxp-1-initial",
|
||||||
|
}
|
||||||
|
return validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference: https://api.slack.com/authentication/config-tokens
|
||||||
|
func SlackConfigurationRefreshToken() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Slack Configuration refresh token",
|
||||||
|
RuleID: "slack-config-refresh-token",
|
||||||
|
Regex: regexp.MustCompile(`(?i)(xoxe-\d-[A-Z0-9]{146})`),
|
||||||
|
Keywords: []string{"xoxe-"},
|
||||||
|
}
|
||||||
|
|
||||||
|
tps := []string{
|
||||||
|
`"refresh_token1": "xoxe-1-My0xLTMxNzcwMjQ0MTcxMy01MTU4MTUyNjkxNzE0LTUxODE4NDI0MDY3MzYtMjA5MGFkOTFlZThkZWE2OGFlZDYwYWJjODNhYzAxYjA5ZjVmODBhYjgzN2QyNDdjOTNlOGY5NTg2YWM1OGM4Mg"`, // gitleaks:allow
|
||||||
|
`"refresh_token2": "xoxe-1-My0xLTM0MTQwNDE0MDE3Ni01MTgyMDc1NDk2MDgwLTU0MjQ1NjIwNzgxODEtNGJkYTZhYTUxY2M1ODk3ZTNkN2YzMTgxMDI1ZDQzNzgwNWY4NWQ0ODdhZGIzM2ViOGI0MTM0MjdlNGVmYzQ4Ng"`, // gitleaks:allow
|
||||||
|
`"refresh_token3": "xoxe-1-` + secrets.NewSecret(alphaNumeric("146")) + `"`,
|
||||||
|
}
|
||||||
|
fps := []string{"xoxe-1-xxx", "XOxE-RROAmw, Home and Garden, 5:24, 20120323"}
|
||||||
|
return validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference: https://api.slack.com/authentication/token-types#legacy_bot
|
||||||
|
func SlackLegacyBotToken() *config.Rule {
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Slack Legacy bot token",
|
||||||
|
RuleID: "slack-legacy-bot-token",
|
||||||
|
// This rule is based off the limited information I could find and may not be 100% accurate.
|
||||||
|
Regex: regexp.MustCompile(
|
||||||
|
`(xoxb-[0-9]{8,14}\-[a-zA-Z0-9]{18,26})`),
|
||||||
|
Keywords: []string{
|
||||||
|
"xoxb",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tps := []string{
|
||||||
|
// https://github.com/jonz-secops/TokenTester/blob/978e9f3eabc7e9978769cfbba10735afa3bf627e/slack#LL42C38-L42C80
|
||||||
|
`"bot_token1": "xoxb-263594206564-FGqddMF8t08v8N7Oq4i57vs1"`, // gitleaks:allow
|
||||||
|
// https://heejune.me/2018/08/01/crashdump-analysis-automation-using-slackbot-python-cdb-from-windows/
|
||||||
|
`"bot_token2": "xoxb-282029623751-BVtmnS3BQitmjZvjpQL7PSGP"`, // gitleaks:allow
|
||||||
|
// https://github.com/praetorian-inc/noseyparker/blob/16e0e5768fd14ea54f6c9a058566184d88343bb4/crates/noseyparker/data/default/rules/slack.yml#L15
|
||||||
|
`"bot_token3": "xoxb-47834520726-N3otsrwj8Cf99cs8GhiRZsX1"`, // gitleaks:allow
|
||||||
|
// https://github.com/pulumi/examples/blob/32d9047c19c2a9380c04e57a764321c25eef45b0/aws-js-sqs-slack/README.md?plain=1#L39
|
||||||
|
`"bot_token4": "xoxb-123456789012-Xw937qtWSXJss1lFaKe"`, // gitleaks:allow
|
||||||
|
// https://github.com/ilyasProgrammer/Odoo-eBay-Amazon/blob/a9c4a8a7548b19027bc0fd904f8ae9249248a293/custom_logging/models.py#LL9C24-L9C66
|
||||||
|
`"bot_token5": "xoxb-312554961652-uSmliU84rFhnUSBq9YdKh6lS"`, // gitleaks:allow
|
||||||
|
// https://github.com/jay-johnson/sci-pype/blob/6bff42ea4eb32d35b9f223db312e4cd0d3911100/src/pycore.py#L37
|
||||||
|
`"bot_token6": "xoxb-51351043345-Lzwmto5IMVb8UK36MghZYMEi"`, // gitleaks:allow
|
||||||
|
// https://github.com/logicmoo/logicmoo_workspace/blob/2e1794f596121c9949deb3bfbd30d5b027a51d3d/packs_sys/slack_prolog/prolog/slack_client_old.pl#L28
|
||||||
|
`"bot_token7": "xoxb-130154379991-ogFL0OFP3w6AwdJuK7wLojpK"`, // gitleaks:allow
|
||||||
|
// https://github.com/sbarski/serverless-chatbot/blob/7d556897486f3fd53795907b7e33252e5cc6b3a3/Lesson%203/serverless.yml#L38
|
||||||
|
`"bot_token8": "xoxb-159279836768-FOst5DLfEzmQgkz7cte5qiI"`, // gitleaks:allow
|
||||||
|
`"bot_token9": "xoxb-50014434-slacktokenx29U9X1bQ"`, // gitleaks:allow
|
||||||
|
`"bot_token10": ` + fmt.Sprintf(`"xoxb-%s-%s`, secrets.NewSecret(numeric("10")), secrets.NewSecret(alphaNumeric("24"))), // gitleaks:allow
|
||||||
|
`"bot_token11": ` + fmt.Sprintf(`"xoxb-%s-%s`, secrets.NewSecret(numeric("12")), secrets.NewSecret(alphaNumeric("23"))), // gitleaks:allow
|
||||||
|
}
|
||||||
|
fps := []string{
|
||||||
|
"xoxb-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx", // gitleaks:allow
|
||||||
|
"xoxb-Slack_BOT_TOKEN",
|
||||||
|
"xoxb-abcdef-abcdef",
|
||||||
|
// "xoxb-0000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // gitleaks:allow
|
||||||
|
}
|
||||||
|
return validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference: https://api.slack.com/authentication/token-types#workspace
|
||||||
|
func SlackLegacyWorkspaceToken() *config.Rule {
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Slack Legacy Workspace token",
|
||||||
|
RuleID: "slack-legacy-workspace-token",
|
||||||
|
// This is by far the least confident pattern.
|
||||||
|
Regex: regexp.MustCompile(
|
||||||
|
`(xox[ar]-(?:\d-)?[0-9a-zA-Z]{8,48})`),
|
||||||
|
Keywords: []string{
|
||||||
|
"xoxa",
|
||||||
|
"xoxr",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tps := []string{
|
||||||
|
`"access_token": "xoxa-2-511111111-31111111111-3111111111111-e039d02840a0b9379c"`, // gitleaks:allow
|
||||||
|
`"access_token1": ` + fmt.Sprintf(`"xoxa-%s-%s`, secrets.NewSecret(numeric("1")), secrets.NewSecret(alphaNumeric("12"))),
|
||||||
|
`"access_token2": ` + fmt.Sprintf(`"xoxa-%s`, secrets.NewSecret(alphaNumeric("12"))),
|
||||||
|
`"refresh_token1": ` + fmt.Sprintf(`"xoxr-%s-%s`, secrets.NewSecret(numeric("1")), secrets.NewSecret(alphaNumeric("12"))),
|
||||||
|
`"refresh_token2": ` + fmt.Sprintf(`"xoxr-%s`, secrets.NewSecret(alphaNumeric("12"))),
|
||||||
|
}
|
||||||
|
fps := []string{
|
||||||
|
// "xoxa-faketoken",
|
||||||
|
// "xoxa-access-token-string",
|
||||||
|
// "XOXa-nx991k",
|
||||||
|
"https://github.com/xoxa-nyc/xoxa-nyc.github.io/blob/master/README.md",
|
||||||
|
}
|
||||||
|
return validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
|
// References:
|
||||||
|
// - https://api.slack.com/authentication/token-types#legacy
|
||||||
|
// - https://api.slack.com/changelog/2016-05-19-authorship-changing-for-older-tokens
|
||||||
|
// - https://github.com/jonz-secops/TokenTester/blob/978e9f3eabc7e9978769cfbba10735afa3bf627e/slack#L29
|
||||||
|
// - https://gist.github.com/thesubtlety/a1c460d53df0837c5817c478b9f10588#file-local-slack-jack-py-L32
|
||||||
|
func SlackLegacyToken() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Slack Legacy token",
|
||||||
|
RuleID: "slack-legacy-token",
|
||||||
|
Regex: regexp.MustCompile(`(xox[os]-\d+-\d+-\d+-[a-fA-F\d]+)`),
|
||||||
|
Keywords: []string{"xoxo", "xoxs"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
// https://github.com/GGStudy-DDUp/https-github.com-aldaor-HackerOneReports/blob/637e9261b63a7292a3a7ddf4bf13729c224d84df/PrivilegeEscalation/47940.txt#L23
|
||||||
|
`"access_token1": "xoxs-3206092076-3204538285-3743137121-836b042620"`, // gitleaks:allow
|
||||||
|
// https://github.com/jonz-secops/TokenTester/blob/978e9f3eabc7e9978769cfbba10735afa3bf627e/slack#L28
|
||||||
|
`"access_token2": "xoxs-416843729158-132049654-5609968301-e708ba56e1"`, // gitleaks:allow
|
||||||
|
// https://github.com/clr2of8/SlackExtract/blob/18d151152ff5a45b293d4b7193aa6d08f9ab1bfd/README.md?plain=1#L32
|
||||||
|
`"access_token3": "xoxs-420083410720-421837374423-440811613314-977844f625b707d5b0b268206dbc92cbc85feef3e71b08e44815a8e6e7657190"`, // gitleaks:allow
|
||||||
|
// https://github.com/zeroc00I/AllVideoPocsFromHackerOne/blob/95ae92f65ccef11c2c6acdaabfb7cc9b2b0eb4c6/jsonReports/61312.json#LL1C17-L1C17
|
||||||
|
`"access_token4": "xoxs-4829527689-4829527691-4814341714-d0346ec616"`, // gitleaks:allow
|
||||||
|
// https://github.com/ericvanderwal/general-playmaker/blob/34bd8e82e2d7b16ca9cc825d0c9d383b8378b550/Logic/setrandomseedtype.cs#LL783C15-L783C69
|
||||||
|
`"access_token5": "xoxs-155191149137-155868813314-338998331396-9f6d235915"`, // gitleaks:allow
|
||||||
|
`"access_token6": "xoxs-` + fmt.Sprintf("%s-%s-%s-%s", secrets.NewSecret(numeric("10")), secrets.NewSecret(numeric("10")), secrets.NewSecret(numeric("10")), secrets.NewSecret(hex("10"))) + `"`,
|
||||||
|
`"access_token7": "xoxo-523423-234243-234233-e039d02840a0b9379c"`, // gitleaks:allow
|
||||||
|
}
|
||||||
|
fps := []string{
|
||||||
|
"https://indieweb.org/images/3/35/2018-250-xoxo-indieweb-1.jpg",
|
||||||
|
"https://lh3.googleusercontent.com/-tWXjX3LUD6w/Ua4La_N5E2I/AAAAAAAAACg/qcm19xbEYa4/s640/EXO-XOXO-teaser-exo-k-34521098-720-516.jpg",
|
||||||
|
}
|
||||||
|
return validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SlackWebHookUrl() *config.Rule {
|
||||||
// define rule
|
// define rule
|
||||||
r := config.Rule{
|
r := config.Rule{
|
||||||
Description: "Slack Webhook",
|
Description: "Slack Webhook",
|
||||||
RuleID: "slack-web-hook",
|
RuleID: "slack-webhook-url",
|
||||||
|
// If this generates too many false-positives we should define an allowlist (e.g., "xxxx", "00000").
|
||||||
Regex: regexp.MustCompile(
|
Regex: regexp.MustCompile(
|
||||||
`https:\/\/hooks.slack.com\/(services|workflows)\/[A-Za-z0-9+\/]{44,46}`),
|
`(https?:\/\/)?hooks.slack.com\/(services|workflows)\/[A-Za-z0-9+\/]{43,46}`),
|
||||||
Keywords: []string{
|
Keywords: []string{
|
||||||
"hooks.slack.com",
|
"hooks.slack.com",
|
||||||
},
|
},
|
||||||
@@ -44,8 +266,16 @@ func SlackWebHook() *config.Rule {
|
|||||||
|
|
||||||
// validate
|
// validate
|
||||||
tps := []string{
|
tps := []string{
|
||||||
"https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
|
"hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")),
|
||||||
"https://hooks.slack.com/workflows/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
|
"http://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("45")),
|
||||||
|
"https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("46")),
|
||||||
|
"http://hooks.slack.com/services/T024TTTTT/BBB72BBL/AZAAA9u0pA4ad666eMgbi555", // gitleaks:allow
|
||||||
|
"https://hooks.slack.com/services/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", // gitleaks:allow
|
||||||
|
"hooks.slack.com/workflows/" + secrets.NewSecret(alphaNumeric("44")),
|
||||||
|
"http://hooks.slack.com/workflows/" + secrets.NewSecret(alphaNumeric("45")),
|
||||||
|
"https://hooks.slack.com/workflows/" + secrets.NewSecret(alphaNumeric("46")),
|
||||||
|
"https://hooks.slack.com/workflows/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", // gitleaks:allow
|
||||||
|
"http://hooks.slack.com/workflows/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", // gitleaks:allow
|
||||||
}
|
}
|
||||||
return validate(r, tps, nil)
|
return validate(r, tps, nil)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package rules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Snyk() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Snyk API token",
|
||||||
|
RuleID: "snyk-api-token",
|
||||||
|
SecretGroup: 1,
|
||||||
|
Regex: generateSemiGenericRegex([]string{"snyk"}, hex8_4_4_4_12()),
|
||||||
|
Keywords: []string{"snyk"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
`const SNYK_TOKEN = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
`const SNYK_KEY = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
`const SNYK = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
`SNYK = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
`SNYK_TOKEN := "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
`SNYK_TOKEN ::= "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
`SNYK_TOKEN :::= "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
`SNYK_TOKEN ?= "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
|
||||||
|
}
|
||||||
|
return validate(r, tps, nil)
|
||||||
|
}
|
||||||
@@ -28,9 +28,9 @@ func TelegramBotToken() *config.Rule {
|
|||||||
minToken := secrets.NewSecret(numeric("5") + ":A" + alphaNumericExtendedShort("34"))
|
minToken := secrets.NewSecret(numeric("5") + ":A" + alphaNumericExtendedShort("34"))
|
||||||
maxToken := secrets.NewSecret(numeric("16") + ":A" + alphaNumericExtendedShort("34"))
|
maxToken := secrets.NewSecret(numeric("16") + ":A" + alphaNumericExtendedShort("34"))
|
||||||
tps := []string{
|
tps := []string{
|
||||||
// variable assigment
|
// variable assignment
|
||||||
generateSampleSecret("telegram", validToken),
|
generateSampleSecret("telegram", validToken),
|
||||||
// URL contaning token
|
// URL containing token
|
||||||
generateSampleSecret("url", "https://api.telegram.org/bot"+validToken+"/sendMessage"),
|
generateSampleSecret("url", "https://api.telegram.org/bot"+validToken+"/sendMessage"),
|
||||||
// object constructor
|
// object constructor
|
||||||
`const bot = new Telegraf("` + validToken + `")`,
|
`const bot = new Telegraf("` + validToken + `")`,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
protectCmd.Flags().Bool("staged", false, "detect secrets in a --staged state")
|
protectCmd.Flags().Bool("staged", false, "detect secrets in a --staged state")
|
||||||
protectCmd.Flags().String("log-opts", "", "git log options")
|
protectCmd.Flags().String("log-opts", "", "git log options")
|
||||||
|
protectCmd.Flags().StringP("gitleaks-ignore-path", "i", ".", "path to .gitleaksignore file or folder containing one")
|
||||||
rootCmd.AddCommand(protectCmd)
|
rootCmd.AddCommand(protectCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +75,23 @@ func runProtect(cmd *cobra.Command, args []string) {
|
|||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gitleaksIgnorePath, err := cmd.Flags().GetString("gitleaks-ignore-path")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not get .gitleaksignore path")
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(gitleaksIgnorePath) {
|
||||||
|
if err = detector.AddGitleaksIgnore(gitleaksIgnorePath); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")) {
|
||||||
|
if err = detector.AddGitleaksIgnore(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().Int("exit-code", 1, "exit code when leaks have been encountered")
|
rootCmd.PersistentFlags().Int("exit-code", 1, "exit code when leaks have been encountered")
|
||||||
rootCmd.PersistentFlags().StringP("source", "s", ".", "path to source")
|
rootCmd.PersistentFlags().StringP("source", "s", ".", "path to source")
|
||||||
rootCmd.PersistentFlags().StringP("report-path", "r", "", "report file")
|
rootCmd.PersistentFlags().StringP("report-path", "r", "", "report file")
|
||||||
rootCmd.PersistentFlags().StringP("report-format", "f", "json", "output format (json, csv, sarif)")
|
rootCmd.PersistentFlags().StringP("report-format", "f", "json", "output format (json, csv, junit, sarif)")
|
||||||
rootCmd.PersistentFlags().StringP("baseline-path", "b", "", "path to baseline with issues that can be ignored")
|
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().StringP("log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal)")
|
||||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
||||||
|
|||||||
+338
-242
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func IsNew(finding report.Finding, baseline []report.Finding) bool {
|
func IsNew(finding report.Finding, baseline []report.Finding) bool {
|
||||||
// Explicitly testing each property as it gives significantly better performance in comparison to cmp.Equal(). Drawback is that
|
// Explicitly testing each property as it gives significantly better performance in comparison to cmp.Equal(). Drawback is that
|
||||||
// the code requires maintanance if/when the Finding struct changes
|
// the code requires maintenance if/when the Finding struct changes
|
||||||
for _, b := range baseline {
|
for _, b := range baseline {
|
||||||
|
|
||||||
if finding.Author == b.Author &&
|
if finding.Author == b.Author &&
|
||||||
|
|||||||
+84
-58
@@ -147,14 +147,19 @@ func NewDetectorDefaultConfig() (*Detector, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
|
func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
|
||||||
log.Debug().Msg("found .gitleaksignore file")
|
log.Debug().Msgf("found .gitleaksignore file: %s", gitleaksIgnorePath)
|
||||||
file, err := os.Open(gitleaksIgnorePath)
|
file, err := os.Open(gitleaksIgnorePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer file.Close()
|
// https://github.com/securego/gosec/issues/512
|
||||||
|
defer func() {
|
||||||
|
if err := file.Close(); err != nil {
|
||||||
|
log.Warn().Msgf("Error closing .gitleaksignore file: %s\n", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
@@ -287,6 +292,17 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extract secret from secret group if set
|
||||||
|
if rule.SecretGroup != 0 {
|
||||||
|
groups := rule.Regex.FindStringSubmatch(secret)
|
||||||
|
if len(groups) <= rule.SecretGroup || len(groups) == 0 {
|
||||||
|
// Config validation should prevent this
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
secret = groups[rule.SecretGroup]
|
||||||
|
finding.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
// check if the regexTarget is defined in the allowlist "regexes" entry
|
// check if the regexTarget is defined in the allowlist "regexes" entry
|
||||||
allowlistTarget := finding.Secret
|
allowlistTarget := finding.Secret
|
||||||
switch rule.Allowlist.RegexTarget {
|
switch rule.Allowlist.RegexTarget {
|
||||||
@@ -308,17 +324,6 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract secret from secret group if set
|
|
||||||
if rule.SecretGroup != 0 {
|
|
||||||
groups := rule.Regex.FindStringSubmatch(secret)
|
|
||||||
if len(groups) <= rule.SecretGroup || len(groups) == 0 {
|
|
||||||
// Config validation should prevent this
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
secret = groups[rule.SecretGroup]
|
|
||||||
finding.Secret = secret
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the secret is in the list of stopwords
|
// check if the secret is in the list of stopwords
|
||||||
if rule.Allowlist.ContainsStopWord(finding.Secret) ||
|
if rule.Allowlist.ContainsStopWord(finding.Secret) ||
|
||||||
d.Config.Allowlist.ContainsStopWord(finding.Secret) {
|
d.Config.Allowlist.ContainsStopWord(finding.Secret) {
|
||||||
@@ -352,70 +357,85 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
|
|||||||
return findings
|
return findings
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitScan accepts a *gitdiff.File channel which contents a git history generated from
|
// DetectGit accepts source directory, log opts and GitScanType and returns a slice of report.Finding.
|
||||||
// the output of `git log -p ...`. startGitScan will look at each file (patch) in the history
|
|
||||||
// and determine if the patch contains any findings.
|
|
||||||
func (d *Detector) DetectGit(source string, logOpts string, gitScanType GitScanType) ([]report.Finding, error) {
|
func (d *Detector) DetectGit(source string, logOpts string, gitScanType GitScanType) ([]report.Finding, error) {
|
||||||
var (
|
var (
|
||||||
gitdiffFiles <-chan *gitdiff.File
|
diffFilesCmd *git.DiffFilesCmd
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
switch gitScanType {
|
switch gitScanType {
|
||||||
case DetectType:
|
case DetectType:
|
||||||
gitdiffFiles, err = git.GitLog(source, logOpts)
|
diffFilesCmd, err = git.NewGitLogCmd(source, logOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d.findings, err
|
return d.findings, err
|
||||||
}
|
}
|
||||||
case ProtectType:
|
case ProtectType:
|
||||||
gitdiffFiles, err = git.GitDiff(source, false)
|
diffFilesCmd, err = git.NewGitDiffCmd(source, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d.findings, err
|
return d.findings, err
|
||||||
}
|
}
|
||||||
case ProtectStagedType:
|
case ProtectStagedType:
|
||||||
gitdiffFiles, err = git.GitDiff(source, true)
|
diffFilesCmd, err = git.NewGitDiffCmd(source, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d.findings, err
|
return d.findings, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
defer diffFilesCmd.Wait()
|
||||||
|
diffFilesCh := diffFilesCmd.DiffFilesCh()
|
||||||
|
errCh := diffFilesCmd.ErrCh()
|
||||||
|
|
||||||
s := semgroup.NewGroup(context.Background(), 4)
|
s := semgroup.NewGroup(context.Background(), 4)
|
||||||
|
|
||||||
for gitdiffFile := range gitdiffFiles {
|
// loop to range over both DiffFiles (stdout) and ErrCh (stderr)
|
||||||
gitdiffFile := gitdiffFile
|
for diffFilesCh != nil || errCh != nil {
|
||||||
|
select {
|
||||||
|
case gitdiffFile, open := <-diffFilesCh:
|
||||||
|
if !open {
|
||||||
|
diffFilesCh = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// skip binary files
|
// skip binary files
|
||||||
if gitdiffFile.IsBinary || gitdiffFile.IsDelete {
|
if gitdiffFile.IsBinary || gitdiffFile.IsDelete {
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if commit is allowed
|
|
||||||
commitSHA := ""
|
|
||||||
if gitdiffFile.PatchHeader != nil {
|
|
||||||
commitSHA = gitdiffFile.PatchHeader.SHA
|
|
||||||
if d.Config.Allowlist.CommitAllowed(gitdiffFile.PatchHeader.SHA) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
d.addCommit(commitSHA)
|
|
||||||
|
|
||||||
s.Go(func() error {
|
// Check if commit is allowed
|
||||||
for _, textFragment := range gitdiffFile.TextFragments {
|
commitSHA := ""
|
||||||
if textFragment == nil {
|
if gitdiffFile.PatchHeader != nil {
|
||||||
return nil
|
commitSHA = gitdiffFile.PatchHeader.SHA
|
||||||
}
|
if d.Config.Allowlist.CommitAllowed(gitdiffFile.PatchHeader.SHA) {
|
||||||
|
continue
|
||||||
fragment := Fragment{
|
|
||||||
Raw: textFragment.Raw(gitdiff.OpAdd),
|
|
||||||
CommitSHA: commitSHA,
|
|
||||||
FilePath: gitdiffFile.NewName,
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, finding := range d.Detect(fragment) {
|
|
||||||
d.addFinding(augmentGitFinding(finding, textFragment, gitdiffFile))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
d.addCommit(commitSHA)
|
||||||
})
|
|
||||||
|
s.Go(func() error {
|
||||||
|
for _, textFragment := range gitdiffFile.TextFragments {
|
||||||
|
if textFragment == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment := Fragment{
|
||||||
|
Raw: textFragment.Raw(gitdiff.OpAdd),
|
||||||
|
CommitSHA: commitSHA,
|
||||||
|
FilePath: gitdiffFile.NewName,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, finding := range d.Detect(fragment) {
|
||||||
|
d.addFinding(augmentGitFinding(finding, textFragment, gitdiffFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
case err, open := <-errCh:
|
||||||
|
if !open {
|
||||||
|
errCh = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.findings, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.Wait(); err != nil {
|
if err := s.Wait(); err != nil {
|
||||||
@@ -423,9 +443,6 @@ func (d *Detector) DetectGit(source string, logOpts string, gitScanType GitScanT
|
|||||||
}
|
}
|
||||||
log.Info().Msgf("%d commits scanned.", 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")
|
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
|
return d.findings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,16 +610,25 @@ func (d *Detector) Detect(fragment Fragment) []report.Finding {
|
|||||||
|
|
||||||
// addFinding synchronously adds a finding to the findings slice
|
// addFinding synchronously adds a finding to the findings slice
|
||||||
func (d *Detector) addFinding(finding report.Finding) {
|
func (d *Detector) addFinding(finding report.Finding) {
|
||||||
if finding.Commit == "" {
|
globalFingerprint := fmt.Sprintf("%s:%s:%d", finding.File, finding.RuleID, finding.StartLine)
|
||||||
finding.Fingerprint = fmt.Sprintf("%s:%s:%d", finding.File, finding.RuleID, finding.StartLine)
|
if finding.Commit != "" {
|
||||||
} else {
|
|
||||||
finding.Fingerprint = fmt.Sprintf("%s:%s:%s:%d", finding.Commit, finding.File, finding.RuleID, finding.StartLine)
|
finding.Fingerprint = fmt.Sprintf("%s:%s:%s:%d", finding.Commit, finding.File, finding.RuleID, finding.StartLine)
|
||||||
|
} else {
|
||||||
|
finding.Fingerprint = globalFingerprint
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we should ignore this finding
|
// check if we should ignore this finding
|
||||||
if _, ok := d.gitleaksIgnore[finding.Fingerprint]; ok {
|
if _, ok := d.gitleaksIgnore[globalFingerprint]; ok {
|
||||||
log.Debug().Msgf("ignoring finding with Fingerprint %s",
|
log.Debug().Msgf("ignoring finding with global Fingerprint %s",
|
||||||
finding.Fingerprint)
|
finding.Fingerprint)
|
||||||
return
|
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 {
|
||||||
|
log.Debug().Msgf("ignoring finding with Fingerprint %s",
|
||||||
|
finding.Fingerprint)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.baseline != nil && !IsNew(finding, d.baseline) {
|
if d.baseline != nil && !IsNew(finding, d.baseline) {
|
||||||
|
|||||||
+41
-2
@@ -6,6 +6,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ func TestDetect(t *testing.T) {
|
|||||||
fragment Fragment
|
fragment Fragment
|
||||||
// NOTE: for expected findings, all line numbers will be 0
|
// NOTE: for expected findings, all line numbers will be 0
|
||||||
// because line deltas are added _after_ the finding is created.
|
// 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
|
// 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,
|
// increase by 1 in DetectFromFiles(). If the finding is from git,
|
||||||
// the line number will be increased by the patch delta.
|
// the line number will be increased by the patch delta.
|
||||||
expectedFindings []report.Finding
|
expectedFindings []report.Finding
|
||||||
@@ -474,6 +475,22 @@ func TestFromGit(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
detector := NewDetector(cfg)
|
detector := NewDetector(cfg)
|
||||||
|
|
||||||
|
var ignorePath string
|
||||||
|
info, err := os.Stat(tt.source)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
ignorePath = filepath.Join(tt.source, ".gitleaksignore")
|
||||||
|
} else {
|
||||||
|
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
|
||||||
|
}
|
||||||
|
if err = detector.AddGitleaksIgnore(ignorePath); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
|
||||||
findings, err := detector.DetectGit(tt.source, tt.logOpts, DetectType)
|
findings, err := detector.DetectGit(tt.source, tt.logOpts, DetectType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -554,7 +571,9 @@ func TestFromGitStaged(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
detector := NewDetector(cfg)
|
detector := NewDetector(cfg)
|
||||||
detector.AddGitleaksIgnore(filepath.Join(tt.source, ".gitleaksignore"))
|
if err = detector.AddGitleaksIgnore(filepath.Join(tt.source, ".gitleaksignore")); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
findings, err := detector.DetectGit(tt.source, tt.logOpts, ProtectStagedType)
|
findings, err := detector.DetectGit(tt.source, tt.logOpts, ProtectStagedType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -617,6 +636,11 @@ func TestFromFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
source: filepath.Join(repoBasePath, "nogit", "api.go"),
|
||||||
|
cfgName: "simple",
|
||||||
|
expectedFindings: []report.Finding{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@@ -635,6 +659,21 @@ func TestFromFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
cfg, _ := vc.Translate()
|
cfg, _ := vc.Translate()
|
||||||
detector := NewDetector(cfg)
|
detector := NewDetector(cfg)
|
||||||
|
|
||||||
|
var ignorePath string
|
||||||
|
info, err := os.Stat(tt.source)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
ignorePath = filepath.Join(tt.source, ".gitleaksignore")
|
||||||
|
} else {
|
||||||
|
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
|
||||||
|
}
|
||||||
|
if err = detector.AddGitleaksIgnore(ignorePath); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
detector.FollowSymlinks = true
|
detector.FollowSymlinks = true
|
||||||
findings, err := detector.DetectFiles(tt.source)
|
findings, err := detector.DetectFiles(tt.source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+90
-30
@@ -2,26 +2,49 @@ package git
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrEncountered bool
|
var quotedOptPattern = regexp.MustCompile(`^(?:"[^"]+"|'[^']+')$`)
|
||||||
|
|
||||||
// GitLog returns a channel of gitdiff.File objects from the
|
// DiffFilesCmd helps to work with Git's output.
|
||||||
// git log -p command for the given source.
|
type DiffFilesCmd struct {
|
||||||
func GitLog(source string, logOpts string) (<-chan *gitdiff.File, error) {
|
cmd *exec.Cmd
|
||||||
|
diffFilesCh <-chan *gitdiff.File
|
||||||
|
errCh <-chan error
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGitLogCmd returns `*DiffFilesCmd` with two channels: `<-chan *gitdiff.File` and `<-chan error`.
|
||||||
|
// Caller should read everything from channels until receiving a signal about their closure and call
|
||||||
|
// the `func (*DiffFilesCmd) Wait()` error in order to release resources.
|
||||||
|
func NewGitLogCmd(source string, logOpts string) (*DiffFilesCmd, error) {
|
||||||
sourceClean := filepath.Clean(source)
|
sourceClean := filepath.Clean(source)
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if logOpts != "" {
|
if logOpts != "" {
|
||||||
args := []string{"-C", sourceClean, "log", "-p", "-U0"}
|
args := []string{"-C", sourceClean, "log", "-p", "-U0"}
|
||||||
args = append(args, strings.Split(logOpts, " ")...)
|
|
||||||
|
// Ensure that the user-provided |logOpts| aren't wrapped in quotes.
|
||||||
|
// https://github.com/gitleaks/gitleaks/issues/1153
|
||||||
|
userArgs := strings.Split(logOpts, " ")
|
||||||
|
var quotedOpts []string
|
||||||
|
for _, element := range userArgs {
|
||||||
|
if quotedOptPattern.MatchString(element) {
|
||||||
|
quotedOpts = append(quotedOpts, element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(quotedOpts) > 0 {
|
||||||
|
log.Warn().Msgf("the following `--log-opts` values may not work as expected: %v\n\tsee https://github.com/gitleaks/gitleaks/issues/1153 for more information", quotedOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, userArgs...)
|
||||||
cmd = exec.Command("git", args...)
|
cmd = exec.Command("git", args...)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command("git", "-C", sourceClean, "log", "-p", "-U0",
|
cmd = exec.Command("git", "-C", sourceClean, "log", "-p", "-U0",
|
||||||
@@ -38,21 +61,29 @@ func GitLog(source string, logOpts string) (<-chan *gitdiff.File, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
go listenForStdErr(stderr)
|
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// HACK: to avoid https://github.com/zricethezav/gitleaks/issues/722
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
|
|
||||||
return gitdiff.Parse(cmd, stdout)
|
errCh := make(chan error)
|
||||||
|
go listenForStdErr(stderr, errCh)
|
||||||
|
|
||||||
|
gitdiffFiles, err := gitdiff.Parse(stdout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &DiffFilesCmd{
|
||||||
|
cmd: cmd,
|
||||||
|
diffFilesCh: gitdiffFiles,
|
||||||
|
errCh: errCh,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitDiff returns a channel of gitdiff.File objects from
|
// NewGitDiffCmd returns `*DiffFilesCmd` with two channels: `<-chan *gitdiff.File` and `<-chan error`.
|
||||||
// the git diff command for the given source.
|
// Caller should read everything from channels until receiving a signal about their closure and call
|
||||||
func GitDiff(source string, staged bool) (<-chan *gitdiff.File, error) {
|
// the `func (*DiffFilesCmd) Wait()` error in order to release resources.
|
||||||
|
func NewGitDiffCmd(source string, staged bool) (*DiffFilesCmd, error) {
|
||||||
sourceClean := filepath.Clean(source)
|
sourceClean := filepath.Clean(source)
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
cmd = exec.Command("git", "-C", sourceClean, "diff", "-U0", ".")
|
cmd = exec.Command("git", "-C", sourceClean, "diff", "-U0", ".")
|
||||||
@@ -70,21 +101,50 @@ func GitDiff(source string, staged bool) (<-chan *gitdiff.File, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
go listenForStdErr(stderr)
|
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// HACK: to avoid https://github.com/zricethezav/gitleaks/issues/722
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
|
|
||||||
return gitdiff.Parse(cmd, stdout)
|
errCh := make(chan error)
|
||||||
|
go listenForStdErr(stderr, errCh)
|
||||||
|
|
||||||
|
gitdiffFiles, err := gitdiff.Parse(stdout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &DiffFilesCmd{
|
||||||
|
cmd: cmd,
|
||||||
|
diffFilesCh: gitdiffFiles,
|
||||||
|
errCh: errCh,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// listenForStdErr listens for stderr output from git and prints it to stdout
|
// DiffFilesCh returns a channel with *gitdiff.File.
|
||||||
// then exits with exit code 1
|
func (c *DiffFilesCmd) DiffFilesCh() <-chan *gitdiff.File {
|
||||||
func listenForStdErr(stderr io.ReadCloser) {
|
return c.diffFilesCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrCh returns a channel that could produce an error if there is something in stderr.
|
||||||
|
func (c *DiffFilesCmd) ErrCh() <-chan error {
|
||||||
|
return c.errCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait waits for the command to exit and waits for any copying to
|
||||||
|
// stdin or copying from stdout or stderr to complete.
|
||||||
|
//
|
||||||
|
// Wait also closes underlying stdout and stderr.
|
||||||
|
func (c *DiffFilesCmd) Wait() (err error) {
|
||||||
|
return c.cmd.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
// listenForStdErr listens for stderr output from git, prints it to stdout,
|
||||||
|
// sends to errCh and closes it.
|
||||||
|
func listenForStdErr(stderr io.ReadCloser, errCh chan<- error) {
|
||||||
|
defer close(errCh)
|
||||||
|
|
||||||
|
var errEncountered bool
|
||||||
|
|
||||||
scanner := bufio.NewScanner(stderr)
|
scanner := bufio.NewScanner(stderr)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
// if git throws one of the following errors:
|
// if git throws one of the following errors:
|
||||||
@@ -110,12 +170,12 @@ func listenForStdErr(stderr io.ReadCloser) {
|
|||||||
log.Warn().Msg(scanner.Text())
|
log.Warn().Msg(scanner.Text())
|
||||||
} else {
|
} else {
|
||||||
log.Error().Msgf("[git] %s", scanner.Text())
|
log.Error().Msgf("[git] %s", scanner.Text())
|
||||||
|
errEncountered = true
|
||||||
// asynchronously set this error flag to true so that we can
|
|
||||||
// capture a log message and exit with a non-zero exit code
|
|
||||||
// This value should get set before the `git` command exits so it's
|
|
||||||
// safe-ish, although I know I know, bad practice.
|
|
||||||
ErrEncountered = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errEncountered {
|
||||||
|
errCh <- errors.New("stderr is not empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+44
-38
@@ -74,7 +74,7 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
|
|||||||
|
|
||||||
genericMatch := strings.Replace(f.Match, f.Secret, "REDACTED", -1)
|
genericMatch := strings.Replace(f.Match, f.Secret, "REDACTED", -1)
|
||||||
betterMatch := strings.Replace(fPrime.Match, fPrime.Secret, "REDACTED", -1)
|
betterMatch := strings.Replace(fPrime.Match, fPrime.Secret, "REDACTED", -1)
|
||||||
log.Trace().Msgf("skipping %s finding (%s), %s rule takes precendence (%s)", f.RuleID, genericMatch, fPrime.RuleID, betterMatch)
|
log.Trace().Msgf("skipping %s finding (%s), %s rule takes precedence (%s)", f.RuleID, genericMatch, fPrime.RuleID, betterMatch)
|
||||||
include = false
|
include = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -92,57 +92,63 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printFinding(f report.Finding, noColor bool) {
|
func printFinding(f report.Finding, noColor bool) {
|
||||||
// trim all whitespace and tabs from the line
|
// trim all whitespace and tabs
|
||||||
f.Line = strings.TrimSpace(f.Line)
|
f.Line = strings.TrimSpace(f.Line)
|
||||||
// trim all whitespace and tabs from the secret
|
|
||||||
f.Secret = strings.TrimSpace(f.Secret)
|
f.Secret = strings.TrimSpace(f.Secret)
|
||||||
// trim all whitespace and tabs from the match
|
|
||||||
f.Match = strings.TrimSpace(f.Match)
|
f.Match = strings.TrimSpace(f.Match)
|
||||||
|
|
||||||
matchInLineIDX := strings.Index(f.Line, f.Match)
|
isFileMatch := strings.HasPrefix(f.Match, "file detected:")
|
||||||
secretInMatchIdx := strings.Index(f.Match, f.Secret)
|
skipColor := noColor
|
||||||
|
finding := ""
|
||||||
|
var secret lipgloss.Style
|
||||||
|
|
||||||
skipColor := false
|
// Matches from filenames do not have a |line| or |secret|
|
||||||
|
if !isFileMatch {
|
||||||
|
matchInLineIDX := strings.Index(f.Line, f.Match)
|
||||||
|
secretInMatchIdx := strings.Index(f.Match, f.Secret)
|
||||||
|
|
||||||
if matchInLineIDX == -1 || noColor {
|
skipColor = false
|
||||||
skipColor = true
|
|
||||||
matchInLineIDX = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
start := f.Line[0:matchInLineIDX]
|
if matchInLineIDX == -1 || noColor {
|
||||||
startMatchIdx := 0
|
skipColor = true
|
||||||
if matchInLineIDX > 20 {
|
matchInLineIDX = 0
|
||||||
startMatchIdx = matchInLineIDX - 20
|
}
|
||||||
start = "..." + f.Line[startMatchIdx:matchInLineIDX]
|
|
||||||
}
|
|
||||||
|
|
||||||
matchBeginning := lipgloss.NewStyle().SetString(f.Match[0:secretInMatchIdx]).Foreground(lipgloss.Color("#f5d445"))
|
start := f.Line[0:matchInLineIDX]
|
||||||
secret := lipgloss.NewStyle().SetString(f.Secret).
|
startMatchIdx := 0
|
||||||
Bold(true).
|
if matchInLineIDX > 20 {
|
||||||
Italic(true).
|
startMatchIdx = matchInLineIDX - 20
|
||||||
Foreground(lipgloss.Color("#f05c07"))
|
start = "..." + f.Line[startMatchIdx:matchInLineIDX]
|
||||||
matchEnd := lipgloss.NewStyle().SetString(f.Match[secretInMatchIdx+len(f.Secret):]).Foreground(lipgloss.Color("#f5d445"))
|
}
|
||||||
|
|
||||||
lineEndIdx := matchInLineIDX + len(f.Match)
|
matchBeginning := lipgloss.NewStyle().SetString(f.Match[0:secretInMatchIdx]).Foreground(lipgloss.Color("#f5d445"))
|
||||||
if len(f.Line)-1 <= lineEndIdx {
|
secret = lipgloss.NewStyle().SetString(f.Secret).
|
||||||
lineEndIdx = len(f.Line) - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
lineEnd := f.Line[matchInLineIDX+len(f.Match):]
|
|
||||||
|
|
||||||
if len(f.Secret) > 100 {
|
|
||||||
secret = lipgloss.NewStyle().SetString(f.Secret[0:100] + "...").
|
|
||||||
Bold(true).
|
Bold(true).
|
||||||
Italic(true).
|
Italic(true).
|
||||||
Foreground(lipgloss.Color("#f05c07"))
|
Foreground(lipgloss.Color("#f05c07"))
|
||||||
}
|
matchEnd := lipgloss.NewStyle().SetString(f.Match[secretInMatchIdx+len(f.Secret):]).Foreground(lipgloss.Color("#f5d445"))
|
||||||
if len(lineEnd) > 20 {
|
|
||||||
lineEnd = lineEnd[0:20] + "..."
|
lineEndIdx := matchInLineIDX + len(f.Match)
|
||||||
|
if len(f.Line)-1 <= lineEndIdx {
|
||||||
|
lineEndIdx = len(f.Line) - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
lineEnd := f.Line[lineEndIdx:]
|
||||||
|
|
||||||
|
if len(f.Secret) > 100 {
|
||||||
|
secret = lipgloss.NewStyle().SetString(f.Secret[0:100] + "...").
|
||||||
|
Bold(true).
|
||||||
|
Italic(true).
|
||||||
|
Foreground(lipgloss.Color("#f05c07"))
|
||||||
|
}
|
||||||
|
if len(lineEnd) > 20 {
|
||||||
|
lineEnd = lineEnd[0:20] + "..."
|
||||||
|
}
|
||||||
|
|
||||||
|
finding = fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
finding := fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
|
if skipColor || isFileMatch {
|
||||||
|
|
||||||
if skipColor {
|
|
||||||
fmt.Printf("%-12s %s\n", "Finding:", f.Match)
|
fmt.Printf("%-12s %s\n", "Finding:", f.Match)
|
||||||
fmt.Printf("%-12s %s\n", "Secret:", f.Secret)
|
fmt.Printf("%-12s %s\n", "Secret:", f.Secret)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
github.com/charmbracelet/lipgloss v0.5.0
|
github.com/charmbracelet/lipgloss v0.5.0
|
||||||
github.com/fatih/semgroup v1.2.0
|
github.com/fatih/semgroup v1.2.0
|
||||||
github.com/gitleaks/go-gitdiff v0.8.0
|
github.com/gitleaks/go-gitdiff v0.9.0
|
||||||
github.com/h2non/filetype v1.1.3
|
github.com/h2non/filetype v1.1.3
|
||||||
github.com/rs/zerolog v1.26.1
|
github.com/rs/zerolog v1.26.1
|
||||||
github.com/spf13/cobra v1.2.1
|
github.com/spf13/cobra v1.2.1
|
||||||
@@ -14,11 +14,12 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.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-isatty v0.0.17 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 // indirect
|
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 // indirect
|
||||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
|
github.com/muesli/termenv v0.15.1 // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ require (
|
|||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/subosito/gotenv v1.2.0 // indirect
|
github.com/subosito/gotenv v1.2.0 // indirect
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect
|
golang.org/x/sys v0.6.0 // indirect
|
||||||
golang.org/x/text v0.3.6 // indirect
|
golang.org/x/text v0.3.6 // indirect
|
||||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
|
|||||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||||
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||||
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
|
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
@@ -74,8 +76,8 @@ github.com/fatih/semgroup v1.2.0/go.mod h1:1KAD4iIYfXjE4U13B48VM4z9QUwV5Tt8O4rS8
|
|||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||||
github.com/gitleaks/go-gitdiff v0.8.0 h1:7aExTZm+K/M/EQKOyYcub8rIAdWK6ONxPGuRzxmWW+0=
|
github.com/gitleaks/go-gitdiff v0.9.0 h1:SHAU2l0ZBEo8g82EeFewhVy81sb7JCxW76oSPtR/Nqg=
|
||||||
github.com/gitleaks/go-gitdiff v0.8.0/go.mod h1:pKz0X4YzCKZs30BL+weqBIG7mx0jl4tF1uXV9ZyNvrA=
|
github.com/gitleaks/go-gitdiff v0.9.0/go.mod h1:pKz0X4YzCKZs30BL+weqBIG7mx0jl4tF1uXV9ZyNvrA=
|
||||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
@@ -193,11 +195,13 @@ github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaW
|
|||||||
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
|
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||||
|
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
|
||||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||||
@@ -213,8 +217,9 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
|||||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=
|
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=
|
||||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
|
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
|
||||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 h1:STjmj0uFfRryL9fzRA/OupNppeAID6QJYPMavTL7jtY=
|
|
||||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
||||||
|
github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs=
|
||||||
|
github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ=
|
||||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||||
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
|
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
|
||||||
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
@@ -432,8 +437,9 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
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-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 h1:WecRHqgE09JBkh/584XIE6PMz5KKE/vER4izNUi30AQ=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
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=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeCsv writes the list of findings to a writeCloser.
|
// writeCsv writes the list of findings to a writeCloser.
|
||||||
@@ -28,6 +29,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
|
|||||||
"Date",
|
"Date",
|
||||||
"Email",
|
"Email",
|
||||||
"Fingerprint",
|
"Fingerprint",
|
||||||
|
"Tags",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -48,6 +50,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
|
|||||||
f.Date,
|
f.Date,
|
||||||
f.Email,
|
f.Email,
|
||||||
f.Fingerprint,
|
f.Fingerprint,
|
||||||
|
strings.Join(f.Tags, " "),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
+4
-9
@@ -1,6 +1,7 @@
|
|||||||
package report
|
package report
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -34,6 +35,7 @@ func TestWriteCSV(t *testing.T) {
|
|||||||
Email: "johndoe@gmail.com",
|
Email: "johndoe@gmail.com",
|
||||||
Date: "10-19-2003",
|
Date: "10-19-2003",
|
||||||
Fingerprint: "fingerprint",
|
Fingerprint: "fingerprint",
|
||||||
|
Tags: []string{"tag1", "tag2", "tag3"},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
{
|
{
|
||||||
@@ -45,42 +47,35 @@ func TestWriteCSV(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
tmpfile, err := os.Create(filepath.Join(tmpPath, test.testReportName+".csv"))
|
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".csv"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
err = writeCsv(test.findings, tmpfile)
|
err = writeCsv(test.findings, tmpfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
got, err := os.ReadFile(tmpfile.Name())
|
got, err := os.ReadFile(tmpfile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if test.wantEmpty {
|
if test.wantEmpty {
|
||||||
if len(got) > 0 {
|
if len(got) > 0 {
|
||||||
t.Errorf("Expected empty file, got %s", got)
|
t.Errorf("Expected empty file, got %s", got)
|
||||||
}
|
}
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
want, err := os.ReadFile(test.expected)
|
want, err := os.ReadFile(test.expected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(got) != string(want) {
|
if !bytes.Equal(got, want) {
|
||||||
err = os.WriteFile(strings.Replace(test.expected, ".csv", ".got.csv", 1), got, 0644)
|
err = os.WriteFile(strings.Replace(test.expected, ".csv", ".got.csv", 1), got, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
t.Errorf("got %s, want %s", string(got), string(want))
|
t.Errorf("got %s, want %s", string(got), string(want))
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -38,7 +38,7 @@ type Finding struct {
|
|||||||
// Rule is the name of the rule that was matched
|
// Rule is the name of the rule that was matched
|
||||||
RuleID string
|
RuleID string
|
||||||
|
|
||||||
// unique identifer
|
// unique identifier
|
||||||
Fingerprint string
|
Fingerprint string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ func writeJson(findings []Finding, w io.WriteCloser) error {
|
|||||||
if len(findings) == 0 {
|
if len(findings) == 0 {
|
||||||
findings = []Finding{}
|
findings = []Finding{}
|
||||||
}
|
}
|
||||||
|
defer w.Close()
|
||||||
|
|
||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
encoder.SetIndent("", " ")
|
encoder.SetIndent("", " ")
|
||||||
return encoder.Encode(findings)
|
return encoder.Encode(findings)
|
||||||
|
|||||||
+3
-11
@@ -1,6 +1,7 @@
|
|||||||
package report
|
package report
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -46,44 +47,35 @@ func TestWriteJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
// create tmp file using os.TempDir()
|
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".json"))
|
||||||
tmpfile, err := os.Create(filepath.Join(tmpPath, test.testReportName+".json"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
err = writeJson(test.findings, tmpfile)
|
err = writeJson(test.findings, tmpfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
got, err := os.ReadFile(tmpfile.Name())
|
got, err := os.ReadFile(tmpfile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if test.wantEmpty {
|
if test.wantEmpty {
|
||||||
if len(got) > 0 {
|
if len(got) > 0 {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Errorf("Expected empty file, got %s", got)
|
t.Errorf("Expected empty file, got %s", got)
|
||||||
}
|
}
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
want, err := os.ReadFile(test.expected)
|
want, err := os.ReadFile(test.expected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(got) != string(want) {
|
if !bytes.Equal(got, want) {
|
||||||
err = os.WriteFile(strings.Replace(test.expected, ".json", ".got.json", 1), got, 0644)
|
err = os.WriteFile(strings.Replace(test.expected, ".json", ".got.json", 1), got, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
t.Errorf("got %s, want %s", string(got), string(want))
|
t.Errorf("got %s, want %s", string(got), string(want))
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
package report
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func writeJunit(findings []Finding, w io.WriteCloser) error {
|
||||||
|
testSuites := TestSuites{
|
||||||
|
TestSuites: getTestSuites(findings),
|
||||||
|
}
|
||||||
|
|
||||||
|
io.WriteString(w, xml.Header)
|
||||||
|
encoder := xml.NewEncoder(w)
|
||||||
|
encoder.Indent("", "\t")
|
||||||
|
return encoder.Encode(testSuites)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTestSuites(findings []Finding) []TestSuite {
|
||||||
|
return []TestSuite{
|
||||||
|
{
|
||||||
|
Failures: strconv.Itoa(len(findings)),
|
||||||
|
Name: "gitleaks",
|
||||||
|
Tests: strconv.Itoa(len(findings)),
|
||||||
|
TestCases: getTestCases(findings),
|
||||||
|
Time: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTestCases(findings []Finding) []TestCase {
|
||||||
|
testCases := []TestCase{}
|
||||||
|
for _, f := range findings {
|
||||||
|
testCase := TestCase{
|
||||||
|
Classname: f.Description,
|
||||||
|
Failure: getFailure(f),
|
||||||
|
File: f.File,
|
||||||
|
Name: getMessage(f),
|
||||||
|
Time: "",
|
||||||
|
}
|
||||||
|
testCases = append(testCases, testCase)
|
||||||
|
}
|
||||||
|
return testCases
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFailure(f Finding) Failure {
|
||||||
|
return Failure{
|
||||||
|
Data: getData(f),
|
||||||
|
Message: getMessage(f),
|
||||||
|
Type: f.Description,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getData(f Finding) string {
|
||||||
|
data, err := json.MarshalIndent(f, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMessage(f Finding) string {
|
||||||
|
if f.Commit == "" {
|
||||||
|
return fmt.Sprintf("%s has detected a secret in file %s, line %s.", f.RuleID, f.File, strconv.Itoa(f.StartLine))
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s has detected a secret in file %s, line %s, at commit %s.", f.RuleID, f.File, strconv.Itoa(f.StartLine), f.Commit)
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestSuites struct {
|
||||||
|
XMLName xml.Name `xml:"testsuites"`
|
||||||
|
TestSuites []TestSuite
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestSuite struct {
|
||||||
|
XMLName xml.Name `xml:"testsuite"`
|
||||||
|
Failures string `xml:"failures,attr"`
|
||||||
|
Name string `xml:"name,attr"`
|
||||||
|
Tests string `xml:"tests,attr"`
|
||||||
|
TestCases []TestCase `xml:"testcase"`
|
||||||
|
Time string `xml:"time,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestCase struct {
|
||||||
|
XMLName xml.Name `xml:"testcase"`
|
||||||
|
Classname string `xml:"classname,attr"`
|
||||||
|
Failure Failure `xml:"failure"`
|
||||||
|
File string `xml:"file,attr"`
|
||||||
|
Name string `xml:"name,attr"`
|
||||||
|
Time string `xml:"time,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Failure struct {
|
||||||
|
XMLName xml.Name `xml:"failure"`
|
||||||
|
Data string `xml:",chardata"`
|
||||||
|
Message string `xml:"message,attr"`
|
||||||
|
Type string `xml:"type,attr"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package report
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWriteJunit(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
findings []Finding
|
||||||
|
testReportName string
|
||||||
|
expected string
|
||||||
|
wantEmpty bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testReportName: "simple",
|
||||||
|
expected: filepath.Join(expectPath, "report", "junit_simple.xml"),
|
||||||
|
findings: []Finding{
|
||||||
|
{
|
||||||
|
|
||||||
|
Description: "Test Rule",
|
||||||
|
RuleID: "test-rule",
|
||||||
|
Match: "line containing secret",
|
||||||
|
Secret: "a secret",
|
||||||
|
StartLine: 1,
|
||||||
|
EndLine: 2,
|
||||||
|
StartColumn: 1,
|
||||||
|
EndColumn: 2,
|
||||||
|
Message: "opps",
|
||||||
|
File: "auth.py",
|
||||||
|
Commit: "0000000000000000",
|
||||||
|
Author: "John Doe",
|
||||||
|
Email: "johndoe@gmail.com",
|
||||||
|
Date: "10-19-2003",
|
||||||
|
Tags: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
|
||||||
|
Description: "Test Rule",
|
||||||
|
RuleID: "test-rule",
|
||||||
|
Match: "line containing secret",
|
||||||
|
Secret: "a secret",
|
||||||
|
StartLine: 2,
|
||||||
|
EndLine: 3,
|
||||||
|
StartColumn: 1,
|
||||||
|
EndColumn: 2,
|
||||||
|
Message: "",
|
||||||
|
File: "auth.py",
|
||||||
|
Commit: "",
|
||||||
|
Author: "",
|
||||||
|
Email: "",
|
||||||
|
Date: "",
|
||||||
|
Tags: []string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testReportName: "empty",
|
||||||
|
expected: filepath.Join(expectPath, "report", "junit_empty.xml"),
|
||||||
|
findings: []Finding{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
// create tmp file using os.TempDir()
|
||||||
|
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".xml"))
|
||||||
|
if err != nil {
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
err = writeJunit(test.findings, tmpfile)
|
||||||
|
if err != nil {
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
got, err := os.ReadFile(tmpfile.Name())
|
||||||
|
if err != nil {
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if test.wantEmpty {
|
||||||
|
if len(got) > 0 {
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
t.Errorf("Expected empty file, got %s", got)
|
||||||
|
}
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
want, err := os.ReadFile(test.expected)
|
||||||
|
if err != nil {
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(got) != string(want) {
|
||||||
|
err = os.WriteFile(strings.Replace(test.expected, ".xml", ".got.xml", 1), got, 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
t.Errorf("got %s, want %s", string(got), string(want))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,8 @@ func Write(findings []Finding, cfg config.Config, ext string, reportPath string)
|
|||||||
err = writeJson(findings, file)
|
err = writeJson(findings, file)
|
||||||
case ".csv", "csv":
|
case ".csv", "csv":
|
||||||
err = writeCsv(findings, file)
|
err = writeCsv(findings, file)
|
||||||
|
case ".xml", "junit":
|
||||||
|
err = writeJunit(findings, file)
|
||||||
case ".sarif", "sarif":
|
case ".sarif", "sarif":
|
||||||
err = writeSarif(cfg, findings, file)
|
err = writeSarif(cfg, findings, file)
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-6
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
expectPath = "../testdata/expected/"
|
expectPath = "../testdata/expected/"
|
||||||
tmpPath = "../testdata/tmp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReport(t *testing.T) {
|
func TestReport(t *testing.T) {
|
||||||
@@ -69,6 +68,22 @@ func TestReport(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ext: ".xml",
|
||||||
|
findings: []Finding{
|
||||||
|
{
|
||||||
|
RuleID: "test-rule",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ext: "junit",
|
||||||
|
findings: []Finding{
|
||||||
|
{
|
||||||
|
RuleID: "test-rule",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
// {
|
// {
|
||||||
// ext: "SARIF",
|
// ext: "SARIF",
|
||||||
// findings: []Finding{
|
// findings: []Finding{
|
||||||
@@ -80,22 +95,18 @@ func TestReport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
tmpfile, err := os.Create(filepath.Join(tmpPath, strconv.Itoa(i)+test.ext))
|
tmpfile, err := os.Create(filepath.Join(t.TempDir(), strconv.Itoa(i)+test.ext))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
err = Write(test.findings, config.Config{}, test.ext, tmpfile.Name())
|
err = Write(test.findings, config.Config{}, test.ext, tmpfile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
got, err := os.ReadFile(tmpfile.Name())
|
got, err := os.ReadFile(tmpfile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
|
|
||||||
if len(got) == 0 && !test.wantEmpty {
|
if len(got) == 0 && !test.wantEmpty {
|
||||||
t.Errorf("got empty file with extension " + test.ext)
|
t.Errorf("got empty file with extension " + test.ext)
|
||||||
|
|||||||
+12
-1
@@ -10,10 +10,11 @@ import (
|
|||||||
|
|
||||||
func writeSarif(cfg config.Config, findings []Finding, w io.WriteCloser) error {
|
func writeSarif(cfg config.Config, findings []Finding, w io.WriteCloser) error {
|
||||||
sarif := Sarif{
|
sarif := Sarif{
|
||||||
Schema: "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
Schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
||||||
Version: "2.1.0",
|
Version: "2.1.0",
|
||||||
Runs: getRuns(cfg, findings),
|
Runs: getRuns(cfg, findings),
|
||||||
}
|
}
|
||||||
|
defer w.Close()
|
||||||
|
|
||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
encoder.SetIndent("", " ")
|
encoder.SetIndent("", " ")
|
||||||
@@ -34,6 +35,7 @@ func getTool(cfg config.Config) Tool {
|
|||||||
Driver: Driver{
|
Driver: Driver{
|
||||||
Name: driver,
|
Name: driver,
|
||||||
SemanticVersion: version,
|
SemanticVersion: version,
|
||||||
|
InformationUri: "https://github.com/gitleaks/gitleaks",
|
||||||
Rules: getRules(cfg),
|
Rules: getRules(cfg),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -102,6 +104,9 @@ func getResults(findings []Finding) []Results {
|
|||||||
Date: f.Date,
|
Date: f.Date,
|
||||||
Author: f.Author,
|
Author: f.Author,
|
||||||
},
|
},
|
||||||
|
Properties: Properties{
|
||||||
|
Tags: f.Tags,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
results = append(results, r)
|
results = append(results, r)
|
||||||
}
|
}
|
||||||
@@ -164,6 +169,7 @@ type Rules struct {
|
|||||||
type Driver struct {
|
type Driver struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
SemanticVersion string `json:"semanticVersion"`
|
SemanticVersion string `json:"semanticVersion"`
|
||||||
|
InformationUri string `json:"informationUri"`
|
||||||
Rules []Rules `json:"rules"`
|
Rules []Rules `json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,11 +206,16 @@ type Locations struct {
|
|||||||
PhysicalLocation PhysicalLocation `json:"physicalLocation"`
|
PhysicalLocation PhysicalLocation `json:"physicalLocation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Properties struct {
|
||||||
|
Tags []string `json:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
type Results struct {
|
type Results struct {
|
||||||
Message Message `json:"message"`
|
Message Message `json:"message"`
|
||||||
RuleId string `json:"ruleId"`
|
RuleId string `json:"ruleId"`
|
||||||
Locations []Locations `json:"locations"`
|
Locations []Locations `json:"locations"`
|
||||||
PartialFingerPrints `json:"partialFingerprints"`
|
PartialFingerPrints `json:"partialFingerprints"`
|
||||||
|
Properties Properties `json:"properties"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Runs struct {
|
type Runs struct {
|
||||||
|
|||||||
+4
-11
@@ -1,6 +1,7 @@
|
|||||||
package report
|
package report
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -42,16 +43,14 @@ func TestWriteSarif(t *testing.T) {
|
|||||||
Author: "John Doe",
|
Author: "John Doe",
|
||||||
Email: "johndoe@gmail.com",
|
Email: "johndoe@gmail.com",
|
||||||
Date: "10-19-2003",
|
Date: "10-19-2003",
|
||||||
Tags: []string{},
|
Tags: []string{"tag1", "tag2", "tag3"},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
// create tmp file using os.TempDir()
|
tmpfile, err := os.Create(filepath.Join(t.TempDir(), test.testReportName+".json"))
|
||||||
tmpfile, err := os.Create(filepath.Join(tmpPath, test.testReportName+".json"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
viper.Reset()
|
viper.Reset()
|
||||||
@@ -76,29 +75,24 @@ func TestWriteSarif(t *testing.T) {
|
|||||||
err = writeSarif(cfg, test.findings, tmpfile)
|
err = writeSarif(cfg, test.findings, tmpfile)
|
||||||
fmt.Println(cfg)
|
fmt.Println(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
got, err := os.ReadFile(tmpfile.Name())
|
got, err := os.ReadFile(tmpfile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if test.wantEmpty {
|
if test.wantEmpty {
|
||||||
if len(got) > 0 {
|
if len(got) > 0 {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Errorf("Expected empty file, got %s", got)
|
t.Errorf("Expected empty file, got %s", got)
|
||||||
}
|
}
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
want, err := os.ReadFile(test.expected)
|
want, err := os.ReadFile(test.expected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(got) != string(want) {
|
if !bytes.Equal(got, want) {
|
||||||
err = os.WriteFile(strings.Replace(test.expected, ".sarif", ".got.sarif", 1), got, 0644)
|
err = os.WriteFile(strings.Replace(test.expected, ".sarif", ".got.sarif", 1), got, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -106,6 +100,5 @@ func TestWriteSarif(t *testing.T) {
|
|||||||
t.Errorf("got %s, want %s", string(got), string(want))
|
t.Errorf("got %s, want %s", string(got), string(want))
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Remove(tmpfile.Name())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"runs": [
|
"runs": [
|
||||||
]
|
]
|
||||||
|
|||||||
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
RuleID,Commit,File,SymlinkFile,Secret,Match,StartLine,EndLine,StartColumn,EndColumn,Author,Message,Date,Email,Fingerprint
|
RuleID,Commit,File,SymlinkFile,Secret,Match,StartLine,EndLine,StartColumn,EndColumn,Author,Message,Date,Email,Fingerprint,Tags
|
||||||
test-rule,0000000000000000,auth.py,,a secret,line containing secret,1,2,1,2,John Doe,opps,10-19-2003,johndoe@gmail.com,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,tag1 tag2 tag3
|
||||||
|
+4
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite failures="0" name="gitleaks" tests="0" time=""></testsuite>
|
||||||
|
</testsuites>
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
</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>
|
||||||
|
</testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
+9
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"runs": [
|
"runs": [
|
||||||
{
|
{
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"driver": {
|
"driver": {
|
||||||
"name": "gitleaks",
|
"name": "gitleaks",
|
||||||
"semanticVersion": "v8.0.0",
|
"semanticVersion": "v8.0.0",
|
||||||
|
"informationUri": "https://github.com/gitleaks/gitleaks",
|
||||||
"rules": [
|
"rules": [
|
||||||
{
|
{
|
||||||
"id": "aws-access-key",
|
"id": "aws-access-key",
|
||||||
@@ -293,6 +294,13 @@
|
|||||||
"author": "John Doe",
|
"author": "John Doe",
|
||||||
"date": "10-19-2003",
|
"date": "10-19-2003",
|
||||||
"commitMessage": "opps"
|
"commitMessage": "opps"
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"tags": [
|
||||||
|
"tag1",
|
||||||
|
"tag2",
|
||||||
|
"tag3"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
../testdata/repos/nogit/api.go:aws-access-key:20
|
||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
var a = "initial"
|
||||||
|
fmt.Println(a)
|
||||||
|
|
||||||
|
var b, c int = 1, 2
|
||||||
|
fmt.Println(b, c)
|
||||||
|
|
||||||
|
var d = true
|
||||||
|
fmt.Println(d)
|
||||||
|
|
||||||
|
var e int
|
||||||
|
fmt.Println(e)
|
||||||
|
|
||||||
|
// opps I added a secret at line 20
|
||||||
|
awsToken := "AKIALALEMEL33243OLIA"
|
||||||
|
|
||||||
|
f := "apple"
|
||||||
|
fmt.Println(f)
|
||||||
|
}
|
||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
api/ignoreGlobal.go:aws-access-key:20
|
||||||
|
53cd7a3c6eb4937f413e3c25e4a9f39289afa69e:api/ignoreCommit.go:aws-access-key:20
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
var a = "initial"
|
||||||
|
fmt.Println(a)
|
||||||
|
|
||||||
|
var b, c int = 1, 2
|
||||||
|
fmt.Println(b, c)
|
||||||
|
|
||||||
|
var d = true
|
||||||
|
fmt.Println(d)
|
||||||
|
|
||||||
|
var e int
|
||||||
|
fmt.Println(e)
|
||||||
|
|
||||||
|
// opps I added a secret at line 20
|
||||||
|
awsToken := "AKIALALEMEL33243OLIA"
|
||||||
|
|
||||||
|
f := "apple"
|
||||||
|
fmt.Println(f)
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
var a = "initial"
|
||||||
|
fmt.Println(a)
|
||||||
|
|
||||||
|
var b, c int = 1, 2
|
||||||
|
fmt.Println(b, c)
|
||||||
|
|
||||||
|
var d = true
|
||||||
|
fmt.Println(d)
|
||||||
|
|
||||||
|
var e int
|
||||||
|
fmt.Println(e)
|
||||||
|
|
||||||
|
// opps I added a secret at line 20
|
||||||
|
awsToken := "AKIALALEMEL33243OLIA"
|
||||||
|
|
||||||
|
f := "apple"
|
||||||
|
fmt.Println(f)
|
||||||
|
}
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
removing secret from foo package
|
add .gitleaksignore test files
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587
|
cada78a9bf157ec05573f19e682d211f811c2e2d
|
||||||
Vendored
BIN
Binary file not shown.
+4
@@ -11,3 +11,7 @@ a122b33c6bad3ee54724f52f2caad385ab1982ab 1b6da43b82b22e4eaa10bcf8ee591e91abbfc58
|
|||||||
f1b58b97808f8e744f6a23c693859df5b5968901 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635897009 -0500 checkout: moving from foo to main
|
f1b58b97808f8e744f6a23c693859df5b5968901 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635897009 -0500 checkout: moving from foo to main
|
||||||
2e1db472eeba53f06c4026ae4566ea022e36598e f1b58b97808f8e744f6a23c693859df5b5968901 Zach Rice <zricer@protonmail.com> 1635897062 -0500 checkout: moving from main to foo
|
2e1db472eeba53f06c4026ae4566ea022e36598e f1b58b97808f8e744f6a23c693859df5b5968901 Zach Rice <zricer@protonmail.com> 1635897062 -0500 checkout: moving from main to foo
|
||||||
f1b58b97808f8e744f6a23c693859df5b5968901 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635897508 -0500 checkout: moving from foo to main
|
f1b58b97808f8e744f6a23c693859df5b5968901 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635897508 -0500 checkout: moving from foo to main
|
||||||
|
2e1db472eeba53f06c4026ae4566ea022e36598e 4f77f1b3cc39d4b17e4cf4ba0a38f5daed9875b4 Richard Gomez <rmgomez368@gmail.com> 1681920523 -0400 commit: add .gitleaksignore test
|
||||||
|
4f77f1b3cc39d4b17e4cf4ba0a38f5daed9875b4 cada78a9bf157ec05573f19e682d211f811c2e2d Richard Gomez <rmgomez368@gmail.com> 1681920658 -0400 commit (amend): add .gitleaksignore test
|
||||||
|
cada78a9bf157ec05573f19e682d211f811c2e2d 2e1db472eeba53f06c4026ae4566ea022e36598e Richard Gomez <rmgomez368@gmail.com> 1681920730 -0400 reset: moving to HEAD~
|
||||||
|
2e1db472eeba53f06c4026ae4566ea022e36598e 53cd7a3c6eb4937f413e3c25e4a9f39289afa69e Richard Gomez <rmgomez368@gmail.com> 1681920759 -0400 commit: add .gitleaksignore test files
|
||||||
@@ -1,2 +1,6 @@
|
|||||||
0000000000000000000000000000000000000000 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896329 -0500 clone: from github.com:gitleaks/test.git
|
0000000000000000000000000000000000000000 1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 Zach Rice <zricer@protonmail.com> 1635896329 -0500 clone: from github.com:gitleaks/test.git
|
||||||
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635896648 -0500 pull origin main: Fast-forward
|
1b6da43b82b22e4eaa10bcf8ee591e91abbfc587 2e1db472eeba53f06c4026ae4566ea022e36598e Zach Rice <zricer@protonmail.com> 1635896648 -0500 pull origin main: Fast-forward
|
||||||
|
2e1db472eeba53f06c4026ae4566ea022e36598e 4f77f1b3cc39d4b17e4cf4ba0a38f5daed9875b4 Richard Gomez <rmgomez368@gmail.com> 1681920523 -0400 commit: add .gitleaksignore test
|
||||||
|
4f77f1b3cc39d4b17e4cf4ba0a38f5daed9875b4 cada78a9bf157ec05573f19e682d211f811c2e2d Richard Gomez <rmgomez368@gmail.com> 1681920658 -0400 commit (amend): add .gitleaksignore test
|
||||||
|
cada78a9bf157ec05573f19e682d211f811c2e2d 2e1db472eeba53f06c4026ae4566ea022e36598e Richard Gomez <rmgomez368@gmail.com> 1681920730 -0400 reset: moving to HEAD~
|
||||||
|
2e1db472eeba53f06c4026ae4566ea022e36598e 53cd7a3c6eb4937f413e3c25e4a9f39289afa69e Richard Gomez <rmgomez368@gmail.com> 1681920759 -0400 commit: add .gitleaksignore test files
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
x•ÎAjÃ0…á®uй@Ãh$�e!»ì{ƒ±5±E-+(ʦ§¯½@v�>xs-%w >zS…$:YF±ŽÅy"�,G¢k�bbó�¦ûզɤ:IpwäÙ#±¨Ì*xpÇaŒjäÕ×Úà+Ï«´·ZôÎ,Ãq¼.Eòvšk¹€åhGÂ@>Ñ#š£/»¾ç9Äo$%8-¹o*ßϼìµ)t}vó¸ÁLë
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
|||||||
2e1db472eeba53f06c4026ae4566ea022e36598e
|
53cd7a3c6eb4937f413e3c25e4a9f39289afa69e
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
nothing should be saved here
|
|
||||||
Reference in new issue
Block a user