Compare commits

...
11 Commits
Author SHA1 Message Date
Zachary Rice 469cd22f61 updating generic regex and algoia regex (#875) 2022-05-25 08:00:10 -05:00
SimonGurney 93e72c215d feat: add algolia key support (#866)
* feat: add algolia key support

* feat: add algolia key to generator

* chore: update algolia regex to match gen
2022-05-25 07:39:20 -05:00
Dirkjan Bussink 865478bcdc Improve PlanetScale token detection (#874)
This improves the PlanetScale token detection. It add some flexibility
in length. There is no guarantee that the length is always 43 characters
(in fact, it's very likely to change a bit soon).

Additionally, it adds support for detecting oauth tokens as well.
2022-05-24 22:15:36 -05:00
Zachary Rice d6c0de7c85 Update README.md 2022-05-16 19:08:06 -05:00
Zachary Rice 0266ab8958 Adding JIT Security messages 2022-05-10 11:21:04 -05:00
Zachary Rice 6b7ab73a52 Update README.md 2022-05-02 10:21:40 -05:00
Zachary Rice 61ee7c58cc fix no-git bug (#859) 2022-04-27 21:48:56 -05:00
Zachary Rice ad7509e3b4 Removing private keyword from private key rule (#858) 2022-04-27 07:29:09 -05:00
Zachary Rice a62cc52aba nasty little bug (#853) 2022-04-23 11:18:56 -05:00
Zachary Rice f93e5dc844 adding a ton of stopwords to the generic rule only as that is the loudest rule (#851) 2022-04-21 17:01:21 -05:00
Zachary Rice 8481f0e9cd adding stopwords (#849)
* adding stopwords

* format readme, update default config
2022-04-21 08:31:58 -05:00
67 changed files with 3248 additions and 144 deletions

No files matched your search

+31 -17
View File
@@ -16,6 +16,9 @@
<a href="https://hub.docker.com/r/zricethezav/gitleaks">
<img src="https://img.shields.io/docker/pulls/zricethezav/gitleaks.svg" />
</a>
<a href="https://www.jit.io/jit-open-source-gitleaks?utm_source=github&utm_medium=badge&utm_campaign=GitleaksReadme&utm_id=oss&items=item-secret-detection">
<img src="https://img.shields.io/badge/Secured%20by-Jit-B8287F?style=?style=plastic" />
</a>
<a href="https://twitter.com/intent/follow?screen_name=zricethezav">
<img src="https://img.shields.io/twitter/follow/zricethezav?label=Follow%20zricethezav&style=social&color=blue" alt="Follow @zricethezav" />
</a>
@@ -124,7 +127,7 @@ When running `detect` on a git repository, gitleaks will parse the output of a `
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L17-L25)).
[`git log -p` generates patches](https://git-scm.com/docs/git-log#_generating_patch_text_with_p) which gitleaks will use to detect secrets.
You can configure what commits `git log` will range over by using the `--log-opts` flag. `--log-opts` accepts any option for `git log -p`.
For example, if you wanted to run gitleaks on a range of commits you could use the following command: `gitleaks --source . --log-opts="--all commitA..commitB"`.
For example, if you wanted to run gitleaks on a range of commits you could use the following command: `gitleaks detect --source . --log-opts="--all commitA..commitB"`.
See the `git log` [documentation](https://git-scm.com/docs/git-log) for more information.
You can scan files and directories by using the `--no-git` option.
@@ -233,9 +236,9 @@ entropy = 3.5
# either be part of the idenitifer or unique strings specific to the rule's regex
# (introduced in v8.6.0)
keywords = [
"auth",
"password",
"token",
"auth",
"password",
"token",
]
# You can include an allowlist table for a single rule to reduce false positives or ignore commits
@@ -244,13 +247,20 @@ keywords = [
description = "ignore commit A"
commits = [ "commit-A", "commit-B"]
paths = [
'''go\.mod''',
'''go\.sum'''
'''go\.mod''',
'''go\.sum'''
]
regexes = [
'''process''',
'''getenv''',
'''process''',
'''getenv''',
]
# note: stopwords targets the extracted secret, not the entire regex match
# like 'regexes' does. (stopwords introduced in 8.8.0)
stopwords = [
'''client''',
'''endpoint''',
]
# This is a global allowlist which has a higher order of precedence than rule-specific allowlists.
# If a commit listed in the `commits` field below is encountered then that commit will be skipped and no
@@ -259,17 +269,25 @@ regexes = [
description = "global allow list"
commits = [ "commit-A", "commit-B", "commit-C"]
paths = [
'''gitleaks\.toml''',
'''(.*?)(jpg|gif|doc)'''
'''gitleaks\.toml''',
'''(.*?)(jpg|gif|doc)'''
]
regexes = [
'''219-09-9999''',
'''078-05-1120''',
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
'''219-09-9999''',
'''078-05-1120''',
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
]
# note: stopwords targets the extracted secret, not the entire regex match
# like 'regexes' does. (stopwords introduced in 8.8.0)
stopwords = [
'''client''',
'''endpoint''',
]
```
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples and advice on writing regular expressions for secret detection.
## Secured by Jit
We use [Jit](https://www.jit.io/jit-open-source-gitleaks?utm_source=github&utm_medium=readme&utm_campaign=GitleaksReadme&utm_id=oss&items=item-secret-detection) to secure our codebase, to achieve fully automated, full-stack continuous security using the world's best OSS security tools.
## Sponsorships
@@ -277,10 +295,6 @@ Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/b
<a href="https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">
<img alt="Tines Sponsorship" src="https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png" width=200>
</a>
</p>
<a href="https://www.typeform.com/">
<img src="https://user-images.githubusercontent.com/15034943/146945294-a6473d55-86b8-4f53-941e-7f185ad6b3d7.png" width=200/>
</a>
</p>
+4 -5
View File
@@ -19,6 +19,7 @@ func main() {
configRules = append(configRules, rules.AdobeClientID())
configRules = append(configRules, rules.AdobeClientSecret())
configRules = append(configRules, rules.AgeSecretKey())
configRules = append(configRules, rules.AlgoliaApiKey())
configRules = append(configRules, rules.AlibabaAccessKey())
configRules = append(configRules, rules.AlibabaSecretKey())
configRules = append(configRules, rules.AsanaClientID())
@@ -50,7 +51,6 @@ func main() {
configRules = append(configRules, rules.FlutterwaveSecretKey())
configRules = append(configRules, rules.FlutterwaveSecretKey())
configRules = append(configRules, rules.FrameIO())
configRules = append(configRules, rules.GenericCredential())
configRules = append(configRules, rules.GoCardless())
// TODO figure out what makes sense for GCP
// configRules = append(configRules, rules.GCPServiceAccount())
@@ -81,7 +81,8 @@ func main() {
configRules = append(configRules, rules.NewRelicBrowserAPIKey())
configRules = append(configRules, rules.NPM())
configRules = append(configRules, rules.PlanetScalePassword())
configRules = append(configRules, rules.PlanetScaleToken())
configRules = append(configRules, rules.PlanetScaleAPIToken())
configRules = append(configRules, rules.PlanetScaleOAuthToken())
configRules = append(configRules, rules.PostManAPI())
configRules = append(configRules, rules.PrivateKey())
configRules = append(configRules, rules.PulumiAPIToken())
@@ -101,6 +102,7 @@ func main() {
configRules = append(configRules, rules.TwitchAPIToken())
configRules = append(configRules, rules.Twitter())
configRules = append(configRules, rules.Typeform())
configRules = append(configRules, rules.GenericCredential())
config := config.Config{
Rules: configRules,
@@ -117,6 +119,3 @@ func main() {
tmpl.Execute(f, config)
}
// TODO introduce skiplists:
// https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/wordlist-skipfish.fuzz.txt
+2 -2
View File
@@ -19,7 +19,7 @@ func AdobeClientID() *config.Rule {
tps := []string{
generateSampleSecret("adobe", secrets.NewSecret(hex("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func AdobeClientSecret() *config.Rule {
@@ -35,5 +35,5 @@ func AdobeClientSecret() *config.Rule {
tps := []string{
"adobeClient := \"p8e-" + secrets.NewSecret(hex("32")) + "\"",
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -19,5 +19,5 @@ func AgeSecretKey() *config.Rule {
tps := []string{
`apiKey := "AGE-SECRET-KEY-1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ`, // gitleaks:allow
}
return validate(r, tps)
return validate(r, tps, nil)
}
+22
View File
@@ -0,0 +1,22 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func AlgoliaApiKey() *config.Rule {
// define rule
r := config.Rule{
Description: "Algolia API Key",
RuleID: "algolia-api-key",
Regex: generateSemiGenericRegex([]string{"algolia"}, `[a-z0-9]{32}`),
Keywords: []string{"algolia"},
}
// validate
tps := []string{
"algolia_key := " + secrets.NewSecret(hex("32")),
}
return validate(r, tps, nil)
}
+2 -2
View File
@@ -18,7 +18,7 @@ func AlibabaAccessKey() *config.Rule {
tps := []string{
"alibabaKey := \"LTAI" + secrets.NewSecret(hex("20")) + "\"",
}
return validate(r, tps)
return validate(r, tps, nil)
}
// TODO
@@ -37,5 +37,5 @@ func AlibabaSecretKey() *config.Rule {
tps := []string{
generateSampleSecret("alibaba", secrets.NewSecret(alphaNumeric("30"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+3 -2
View File
@@ -19,7 +19,7 @@ func AsanaClientID() *config.Rule {
tps := []string{
generateSampleSecret("asana", secrets.NewSecret(numeric("16"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func AsanaClientSecret() *config.Rule {
@@ -28,6 +28,7 @@ func AsanaClientSecret() *config.Rule {
Description: "Asana Client Secret",
RuleID: "asana-client-secret",
Regex: generateSemiGenericRegex([]string{"asana"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{"asana"},
}
@@ -35,5 +36,5 @@ func AsanaClientSecret() *config.Rule {
tps := []string{
generateSampleSecret("asana", secrets.NewSecret(alphaNumeric("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Atlassian() *config.Rule {
generateSampleSecret("atlassian", secrets.NewSecret(alphaNumeric("24"))),
generateSampleSecret("confluence", secrets.NewSecret(alphaNumeric("24"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -27,5 +27,5 @@ func AWS() *config.Rule {
// validate
tps := []string{generateSampleSecret("AWS", "AKIALALEMEL33243OLIB")} // gitleaks:allow
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Beamer() *config.Rule {
tps := []string{
generateSampleSecret("beamer", "b_"+secrets.NewSecret(alphaNumericExtended("44"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+2 -2
View File
@@ -19,7 +19,7 @@ func BitBucketClientID() *config.Rule {
tps := []string{
generateSampleSecret("bitbucket", secrets.NewSecret(alphaNumeric("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func BitBucketClientSecret() *config.Rule {
@@ -36,5 +36,5 @@ func BitBucketClientSecret() *config.Rule {
tps := []string{
generateSampleSecret("bitbucket", secrets.NewSecret(alphaNumeric("64"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Clojars() *config.Rule {
tps := []string{
generateSampleSecret("clojars", "CLOJARS_"+secrets.NewSecret(alphaNumeric("60"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+13 -1
View File
@@ -18,7 +18,19 @@ paths = [
]
{{ range $i, $rule := .Rules }}[[rules]]
{{ if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}"
{{ if and $rule.SecretGroup $rule.Entropy $rule.Allowlist.StopWords }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }}
entropy = {{ $rule.Entropy}}
keywords = [
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
]
[rules.allowlist]
stopwords= [{{ range $j, $stopword := $rule.Allowlist.StopWords }}
"{{$stopword}}",{{end}}
]
{{ else if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }}
+1 -1
View File
@@ -20,5 +20,5 @@ func Contentful() *config.Rule {
tps := []string{
generateSampleSecret("contentful", secrets.NewSecret(alphaNumeric("43"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -18,5 +18,5 @@ func Databricks() *config.Rule {
tps := []string{
generateSampleSecret("databricks", "dapi"+secrets.NewSecret(hex("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+3 -3
View File
@@ -19,7 +19,7 @@ func DiscordAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("discord", secrets.NewSecret(hex("64"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func DiscordClientID() *config.Rule {
@@ -36,7 +36,7 @@ func DiscordClientID() *config.Rule {
tps := []string{
generateSampleSecret("discord", secrets.NewSecret(numeric("18"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func DiscordClientSecret() *config.Rule {
@@ -53,5 +53,5 @@ func DiscordClientSecret() *config.Rule {
tps := []string{
generateSampleSecret("discord", secrets.NewSecret(numeric("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,7 +20,7 @@ func Doppler() *config.Rule {
tps := []string{
generateSampleSecret("doppler", "dp.pt."+secrets.NewSecret(alphaNumeric("43"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
// TODO add additional doppler formats:
+1 -1
View File
@@ -19,7 +19,7 @@ func DropBoxAPISecret() *config.Rule {
tps := []string{
generateSampleSecret("dropbox", secrets.NewSecret(alphaNumeric("15"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func DropBoxShortLivedAPIToken() *config.Rule {
+1 -1
View File
@@ -20,5 +20,5 @@ func Duffel() *config.Rule {
tps := []string{
generateSampleSecret("duffel", "duffel_test_"+secrets.NewSecret(alphaNumericExtended("43"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Dynatrace() *config.Rule {
tps := []string{
generateSampleSecret("dynatrace", "dt0c01."+secrets.NewSecret(alphaNumeric("24"))+"."+secrets.NewSecret(alphaNumeric("64"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+2 -2
View File
@@ -20,7 +20,7 @@ func EasyPost() *config.Rule {
tps := []string{
generateSampleSecret("EZAK", "EZAK"+secrets.NewSecret(alphaNumeric("54"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func EasyPostTestAPI() *config.Rule {
@@ -36,5 +36,5 @@ func EasyPostTestAPI() *config.Rule {
tps := []string{
generateSampleSecret("EZTK", "EZTK"+secrets.NewSecret(alphaNumeric("54"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -19,5 +19,5 @@ func Facebook() *config.Rule {
tps := []string{
generateSampleSecret("facebook", secrets.NewSecret(hex("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -19,5 +19,5 @@ func FastlyAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("fastly", secrets.NewSecret(alphaNumericExtended("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+2 -2
View File
@@ -19,7 +19,7 @@ func FinicityClientSecret() *config.Rule {
tps := []string{
generateSampleSecret("finicity", secrets.NewSecret(alphaNumeric("20"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func FinicityAPIToken() *config.Rule {
@@ -36,5 +36,5 @@ func FinicityAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("finicity", secrets.NewSecret(hex("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+3 -3
View File
@@ -20,7 +20,7 @@ func FlutterwavePublicKey() *config.Rule {
tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWPUBK_TEST-"+secrets.NewSecret(hex("32"))+"-X"),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func FlutterwaveSecretKey() *config.Rule {
@@ -36,7 +36,7 @@ func FlutterwaveSecretKey() *config.Rule {
tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(hex("32"))+"-X"),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func FlutterwaveEncKey() *config.Rule {
@@ -52,5 +52,5 @@ func FlutterwaveEncKey() *config.Rule {
tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(hex("12"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func FrameIO() *config.Rule {
tps := []string{
generateSampleSecret("frameio", "fio-u-"+secrets.NewSecret(alphaNumericExtended("64"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func GCPServiceAccount() *config.Rule {
tps := []string{
`"type": "service_account"`,
}
return validate(r, tps)
return validate(r, tps, nil)
}
+10 -5
View File
@@ -13,9 +13,9 @@ func GenericCredential() *config.Rule {
"key",
"api[^Version]",
"token",
"pat",
"secret",
"client",
"passwd",
"password",
"auth",
}, `[0-9a-z\-_.=]{10,150}`),
@@ -26,11 +26,14 @@ func GenericCredential() *config.Rule {
"token",
"secret",
"client",
"pat",
"passwd",
"password",
"auth",
},
Entropy: 3.7,
Entropy: 3.5,
Allowlist: config.Allowlist{
StopWords: DefaultStopWords,
},
}
// validate
@@ -39,7 +42,9 @@ func GenericCredential() *config.Rule {
generateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
`"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
// TODO add more
}
return validate(r, tps)
fps := []string{
`client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.client-vpn-endpoint.id`,
}
return validate(r, tps, fps)
}
+4 -4
View File
@@ -20,7 +20,7 @@ func GitHubPat() *config.Rule {
tps := []string{
generateSampleSecret("github", "ghp_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func GitHubOauth() *config.Rule {
@@ -36,7 +36,7 @@ func GitHubOauth() *config.Rule {
tps := []string{
generateSampleSecret("github", "gho_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func GitHubApp() *config.Rule {
@@ -53,7 +53,7 @@ func GitHubApp() *config.Rule {
generateSampleSecret("github", "ghu_"+secrets.NewSecret(alphaNumeric("36"))),
generateSampleSecret("github", "ghs_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func GitHubRefresh() *config.Rule {
@@ -69,5 +69,5 @@ func GitHubRefresh() *config.Rule {
tps := []string{
generateSampleSecret("github", "ghr_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Gitlab() *config.Rule {
tps := []string{
generateSampleSecret("gitlab", "glpat-"+secrets.NewSecret(alphaNumeric("20"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+2 -1
View File
@@ -11,6 +11,7 @@ func GoCardless() *config.Rule {
RuleID: "gocardless-api-token",
Description: "GoCardless API token",
Regex: generateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`),
SecretGroup: 1,
Keywords: []string{
"live_",
"gocardless",
@@ -21,5 +22,5 @@ func GoCardless() *config.Rule {
tps := []string{
generateSampleSecret("gocardless", "live_"+secrets.NewSecret(alphaNumericExtended("40"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Hashicorp() *config.Rule {
tps := []string{
generateSampleSecret("hashicorpToken", secrets.NewSecret(hex("14"))+".atlasv1."+secrets.NewSecret(alphaNumericExtended("60,70"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -19,5 +19,5 @@ func Heroku() *config.Rule {
tps := []string{
`const HEROKU_KEY = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -19,5 +19,5 @@ func HubSpot() *config.Rule {
tps := []string{
`const hubspotKey = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -19,5 +19,5 @@ func Intercom() *config.Rule {
tps := []string{
generateSampleSecret("intercom", secrets.NewSecret(alphaNumericExtended("60"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+3 -2
View File
@@ -20,7 +20,7 @@ func LinearAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("linear", "lin_api_"+secrets.NewSecret(alphaNumeric("40"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func LinearClientSecret() *config.Rule {
@@ -30,11 +30,12 @@ func LinearClientSecret() *config.Rule {
RuleID: "linear-client-secret",
Regex: generateSemiGenericRegex([]string{"linear"}, hex("32")),
Keywords: []string{"linear"},
SecretGroup: 1,
}
// validate
tps := []string{
generateSampleSecret("linear", secrets.NewSecret(hex("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+2 -2
View File
@@ -25,7 +25,7 @@ func LinkedinClientSecret() *config.Rule {
tps := []string{
generateSampleSecret("linkedin", secrets.NewSecret(alphaNumeric("16"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func LinkedinClientID() *config.Rule {
@@ -48,5 +48,5 @@ func LinkedinClientID() *config.Rule {
tps := []string{
generateSampleSecret("linkedin", secrets.NewSecret(alphaNumeric("14"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+4 -2
View File
@@ -11,6 +11,7 @@ func LobPubAPIToken() *config.Rule {
Description: "Lob Publishable API Key",
RuleID: "lob-pub-api-key",
Regex: generateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`),
SecretGroup: 1,
Keywords: []string{
"test_pub",
"live_pub",
@@ -22,7 +23,7 @@ func LobPubAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("lob", "test_pub_"+secrets.NewSecret(hex("31"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func LobAPIToken() *config.Rule {
@@ -35,11 +36,12 @@ func LobAPIToken() *config.Rule {
"test_",
"live_",
},
SecretGroup: 1,
}
// validate
tps := []string{
generateSampleSecret("lob", "test_"+secrets.NewSecret(hex("35"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -21,5 +21,5 @@ func MailChimp() *config.Rule {
tps := []string{
generateSampleSecret("mailchimp", secrets.NewSecret(hex("32"))+"-us20"),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+3 -3
View File
@@ -21,7 +21,7 @@ func MailGunPrivateAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("mailgun", "key-"+secrets.NewSecret(hex("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func MailGunPubAPIToken() *config.Rule {
@@ -40,7 +40,7 @@ func MailGunPubAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("mailgun", "pubkey-"+secrets.NewSecret(hex("32"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func MailGunSigningKey() *config.Rule {
@@ -59,5 +59,5 @@ func MailGunSigningKey() *config.Rule {
tps := []string{
generateSampleSecret("mailgun", secrets.NewSecret(hex("32"))+"-00001111-22223333"),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -19,5 +19,5 @@ func MapBox() *config.Rule {
tps := []string{
generateSampleSecret("mapbox", "pk."+secrets.NewSecret(alphaNumeric("60"))+"."+secrets.NewSecret(alphaNumeric("22"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+2 -2
View File
@@ -29,7 +29,7 @@ func MessageBirdAPIToken() *config.Rule {
generateSampleSecret("message-bird", secrets.NewSecret(alphaNumeric("25"))),
generateSampleSecret("message_bird", secrets.NewSecret(alphaNumeric("25"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func MessageBirdClientID() *config.Rule {
@@ -54,5 +54,5 @@ func MessageBirdClientID() *config.Rule {
tps := []string{
`const MessageBirdClientID = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
}
return validate(r, tps)
return validate(r, tps, nil)
}
+3 -3
View File
@@ -25,7 +25,7 @@ func NewRelicUserID() *config.Rule {
tps := []string{
generateSampleSecret("new-relic", "NRAK-"+secrets.NewSecret(alphaNumeric("27"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func NewRelicUserKey() *config.Rule {
@@ -50,7 +50,7 @@ func NewRelicUserKey() *config.Rule {
tps := []string{
generateSampleSecret("new-relic", secrets.NewSecret(alphaNumeric("64"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func NewRelicBrowserAPIKey() *config.Rule {
@@ -73,5 +73,5 @@ func NewRelicBrowserAPIKey() *config.Rule {
tps := []string{
generateSampleSecret("new-relic", "NRJS-"+secrets.NewSecret(hex("19"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -21,5 +21,5 @@ func NPM() *config.Rule {
tps := []string{
generateSampleSecret("npmAccessToken", "npm_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+30 -5
View File
@@ -10,7 +10,7 @@ func PlanetScalePassword() *config.Rule {
r := config.Rule{
RuleID: "planetscale-password",
Description: "PlanetScale password",
Regex: generateUniqueTokenRegex(`pscale_pw_(?i)[a-z0-9=\-_\.]{43}`),
Regex: generateUniqueTokenRegex(`pscale_pw_(?i)[a-z0-9=\-_\.]{32,64}`),
SecretGroup: 1,
Keywords: []string{
"pscale_pw_",
@@ -19,17 +19,19 @@ func PlanetScalePassword() *config.Rule {
// validate
tps := []string{
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("64"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func PlanetScaleToken() *config.Rule {
func PlanetScaleAPIToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "planetscale-api-token",
Description: "PlanetScale API token",
Regex: generateUniqueTokenRegex(`pscale_tkn_(?i)[a-z0-9=\-_\.]{43}`),
Regex: generateUniqueTokenRegex(`pscale_tkn_(?i)[a-z0-9=\-_\.]{32,64}`),
SecretGroup: 1,
Keywords: []string{
"pscale_tkn_",
@@ -38,7 +40,30 @@ func PlanetScaleToken() *config.Rule {
// validate
tps := []string{
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("64"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
func PlanetScaleOAuthToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "planetscale-oauth-token",
Description: "PlanetScale OAuth token",
Regex: generateUniqueTokenRegex(`pscale_oauth_(?i)[a-z0-9=\-_\.]{32,64}`),
SecretGroup: 1,
Keywords: []string{
"pscale_oauth_",
},
}
// validate
tps := []string{
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("64"))),
}
return validate(r, tps, nil)
}
+1 -1
View File
@@ -21,5 +21,5 @@ func PostManAPI() *config.Rule {
tps := []string{
generateSampleSecret("postmanAPItoken", "PMAK-"+secrets.NewSecret(hex("24"))+"-"+secrets.NewSecret(hex("34"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+8 -3
View File
@@ -12,12 +12,17 @@ func PrivateKey() *config.Rule {
Description: "Private Key",
RuleID: "private-key",
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY-----[\s\S-]*KEY----`),
Keywords: []string{"-----BEGIN PRIVATE"},
Keywords: []string{"-----BEGIN"},
}
// validate
tps := []string{`-----BEGIN PRIVATE KEY-----
anything
-----END PRIVATE KEY-----`} // gitleaks:allow
return validate(r, tps)
-----END PRIVATE KEY-----`,
`-----BEGIN RSA PRIVATE KEY-----
abcdefghijklmnopqrstuvwxyz
-----END RSA PRIVATE KEY-----
`,
} // gitleaks:allow
return validate(r, tps, nil)
}
+1 -1
View File
@@ -21,5 +21,5 @@ func PulumiAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("pulumi-api-token", "pul-"+secrets.NewSecret(hex("40"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -22,5 +22,5 @@ func PyPiUploadToken() *config.Rule {
// validate
tps := []string{"pypiToken := \"pypi-AgEIcHlwaS5vcmc" + secrets.NewSecret(hex("32")) +
secrets.NewSecret(hex("32")) + "\""}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -21,5 +21,5 @@ func RubyGemsAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("rubygemsAPIToken", "rubygems_"+secrets.NewSecret(hex("48"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+7 -2
View File
@@ -54,7 +54,7 @@ func generateSampleSecret(identifier string, secret string) string {
return fmt.Sprintf("%s_api_token = \"%s\"", identifier, secret)
}
func validate(r config.Rule, truePositives []string) *config.Rule {
func validate(r config.Rule, truePositives []string, falsePositives []string) *config.Rule {
// normalize keywords like in the config package
var keywords []string
for _, k := range r.Keywords {
@@ -68,7 +68,12 @@ func validate(r config.Rule, truePositives []string) *config.Rule {
})
for _, tp := range truePositives {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msgf("Failed to validate %s", r.RuleID)
log.Fatal().Msgf("Failed to validate (tp) %s %s", r.RuleID, tp)
}
}
for _, fp := range falsePositives {
if len(d.DetectString(fp)) != 0 {
log.Fatal().Msgf("Failed to validate (fp) %s", r.RuleID)
}
}
return &r
+1 -1
View File
@@ -21,5 +21,5 @@ func SendGridAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("sengridAPIToken", "SG."+secrets.NewSecret(alphaNumericExtended("66"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -21,5 +21,5 @@ func SendInBlueAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("sendinblue", "xkeysib-"+secrets.NewSecret(hex("64"))+"-"+secrets.NewSecret(alphaNumeric("16"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -22,5 +22,5 @@ func ShippoAPIToken() *config.Rule {
generateSampleSecret("shippo", "shippo_live_"+secrets.NewSecret(hex("40"))),
generateSampleSecret("shippo", "shippo_test_"+secrets.NewSecret(hex("40"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+4 -4
View File
@@ -18,7 +18,7 @@ func ShopifySharedSecret() *config.Rule {
// validate
tps := []string{"shopifySecret := \"shpss_" + secrets.NewSecret(hex("32")) + "\""}
return validate(r, tps)
return validate(r, tps, nil)
}
func ShopifyAccessToken() *config.Rule {
@@ -32,7 +32,7 @@ func ShopifyAccessToken() *config.Rule {
// validate
tps := []string{"shopifyToken := \"shpat_" + secrets.NewSecret(hex("32")) + "\""}
return validate(r, tps)
return validate(r, tps, nil)
}
func ShopifyCustomAccessToken() *config.Rule {
@@ -46,7 +46,7 @@ func ShopifyCustomAccessToken() *config.Rule {
// validate
tps := []string{"shopifyToken := \"shpca_" + secrets.NewSecret(hex("32")) + "\""}
return validate(r, tps)
return validate(r, tps, nil)
}
func ShopifyPrivateAppAccessToken() *config.Rule {
@@ -60,5 +60,5 @@ func ShopifyPrivateAppAccessToken() *config.Rule {
// validate
tps := []string{"shopifyToken := \"shppa_" + secrets.NewSecret(hex("32")) + "\""}
return validate(r, tps)
return validate(r, tps, nil)
}
+3 -3
View File
@@ -27,7 +27,7 @@ func SlackAccessToken() *config.Rule {
tps := []string{
"\"slackToken\": \"xoxb-" + secrets.NewSecret(alphaNumeric("30")) + "\"",
}
return validate(r, tps)
return validate(r, tps, nil)
}
func SlackWebHook() *config.Rule {
@@ -44,7 +44,7 @@ func SlackWebHook() *config.Rule {
// validate
tps := []string{
"https://hooks.slack.com/services/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", // gitleaks:allow
"https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
}
return validate(r, tps)
return validate(r, tps, nil)
}
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -23,5 +23,5 @@ func StripeAccessToken() *config.Rule {
// validate
tps := []string{"stripeToken := \"sk_test_" + secrets.NewSecret(alphaNumeric("30")) + "\""}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Twilio() *config.Rule {
tps := []string{
"twilioAPIKey := \"SK" + secrets.NewSecret(hex("32")) + "\"",
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -21,5 +21,5 @@ func TwitchAPIToken() *config.Rule {
tps := []string{
generateSampleSecret("twitch", secrets.NewSecret(alphaNumeric("30"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -20,5 +20,5 @@ func Twitter() *config.Rule {
"twitterToken := \"" + secrets.NewSecret(hex("36")) + "aaaa\"",
"twitterToken := `" + secrets.NewSecret(hex("36")) + "aaaa`",
}
return validate(r, tps)
return validate(r, tps, nil)
}
+1 -1
View File
@@ -22,5 +22,5 @@ func Typeform() *config.Rule {
tps := []string{
generateSampleSecret("typeformAPIToken", "tfp_"+secrets.NewSecret(alphaNumericExtended("59"))),
}
return validate(r, tps)
return validate(r, tps, nil)
}
+19 -1
View File
@@ -1,6 +1,9 @@
package config
import "regexp"
import (
"regexp"
"strings"
)
// Allowlist allows a rule to be ignored for specific
// regexes, paths, and/or commits
@@ -16,6 +19,11 @@ type Allowlist struct {
// Commits is a slice of commit SHAs that are allowed to be ignored.
Commits []string
// StopWords is a slice of stop words that are allowed to be ignored.
// This targets the _secret_, not the content of the regex match like the
// Regexes slice.
StopWords []string
}
// CommitAllowed returns true if the commit is allowed to be ignored.
@@ -40,3 +48,13 @@ func (a *Allowlist) PathAllowed(path string) bool {
func (a *Allowlist) RegexAllowed(s string) bool {
return anyRegexMatch(s, a.Regexes)
}
func (a *Allowlist) ContainsStopWord(s string) bool {
s = strings.ToLower(s)
for _, stopWord := range a.StopWords {
if strings.Contains(s, strings.ToLower(stopWord)) {
return true
}
}
return false
}
+16 -12
View File
@@ -26,15 +26,17 @@ type ViperConfig struct {
Tags []string
Allowlist struct {
Regexes []string
Paths []string
Commits []string
Regexes []string
Paths []string
Commits []string
StopWords []string
}
}
Allowlist struct {
Regexes []string
Paths []string
Commits []string
Regexes []string
Paths []string
Commits []string
StopWords []string
}
}
@@ -96,9 +98,10 @@ func (vc *ViperConfig) Translate() (Config, error) {
Tags: r.Tags,
Keywords: r.Keywords,
Allowlist: Allowlist{
Regexes: allowlistRegexes,
Paths: allowlistPaths,
Commits: r.Allowlist.Commits,
Regexes: allowlistRegexes,
Paths: allowlistPaths,
Commits: r.Allowlist.Commits,
StopWords: r.Allowlist.StopWords,
},
}
if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() {
@@ -118,9 +121,10 @@ func (vc *ViperConfig) Translate() (Config, error) {
Description: vc.Description,
Rules: rules,
Allowlist: Allowlist{
Regexes: allowlistRegexes,
Paths: allowlistPaths,
Commits: vc.Allowlist.Commits,
Regexes: allowlistRegexes,
Paths: allowlistPaths,
Commits: vc.Allowlist.Commits,
StopWords: vc.Allowlist.StopWords,
},
Keywords: keywords,
}, nil
+1509 -13
View File
File diff suppressed because it is too large. Load diff
+7 -1
View File
@@ -217,6 +217,12 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
finding.Secret = secret
}
// check if the secret is in the list of stopwords
if rule.Allowlist.ContainsStopWord(finding.Secret) ||
d.Config.Allowlist.ContainsStopWord(finding.Secret) {
continue
}
// check entropy
entropy := shannonEntropy(finding.Secret)
finding.Entropy = float32(entropy)
@@ -329,7 +335,7 @@ func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
if err != nil {
return err
}
if fInfo.Name() == ".git" {
if fInfo.Name() == ".git" && fInfo.IsDir() {
return filepath.SkipDir
}
if fInfo.Mode().IsRegular() {
+1
View File
@@ -22,6 +22,7 @@ func location(fragment Fragment, matchIndex []int) Location {
end := matchIndex[1]
for lineNum, pair := range fragment.newlineIndices {
_lineNum = lineNum
newLineByteIndex := pair[0]
if prevNewLine <= start && start < newLineByteIndex {
lineSet = true