From ab5fc21e824a2eb7d420006ce9793161e3a54e01 Mon Sep 17 00:00:00 2001 From: wayne-snyk <100307369+wayne-snyk@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:08:48 -0400 Subject: [PATCH] Add detection for Snyk tokens (#1190) * add snyk token * add snyk token to rules * s/snyk_token/snyk --- cmd/generate/config/main.go | 1 + cmd/generate/config/rules/snyk.go | 24 ++++++++++++++++++++++++ config/gitleaks.toml | 10 +++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 cmd/generate/config/rules/snyk.go diff --git a/cmd/generate/config/main.go b/cmd/generate/config/main.go index 151b6aa0..ae32e6d3 100644 --- a/cmd/generate/config/main.go +++ b/cmd/generate/config/main.go @@ -144,6 +144,7 @@ func main() { configRules = append(configRules, rules.SidekiqSensitiveUrl()) configRules = append(configRules, rules.SlackAccessToken()) configRules = append(configRules, rules.SlackWebHook()) + configRules = append(configRules, rules.Snyk()) configRules = append(configRules, rules.StripeAccessToken()) configRules = append(configRules, rules.SquareAccessToken()) configRules = append(configRules, rules.SquareSpaceAccessToken()) diff --git a/cmd/generate/config/rules/snyk.go b/cmd/generate/config/rules/snyk.go new file mode 100644 index 00000000..9543c72e --- /dev/null +++ b/cmd/generate/config/rules/snyk.go @@ -0,0 +1,24 @@ +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 + } + return validate(r, tps, nil) +} diff --git a/config/gitleaks.toml b/config/gitleaks.toml index fcaf0510..e69a6e1f 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -1986,7 +1986,6 @@ stopwords= [ "branch", "combination", "combo", - "REDACTED", ] [[rules]] description = "GitHub App Token" @@ -2616,6 +2615,15 @@ keywords = [ "hooks.slack.com", ] +[[rules]] +description = "Snyk API token" +id = "snyk-api-token" +regex = '''(?i)(?:snyk)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:=|\|\|:|<=|=>|:)(?:'|\"|\s|=|\x60){0,5}([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:['|\"|\n|\r|\s|\x60|;]|$)''' +secretGroup = 1 +keywords = [ + "snyk", +] + [[rules]] description = "Square Access Token" id = "square-access-token"