mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-27 11:44:23 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed19c4e8b4 | ||
|
|
989ef19fb0 | ||
|
|
191eb43841 | ||
|
|
78f7d3f5df | ||
|
|
7098f6d958 | ||
|
|
97dbe1ef09 | ||
|
|
9e06824372 | ||
|
|
db782603f7 | ||
|
|
df126a7473 | ||
|
|
75dd70e59a | ||
|
|
8510d39ffe | ||
|
|
3698060a2b |
No files matched your search
@@ -24,3 +24,6 @@ jobs:
|
||||
|
||||
- name: Test
|
||||
run: make test
|
||||
|
||||
- name: Validate Config
|
||||
run: go generate ./... && git diff --exit-code
|
||||
@@ -43,7 +43,6 @@ func runDirectory(cmd *cobra.Command, args []string) {
|
||||
// start timer
|
||||
start := time.Now()
|
||||
|
||||
|
||||
detector := Detector(cmd, cfg, source)
|
||||
|
||||
// set exit code
|
||||
|
||||
@@ -81,6 +81,7 @@ func main() {
|
||||
rules.FlutterwavePublicKey(),
|
||||
rules.FlutterwaveSecretKey(),
|
||||
rules.FlutterwaveEncKey(),
|
||||
rules.FlyIOAccessToken(),
|
||||
rules.FrameIO(),
|
||||
rules.FreshbooksAccessToken(),
|
||||
rules.GoCardless(),
|
||||
@@ -113,8 +114,7 @@ func main() {
|
||||
rules.JWT(),
|
||||
rules.JWTBase64(),
|
||||
rules.KrakenAccessToken(),
|
||||
rules.KubernetesSecretWithDataAfter(),
|
||||
rules.KubernetesSecretWithDataBefore(),
|
||||
rules.KubernetesSecret(),
|
||||
rules.KucoinAccessToken(),
|
||||
rules.KucoinSecretKey(),
|
||||
rules.LaunchDarklyAccessToken(),
|
||||
|
||||
@@ -14,7 +14,7 @@ title = "gitleaks config"
|
||||
description = "global allow lists"
|
||||
paths = [
|
||||
'''gitleaks.toml''',
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe)$''',
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$''',
|
||||
'''(go.mod|go.sum|go.work|go.work.sum)$''',
|
||||
'''gradle.lockfile''',
|
||||
'''verification-metadata.xml''',
|
||||
@@ -51,7 +51,7 @@ tags = [
|
||||
regexTarget = "{{ . }}"{{ end -}}
|
||||
{{- with $rule.Allowlist.Regexes }}
|
||||
regexes = [
|
||||
{{ range $j, $regex := . }}"{{ $regex }}",{{ end }}
|
||||
{{ range $j, $regex := . }}'''{{ $regex }}''',{{ end }}
|
||||
]{{ end }}
|
||||
{{- with $rule.Allowlist.Paths }}paths = [
|
||||
{{ range $j, $path := . }}"{{ $path }}",{{ end }}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
@@ -11,8 +12,8 @@ func EtsyAccessToken() *config.Rule {
|
||||
r := config.Rule{
|
||||
RuleID: "etsy-access-token",
|
||||
Description: "Found an Etsy Access Token, potentially compromising Etsy shop management and customer data.",
|
||||
Regex: utils.GenerateSemiGenericRegex([]string{"etsy"}, utils.AlphaNumeric("24"), true),
|
||||
|
||||
Regex: utils.GenerateSemiGenericRegex([]string{"(?-i:ETSY|[Ee]tsy)"}, utils.AlphaNumeric("24"), true),
|
||||
Entropy: 3,
|
||||
Keywords: []string{
|
||||
"etsy",
|
||||
},
|
||||
@@ -20,7 +21,15 @@ func EtsyAccessToken() *config.Rule {
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("ETSY", secrets.NewSecret(utils.AlphaNumeric("24"))),
|
||||
utils.GenerateSampleSecret("etsy", secrets.NewSecret(utils.AlphaNumeric("24"))),
|
||||
utils.GenerateSampleSecret("Etsy", secrets.NewSecret(utils.AlphaNumeric("24"))),
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
fmt.Sprintf(`SetSysctl = "%s"`, secrets.NewSecret(utils.AlphaNumeric("24"))),
|
||||
` if err := sysctl.SetSysctl(sysctlBridgeCallIPTables); err != nil {`,
|
||||
`g6Rib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEgETSYcPQGcaAxl8vuQDLahSfhxkEEHu2flbF9ErAooEoKp3BheWxvYWTFAwB7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwMTEzNDk4NzBmNDA2NzFhMDMxOTdjYmVlNDAzMmRhODUyN2UxYzY0MTA0MWVlZDlmOTViMTdkMTJiMDI4YTA0YTBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwMTEzNDk4NzBmNDA2NzFhMDMxOTdjYmVlNDAzMmRhODUyN2UxYzY0MTA0MWVlZDlmOTViMTdkMTJiMDI4YTA0YTBhIiwidWlkIjoiYzUyZjc2M2MxNzYyNWZiMTI5YWU1ZDZmZThhMGUzMTkiLCJ1c2VybmFtZSI6ImttYXJla3NwYXJ0eiJ9LCJzZXJ2aWNlIjp7Imhvc3RuYW1lIjoia3lsZS5tYXJlay1zcGFydHoub3JnIiwicHJvdG9jb2wiOiJodHRwOiJ9LCJ0eXBlIjoid2ViX3NlcnZpY2VfYmluZGluZyIsInZlcnNpb24iOjF9LCJjbGllbnQiOnsibmFtZSI6ImtleWJhc2UuaW8gZ28gY2xpZW50IiwidmVyc2lvbiI6IjEuMC4xNCJ9LCJjdGltZSI6MTQ1ODU5MDYyMSwiZXhwaXJlX2luIjo1MDQ1NzYwMDAsIm1lcmtsZV9yb290Ijp7ImN0aW1lIjoxNDU4NTkwNTgzLCJoYXNoIjoiODQ0ZWRkNGU0OTQ3MWUzNWQxZTFkOTM5YTc0ZjUwMDc5Nzg3NzljMTAwYzY1NGE2OGI1NDNhYzY2Y2NlYTQ1MGFjNTllNmY3Yjc4ZGZiN2MyYzdjMmYwMzJiYTA2MzdjMzVjZDk1ZGYyZmRiNjFlNjgxMjVmNDkxNjVlZDkwNzMiLCJzZXFubyI6NDE3Mjk5fSwicHJldiI6IjdmNWFkMGZlZmQxNjM4ZjBlOTc1MTk3NzA5YTk2OTVkZmQ1NzU0MTA4NTYxZGUzMDM0ODc2NDcxODdhMDkyYzUiLCJzZXFubyI6OSwidGFnIjoic2lnbmF0dXJlIn2jc2lnxEDDVCB/SdOzo+BznIUCCa5DgISbH+0noUjyAJ4r0sH/tj8lYNpHw3WR93SBCufeElsl7KrxVdg5qU5ADYj26wgOqHNpZ190eXBlIKN0YWfNAgKndmVyc2lvbgE=`,
|
||||
`in XCBuild.XCBBuildServiceSession.setSystemInfo(operatingSystemVersion: __C.NSOperatingSystemVersion, productBuildVersion: Swift.String, nativeArchitecture: Swift.String, completion: (Swift.Bool) -> ()) -> ()`,
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
// https://fly.io/docs/security/tokens/
|
||||
// https://github.com/trufflesecurity/trufflehog/pull/2381/files#r1565860579
|
||||
// https://github.com/superfly/macaroon-elixir/blob/8b42043b0a24aada5c8b8eb8505dbf1590557f1b/test/vectors.json#L7
|
||||
func FlyIOAccessToken() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
RuleID: "flyio-access-token",
|
||||
Description: "Uncovered a Fly.io API key", // TODO
|
||||
Regex: utils.GenerateUniqueTokenRegex(`(?:fo1_[\w-]{43}|fm1[ar]_[a-zA-Z0-9+\/]{100,}={0,3}|fm2_[a-zA-Z0-9+\/]{100,}={0,3})`, false),
|
||||
Entropy: 4,
|
||||
Keywords: []string{"fo1_", "fm1", "fm2_"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
// fo1_
|
||||
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fo1_[\w-]{43}`)),
|
||||
`Fly access token: fo1_8rz-j7r2eqJ2U7affEOO3HJN0j63DInyog3eV-glQSc
|
||||
`,
|
||||
`=============================================================================================================
|
||||
|
||||
fo1_BtKlzvfztw0M2hlLgTdsfPgDFiwM2jJjQXXy6I2pjuQ
|
||||
fly deploy`,
|
||||
// fm1
|
||||
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fm1[ar]_[a-zA-Z0-9+\/]{100,}={0,3}`)),
|
||||
`ENV FLY_API_TOKEN="FlyV1 fm1r_lJPECAAAAAAAAMqcxBBLMJKXYKJiT0CI58XmukX/wrVodHlwczovL2FwaS5mbHkuaW8vdjGWAJLOAAFmXh8Lk7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxxDy5OfA2M6K6aLEoEDKxehojbj+8ZT9IrXCF5sL/r8m6/1gylwySsNxpD40wnpd/G2ZdjwVaQev1kEuFUgzERxPbtWHDNa+NYIZwbKN6b7/JxdbUprq0M10HI4fwtlxhqhdA/mMaMw70EC4TsfJyghIL98KP4ry5AaXiroRdjrSsFExc/xRCDZKUA5GBzgATuNsfBZGCp2J1aWxkZXIfondnHwHEIMa6NWc4b52S+UY7vjPdwKrz00Uzrc1830mOHzQNLun7,fm1a_lJPERxPbtWHDNa+NYIZwbKN6b7/JxdbUprq0M10HI4fwtlxhqhdA/mMaMw70EC4TsfJyghIL98KP4ry4AaXiroRdjrSsFExc/xRCxBCVlAoRzKV/+qYkxuipIbIcw7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxlgSSzmS4Y7nPAAAAASCwgdcKkc4AAUktDMQQURck2h+upbiOrW66Nf5SA8QgrD03xlWju1WQi0AUhlk7YYFzOLDfhRyJ6nEziO37NUE="`,
|
||||
// fm2
|
||||
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fm2_[a-zA-Z0-9+\/]{100,}={0,3}`)),
|
||||
`# FLY_API_TOKEN: FlyV1 fm2_lJPECAAAAAAAAyZtxBD1hSZ7L5leXsj64ZbDlkm/wrVodHRwczovL2FwaS5mbHkuaW8vdjGWAJLOAAwMDB8Lk7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxxDwDnhgJj/ML/nRKMiAYgnvXfNacrGWffj5TdfgGY2LU0ZetT7WzTLQQMO8cN2nRTztl/xLjnnZg5pBwFonETmhNA6Yl0X1tatt8ezA0UjVQiJr93VQ7qAmD5GG2Ce5txhbQv3tmIGsvaC7BOkIqAiR273bhZkO44AYsrCPr2XF8W6Twk7NyU+3UUeDwjw2SlAORgc4APu7vHwWRgqdidWlsZGVyH6J3Zx8BxCAlmLbu1HQDg8ZAGKKmEt4Mbnbqli6lbzBDHsawhcUF4A==,fm2_lJPETmhNA6Yl0X1tatt8ezA0UjVQiJr93VQ7qAmD5GG2Ce5txhbQv3tmIGsvaC7BOkIqAij273bhZkO44AYsrCPr2XF8W6Twk7NyU+3UUeDwj8QQbn07DOV+7SmoLj/uT+dbr8O5aHR0cHM6Ly9hcGkuZmx5LmlvL2FhYS92MZgEks5mqfbvzwAAAAE9PYz9F84AC7QACpHOAAu0AAzEEFfW3B+SzffV/KrAYa8qqpnEIIlD6DqZMZQ9Kt7fEenCCOLA+tUSJ+kmEFIUcc83npOI`,
|
||||
`"BindToParentToken": "FlyV1 fm2_lJPEEKnzKy0lkwV3B+WIlmrdwejEEFv5qmevHU4fMs+2Gr6oOiPC2SAyOTc0NWI4ZmJlNjBlNjJmZTgzNTkxOThhZWE4MjY0M5IMxAMBAgPEIH7VG8u74KwO62hmx8SZO8WaU5o1g3W2IVc7QN6T1VTr",`,
|
||||
}
|
||||
fps := []string{
|
||||
// fo1_
|
||||
`resource "doppler_integration_flyio" "prod" {
|
||||
name = "TF Fly.io"
|
||||
api_key = "fo1_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
}`, // https://github.com/DopplerHQ/terraform-provider-doppler/blob/a012e1a7903cce391be511b391850b29ebfdeb68/docs/resources/integration_flyio.md?plain=1#L17
|
||||
`pub const MINIDUMP_SYSMEMINFO1_PERF_CCTOTALDIRTYPAGES_CCDIRTYPAGETHRESHOLD: u32 = 4u32;`, // https://github.com/microsoft/windows-rs/blob/0f7466c34e774e547d21c579b58b60168c4ee6bc/crates/libs/sys/src/Windows/Win32/System/Diagnostics/Debug/mod.rs#L1258
|
||||
`<input type="hidden" name="authenticity_token" value="7SWa-Fo1_hsC6oovfBsJFLGPUl2EhkSWPbJhWANwgaJWBDl1vxd9VNqXTNAefsJqzIRYaZEfYZLffa31rw8zJA" autocomplete="off" />`,
|
||||
// fm1
|
||||
`signature":"I7l2ZXhw9ajjIE2w9tjHNvYjcHg7E2qldMMhoQKjborcWIj8c40rMj83venoy6gXsg6V6B7dlBWxUmzYJR3lJKGECtCSM5BqBvWhL6wX2CN2lZlvwNCyPjG4PCt5MAK1yV1Xv4fqfz8EfT_U49vOzfM1a_nfhXOzrvdg9XgLkAotWBI31vPKjMBrvPqiLcZ12MDNTSK7ubRpVaehSNxiGYHpLhWTkun9qm_APYYXJBjhJYkej50Qcp7Ou8fs3kH02prYIJt4JbWelr5vUDkgMH3AwEx1eYu5NI_8sESlqosl1nhSDx7zq3X1FV1iJlAYCNwGWzW1tjo8PCaJrIHVZZnhBPMN-6ahmOpKb8GViqd4fCQuNe4VUSOeJg8i97kMuk-4r7hwIubR0XfCGzxr7uGDQBdFANi3c4dLlzBAJNifa6b_hT4Xzqja6RCFSv6Cnalyx3hbSkjbyThnXFavJIiR7cvgTcdECg9VxkaxqqRhfAkLAS3hpXQAIYL_bw61M3LN37WHwdgxN_6yZhbSbOsYPmTxiWvdlDaCP_iaCgXgJNfdQ6kep_I89slynE9gdDZ6NSjFJH2Soml4pR6HnQKPjA3OpoTwPSmZjxXY5I78xvrRqRkjdnVzeufqG8LyA-sAEtC0G_312JOxV4GZINquPGk1qFx8WN59Rxw28Tg",`,
|
||||
// fm2
|
||||
`<p><span class="emoji">🗣️</span> Adobe illustrator软件基础精讲课程<br><br><span class="emoji">🏷️</span> <a href="https://t.me/abskoop/8565?q=%23%E8%AE%BE%E8%AE%A1%E5%B8%88">#设计师</a> <a href="https://t.me/abskoop/8565?q=%23%E8%B5%84%E6%BA%90">#资源</a> <a href="https://t.me/abskoop/8565?q=%23%E5%A4%B8%E5%85%8B%E7%BD%91%E7%9B%98">#夸克网盘</a><br><br><span class="emoji">👉</span> <a href="https://www.ahhhhfs.com/62409/" target="_blank" rel="noopener">https://www.ahhhhfs.com/62409/</a></p><img src="https://cdn5.cdn-telegram.org/file/uGoDMy0VXMbL1nki9OT0VbJYtfURvDNLurptsQVuhuzF45tNfm2_z5wgR7CnL7lTZ4bbotjXZtiLWvolNQqWBRFWkcidtzSyhWvta9yPB3E2uyvfJvGpditkaLVIiCCXt9BhFBEdgkXa8ODaM7geHK3pW0tmO_IViHBnG8VZqVfDpaQW0W9IRAUwGv2mPZWVRysPJyDSIuY9b-_3ElUml-Xlpm1r8EDcm9Q2WCTCOYur7Gmef4imQ5D-DLTviqmoONgQDLA10WVS3CApXBK4ADSjoIUeMck62owtjElSXnEYMaSGI_OE3B21QplsspPbPlXVUBScLfLOFb9tn-34tw.jpg" width="800" height="533" referrerpolicy="no-referrer">`,
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
@@ -30,8 +30,8 @@ func GCPAPIKey() *config.Rule {
|
||||
r := config.Rule{
|
||||
RuleID: "gcp-api-key",
|
||||
Description: "Uncovered a GCP API key, which could lead to unauthorized access to Google Cloud services and data breaches.",
|
||||
Regex: utils.GenerateUniqueTokenRegex(`AIza[0-9A-Za-z\\-_]{35}`, true),
|
||||
|
||||
Regex: utils.GenerateUniqueTokenRegex(`AIza[\w-]{35}`, false),
|
||||
Entropy: 3.0,
|
||||
Keywords: []string{
|
||||
"AIza",
|
||||
},
|
||||
@@ -39,7 +39,15 @@ func GCPAPIKey() *config.Rule {
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("gcp", secrets.NewSecret(`AIza[0-9A-Za-z\\-_]{35}`)),
|
||||
utils.GenerateSampleSecret("gcp", secrets.NewSecret(`AIza[\w-]{35}`)),
|
||||
// non-word character at end
|
||||
`AIzaSyNHxIf32IQ1a1yjl3ZJIqKZqzLAK1XhDk-`, // gitleaks:allow
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
`GWw4hjABFzZCGiRpmlDyDdo87Jn9BN9THUA47muVRNunLxsa82tMAdvmrhOqNkRKiYMEAFbTJAIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDq`, // text boundary start
|
||||
`AIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDqabcd123`, // text boundary end
|
||||
`apiKey: "AIzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`, // not enough entropy
|
||||
`AIZASYCO2CXRMC9ELSKLHLHRMBSWDEVEDZTLO2O`, // incorrect case
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
@@ -14,6 +14,7 @@ func GitHubPat() *config.Rule {
|
||||
Description: "Uncovered a GitHub Personal Access Token, potentially leading to unauthorized repository access and sensitive content exposure.",
|
||||
RuleID: "github-pat",
|
||||
Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`),
|
||||
Entropy: 3,
|
||||
Keywords: []string{"ghp_"},
|
||||
}
|
||||
|
||||
@@ -21,7 +22,10 @@ func GitHubPat() *config.Rule {
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("github", "ghp_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
"ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
|
||||
func GitHubFineGrainedPat() *config.Rule {
|
||||
@@ -29,7 +33,8 @@ func GitHubFineGrainedPat() *config.Rule {
|
||||
r := config.Rule{
|
||||
Description: "Found a GitHub Fine-Grained Personal Access Token, risking unauthorized repository access and code manipulation.",
|
||||
RuleID: "github-fine-grained-pat",
|
||||
Regex: regexp.MustCompile(`github_pat_[0-9a-zA-Z_]{82}`),
|
||||
Regex: regexp.MustCompile(`github_pat_\w{82}`),
|
||||
Entropy: 3,
|
||||
Keywords: []string{"github_pat_"},
|
||||
}
|
||||
|
||||
@@ -37,7 +42,10 @@ func GitHubFineGrainedPat() *config.Rule {
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("github", "github_pat_"+secrets.NewSecret(utils.AlphaNumeric("82"))),
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
"github_pat_xxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
|
||||
func GitHubOauth() *config.Rule {
|
||||
@@ -46,6 +54,7 @@ func GitHubOauth() *config.Rule {
|
||||
Description: "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks.",
|
||||
RuleID: "github-oauth",
|
||||
Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
|
||||
Entropy: 3,
|
||||
Keywords: []string{"gho_"},
|
||||
}
|
||||
|
||||
@@ -53,7 +62,10 @@ func GitHubOauth() *config.Rule {
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("github", "gho_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
"gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
|
||||
func GitHubApp() *config.Rule {
|
||||
@@ -62,6 +74,7 @@ func GitHubApp() *config.Rule {
|
||||
Description: "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security.",
|
||||
RuleID: "github-app-token",
|
||||
Regex: regexp.MustCompile(`(?:ghu|ghs)_[0-9a-zA-Z]{36}`),
|
||||
Entropy: 3,
|
||||
Keywords: []string{"ghu_", "ghs_"},
|
||||
}
|
||||
|
||||
@@ -70,7 +83,11 @@ func GitHubApp() *config.Rule {
|
||||
utils.GenerateSampleSecret("github", "ghu_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
|
||||
utils.GenerateSampleSecret("github", "ghs_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
"ghu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"ghs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
|
||||
func GitHubRefresh() *config.Rule {
|
||||
@@ -79,6 +96,7 @@ func GitHubRefresh() *config.Rule {
|
||||
Description: "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services.",
|
||||
RuleID: "github-refresh-token",
|
||||
Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
|
||||
Entropy: 3,
|
||||
Keywords: []string{"ghr_"},
|
||||
}
|
||||
|
||||
@@ -86,5 +104,8 @@ func GitHubRefresh() *config.Rule {
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("github", "ghr_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
"ghr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func VaultServiceToken() *config.Rule {
|
||||
@@ -14,6 +15,12 @@ func VaultServiceToken() *config.Rule {
|
||||
Regex: utils.GenerateUniqueTokenRegex(`(?:hvs\.[\w-]{90,120}|s\.(?i:[a-z0-9]{24}))`, false),
|
||||
Entropy: 3.5,
|
||||
Keywords: []string{"hvs", "s."},
|
||||
Allowlist: config.Allowlist{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// https://github.com/gitleaks/gitleaks/issues/1490#issuecomment-2334166357
|
||||
regexp.MustCompile(`s\.[A-Za-z]{24}`),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// validate
|
||||
@@ -29,7 +36,11 @@ func VaultServiceToken() *config.Rule {
|
||||
// Old
|
||||
` credentials: new AWS.SharedIniFileCredentials({ profile: '<YOUR_PROFILE>' })`, // word boundary start
|
||||
`INFO 4 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean`, // word boundary end
|
||||
`s.xxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
|
||||
`s.xxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
|
||||
`s.THISSTRINGISALLUPPERCASE`, // uppercase
|
||||
`s.thisstringisalllowercase`, // lowercase
|
||||
`s.AcceptanceTimeoutSeconds `, // pascal-case
|
||||
`s.makeKubeConfigController = args`, // camel-case
|
||||
// New
|
||||
`hvs.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
|
||||
}
|
||||
@@ -1,69 +1,413 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
)
|
||||
|
||||
// The kubernetes rules are split into two functions to make the complex proximity matching of the data-key and the kind-identifier more readable and testable
|
||||
// KubernetesSecret validates if we detected a kubernetes secret which contains data!
|
||||
func KubernetesSecret() *config.Rule {
|
||||
// Only match basic variations of `kind: secret`, we don't want things like `kind: ExternalSecret`.
|
||||
//language=regexp
|
||||
kindPat := `\bkind:[ \t]*["']?secret["']?`
|
||||
// Only matches values (`key: value`) under `data:` that are:
|
||||
// - valid base64 characters
|
||||
// - longer than 10 characters (no "YmFyCg==")
|
||||
//language=regexp
|
||||
dataPat := `\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))`
|
||||
|
||||
// KubernetesSecretWithDataBefore validates if we detected a kubernetes secret which contains data, before the resource identifier!
|
||||
func KubernetesSecretWithDataBefore() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
RuleID: "kubernetes-secret-with-data-before",
|
||||
RuleID: "kubernetes-secret-yaml",
|
||||
Description: "Possible Kubernetes Secret detected, posing a risk of leaking credentials/tokens from your deployments",
|
||||
// We try to match secrets by looking if we have the keyword
|
||||
Regex: utils.GenerateUniqueTokenRegex(`(?i)(?:\b(?:data:))(\W+(?:\w+\W+){0,200}?)\bkind:.{0,10}Secret\b`, true),
|
||||
|
||||
Regex: regexp.MustCompile(fmt.Sprintf(
|
||||
//language=regexp
|
||||
`(?i)(?:%s(?:.|\s){0,200}?%s|%s(?:.|\s){0,200}?%s)`, kindPat, dataPat, dataPat, kindPat)),
|
||||
Keywords: []string{
|
||||
"Secret",
|
||||
"secret",
|
||||
},
|
||||
// Kubernetes secrets are always yaml files, we limit to common yaml-endings to make this rule more safe!
|
||||
// Kubernetes secrets are usually yaml files.
|
||||
Path: regexp.MustCompile(`(?i)\.ya?ml$`),
|
||||
Allowlist: config.Allowlist{
|
||||
Regexes: []*regexp.Regexp{
|
||||
// Ignore empty or placeholder values.
|
||||
// variable: {{ .Values.Example }} (https://helm.sh/docs/chart_template_guide/variables/)
|
||||
// variable: ""
|
||||
// variable: ''
|
||||
regexp.MustCompile(`[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')`),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := map[string]string{
|
||||
"comment.yaml": `
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: heketi-secret
|
||||
namespace: default
|
||||
data:
|
||||
# base64 encoded password. E.g.: echo -n "mypassword" | base64
|
||||
key: bXlwYXNzd29yZA==`,
|
||||
// The "data"-key is before the identifier "kind: Secret"
|
||||
"before-kubernetes.yaml": `apiVersion: v1
|
||||
data:
|
||||
extra: YWRtaW46cGFzc3dvcmQ=
|
||||
kind: secret
|
||||
metadata:
|
||||
name: secret-sa-sample
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: 'sa-name'`,
|
||||
"before-kubernetes.yml": `apiVersion: v1
|
||||
data:
|
||||
password: UyFCXCpkJHpEc2I9
|
||||
username: YWRtaW4=
|
||||
kind: Secret
|
||||
metadata:
|
||||
creationTimestamp: '2022-06-28T17:44:13Z'
|
||||
name: db-user-pass
|
||||
namespace: default
|
||||
type: Opaque`,
|
||||
"before-comment.yml": `apiVersion: v1
|
||||
data:
|
||||
# the data is abbreviated in this example
|
||||
password: UyFCXCpkJHpEc2I9
|
||||
username: YWRtaW4=
|
||||
kind: Secret
|
||||
metadata:
|
||||
creationTimestamp: '2022-06-28T17:44:13Z'
|
||||
name: db-user-pass
|
||||
namespace: default
|
||||
type: Opaque`,
|
||||
"before-quoted-1.yaml": `apiVersion: 'v1'
|
||||
data:
|
||||
extra: 'YWRtaW46cGFzc3dvcmQ='
|
||||
kind: 'Secret'
|
||||
metadata:
|
||||
name: 'secret-sa-sample'
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: 'sa-name'`,
|
||||
"before-quoted-2.yaml": `apiVersion: "v1"
|
||||
data:
|
||||
extra: "YWRtaW46cGFzc3dvcmQ="
|
||||
kind: "secret"
|
||||
metadata:
|
||||
name: "secret-sa-sample"
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: "sa-name"`,
|
||||
"before-multiline-literal.yaml": `apiVersion: v1
|
||||
data:
|
||||
.dockercfg: |
|
||||
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=
|
||||
metadata:
|
||||
name: secret-dockercfg
|
||||
type: kubernetes.io/dockercfg
|
||||
kind: Secret
|
||||
`,
|
||||
"before-multiline-folded.yaml": `apiVersion: v1
|
||||
data:
|
||||
.dockercfg: >
|
||||
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=
|
||||
metadata:
|
||||
name: secret-dockercfg
|
||||
type: kubernetes.io/dockercfg
|
||||
kind: Secret`,
|
||||
// Sample Kubernetes Secret from https://kubernetes.io/docs/concepts/configuration/secret/
|
||||
// These secrets contain the "data"-key before the actual identifier "kind: Secret"
|
||||
"kubernetes.yaml": "apiVersion: v1'\n' data:'\n' extra: YmFyCg=='\n' kind: secret'\n' metadata:'\n' name: secret-sa-sample'\n' annotations:'\n' kubernetes.io/service-account.name: 'sa-name'", // gitleaks:allow
|
||||
"kubernetes.yml": "apiVersion: v1'\n' data:'\n' password: UyFCXCpkJHpEc2I9'\n' username: YWRtaW4='\n' kind: Secret'\n' metadata:'\n' creationTimestamp: '2022-06-28T17:44:13Z''\n' name: db-user-pass'\n' namespace: default'\n' type: Opaque", // gitleaks:allow
|
||||
// Quoted Test Cases
|
||||
"kubernetes-quoted-1.yaml": "apiVersion: v1'\n' data:'\n' extra: YmFyCg=='\n' kind: 'Secret''\n' metadata:'\n' name: 'secret-sa-sample''\n' annotations:'\n' kubernetes.io/service-account.name: 'sa-name'", // gitleaks:allow
|
||||
"kubernetes-quoted-2.yaml": "apiVersion: v1'\n' data:'\n' extra: YmFyCg=='\n' kind: 'secret''\n' metadata:'\n' name: 'secret-sa-sample''\n' annotations:'\n' kubernetes.io/service-account.name: 'sa-name'", // gitleaks:allow
|
||||
// The "data"-key is after the identifier "kind: Secret"
|
||||
"after-kubernetes.yaml": `apiVersion: v1
|
||||
kind: secret
|
||||
data:
|
||||
extra: YWRtaW46cGFzc3dvcmQ=
|
||||
metadata:
|
||||
name: secret-sa-sample
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: 'sa-name'`,
|
||||
"after-kubernetes.yml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: ca-secret
|
||||
type: Opaque
|
||||
data:
|
||||
ca.pem: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4RENDQXF5Z0F3SUJBZ0lVV3pqUDl5RUk0eHlRSnBzVHVERU4yV2ROaUFzd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2FERUxNQWtHQTFVRUJoTUNWVk14RHpBTkJnTlZCQWdUQms5eVpXZHZiakVSTUE4R0ExVUVCeE1JVUc5eQpkR3hoYm1ReEV6QVJCZ05WQkFvVENrdDFZbVZ5Ym1WMFpYTXhDekFKQmdOVkJBc1RBa05CTVJNd0VRWURWUVFECkV3cExkV0psY201bGRHVnpNQjRYRFRFMk1EZ3hNVEUyTkRnd01Gb1hEVEl4TURneE1ERTJORGd3TUZvd2FERUwKTUFrR0ExVUVCaE1DVlZNeER6QU5CZ05WQkFnVEJrOXlaV2R2YmpFUk1BOEdBMVVFQnhNSVVHOXlkR3hoYm1ReApFekFSQmdOVkJBb1RDa3QxWW1WeWJtVjBaWE14Q3pBSkJnTlZCQXNUQWtOQk1STXdFUVlEVlFRREV3cExkV0psCmNtNWxkR1Z6TUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF3QkhNOGN6anc0Q1cKK05wbklhV012RzZlcVhtelNZT20vbHdaNUhOMnVLck9xaTNHYUUyTjFKd2tzcGRmMXNOUGFZMHdPR2xkbURIZgoxSnlyTW8rUFdLVUVjWko1WGE4Vm02d2I0MlpjczN3MEp5dlEzWFJjaDQyMFJRWGRKayszcmMybWRvSVRkL0lmCnZjWms0N0RzQTMrQU5QSUlSTzdWRmZpS1JNRFpTUDR1OThnVjI2eW1zbjc0TzFVKzNVUHR1TEFTVTFLck9FTk4KR01FWG0ydTJpdmVvbTJrbjFlZTZuM1hCR1o2bU52cUNPdWUxRXdza0gvWkhoUVh1UDgyV1U5dVk0aGVORnoyQwpBNmR0Q0Q0c3Z6eHc3ZFQ2cVhsV0ZIWUYrc3VLVDhXNkczd3NkOWxzV0ZVY0ZWL0lwaTVobEVaTWprNFNoY3RqCjdpYnlrRURKM1FJREFRQUJvMll3WkRBT0JnTlZIUThCQWY4RUJBTUNBUVl3RWdZRFZSMFRBUUgvQkFnd0JnRUIKL3dJQkFqQWRCZ05WSFE0RUZnUVVOdnhRZ3o5ZTNXS2VscU1KTmZXNE1KUHYzc0V3SHdZRFZSMGpCQmd3Rm9BVQpOdnhRZ3o5ZTNXS2VscU1KTmZXNE1KUHYzc0V3RFFZSktvWklodmNOQVFFTEJRQURnZ0VCQUp1TUhYUms1TEVyCmxET1p4Mm9aRUNQZ29reXMzSGJsM05oempXd2pncXdxNVN6a011V3QrUnVkdnRTK0FUQjFtTjRjYTN0eSt2bWcKT09heTkvaDZoditmSE5jZHpYdWR5dFZYZW1KN3F4ZFoxd25DUUcwdnpqOWRZY0xFSGpJWi94dU1jNlY3dnJ4YwpSc0preGp5aE01UXBmRHd0eVZKeGpkUmVBZ0huSyswTkNieHdtQ3cyRGIvOXpudm9LWGk4TEQwbkQzOFQxY3R3CmhmdGxwTmRoZXFNRlpEZXBuTUYwY2g2cHo5TFV5Mkh1cnhrV2dkWVNjY2VNU0hPTzBMcG4xeVVBMWczOTJhUjUKWk81Zm5KMW95Vm1LVWFCeDJCMndsSVlUSXlES1ZiMnY1UXNHbnYvRHVTMDZhcmVLTmsvTGpHRTRlMXlHOHJkcwpacnZHMzNvUmtEbz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
|
||||
`,
|
||||
"after-comment.yml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
creationTimestamp: '2022-06-28T17:44:13Z'
|
||||
name: db-user-pass
|
||||
namespace: default
|
||||
type: Opaque
|
||||
data:
|
||||
# the data is abbreviated in this example
|
||||
password: UyFCXCpkJHpEc2I9
|
||||
username: YWRtaW4=
|
||||
`,
|
||||
"after-quoted-1.yaml": `apiVersion: 'v1'
|
||||
kind: 'Secret'
|
||||
data:
|
||||
password: 'UyFCXCpkJHpEc2I9'
|
||||
username: 'YWRtaW4='
|
||||
metadata:
|
||||
name: 'db-user-pass'
|
||||
namespace: 'default'
|
||||
type: 'Opaque'`,
|
||||
"after-quoted-2.yaml": `apiVersion: "v1"
|
||||
kind: "Secret"
|
||||
data:
|
||||
password: "UyFCXCpkJHpEc2I9"
|
||||
username: "YWRtaW4="
|
||||
metadata:
|
||||
name: "db-user-pass"
|
||||
namespace: "default"
|
||||
type: "Opaque"`,
|
||||
"after-multiline-literal.yaml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: secret-dockercfg
|
||||
type: kubernetes.io/dockercfg
|
||||
data:
|
||||
.dockercfg: |
|
||||
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=
|
||||
`,
|
||||
"after-multiline-folded.yaml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: secret-dockercfg
|
||||
type: kubernetes.io/dockercfg
|
||||
data:
|
||||
.dockercfg: >
|
||||
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=`,
|
||||
}
|
||||
return utils.ValidateWithPaths(r, tps, nil)
|
||||
}
|
||||
fps := map[string]string{
|
||||
"empty-quotes1.yml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: registry-auth-data
|
||||
type: Opaque
|
||||
data:
|
||||
htpasswd: ''
|
||||
`,
|
||||
"empty-quotes2.yml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: registry-auth-data
|
||||
type: Opaque
|
||||
data:
|
||||
htpasswd: ""
|
||||
`,
|
||||
"overly-permissive1.yaml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: registry-auth-data
|
||||
type: Opaque
|
||||
data:
|
||||
htpasswd: {{ htpasswd }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ReplicationController`,
|
||||
"overly-permissive2.yaml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
labels:
|
||||
k8s-app: kubernetes-dashboard
|
||||
addonmanager.kubernetes.io/mode: EnsureExists
|
||||
name: kubernetes-dashboard-csrf
|
||||
namespace: kubernetes-dashboard
|
||||
type: Opaque
|
||||
data:
|
||||
csrf: ""
|
||||
|
||||
// KubernetesSecretWithDataAfter validates if we detected a kubernetes secret which contains data, after the resource identifier!
|
||||
func KubernetesSecretWithDataAfter() *config.Rule {
|
||||
// define rule
|
||||
r := config.Rule{
|
||||
RuleID: "kubernetes-secret-with-data-after",
|
||||
Description: "Possible Kubernetes Secret detected, posing a risk of leaking credentials/tokens from your deployments",
|
||||
// We try to match secrets by looking if we have the keyword
|
||||
Regex: utils.GenerateUniqueTokenRegex(`(?i)(?:\bkind:.{0,10}Secret\b)(?:.|\s){0,200}?\b(?:data:)\s*(.+)`, true),
|
||||
---
|
||||
|
||||
Keywords: []string{
|
||||
"Secret",
|
||||
},
|
||||
// Kubernetes secrets are always yaml files, we limit to common yaml-endings to make this rule more safe!
|
||||
Path: regexp.MustCompile(`(?i)\.ya?ml$`),
|
||||
}
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
labels:
|
||||
k8s-app: kubernetes-dashboard
|
||||
addonmanager.kubernetes.io/mode: EnsureExists
|
||||
name: kubernetes-dashboard-key-holder
|
||||
namespace: kubernetes-dashboard
|
||||
type: Opaque
|
||||
`,
|
||||
"sopssecret.yaml": `apiVersion: isindir.github.com/v1alpha3
|
||||
kind: SopsSecret
|
||||
metadata:
|
||||
name: app1-sopssecret
|
||||
namespace: test
|
||||
spec:
|
||||
suspend: false
|
||||
secretTemplates:
|
||||
- name: ENC[AES256_GCM,data:W3PiZ6lD6bpfAdI=,iv:2qF98ZkchgfWF4tZo8fok6zY0ZLNRV3wFpl8n2iyC7I=,tag:FzoL+CZHkLEqfWKniRApBA==,type:str]
|
||||
labels:
|
||||
app: ENC[AES256_GCM,data:t9ujIQ==,iv:slZBpmKF+DOg/wVBWmq5iTqkRBZUMao0a3MdoxzJs3s=,tag:xJyhdJ4rn/cB/4mxHzmGig==,type:str]
|
||||
stringData:
|
||||
db-password: ENC[AES256_GCM,data:O+5l4g==,iv:c/dS4BCBMbnKsXYuzBuCuVQt8RV9bOv5HgdpL+iwmns=,tag:KkQfh6OymvCt4uC13p318g==,type:str]
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
azure_kv: []
|
||||
hc_vault: []
|
||||
lastmodified: '2021-10-21T10:56:37Z'
|
||||
mac: ENC[AES256_GCM,data:Tl1V1PuI5tZ0Hu3qxxzpDNeKQkuW0g/x/Mlp1yM6HaBqDr+r2FukLdYSYqjjJ3A8g+YkpvMib50M7j0V7zoX9sgCvMKEg86pRsWtThv8n/L+bsjClVTqnhJ9nfYlaPOMlvggbiMOE5hXPIuVz8WXYoVYJ2cVNCd/GfwOraUmj7I=,iv:n7HVI13okfbW3FS/ZsJ2GNmibudxc/TlkLa3umQQ+vc=,tag:R4ikep1wlxlDWlODJqFHHw==,type:str]
|
||||
pgp:
|
||||
- created_at: '2021-10-21T10:56:37Z'
|
||||
enc: |
|
||||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
// validate
|
||||
tps := map[string]string{
|
||||
// Sample Kubernetes Secret from https://kubernetes.io/docs/concepts/configuration/secret/
|
||||
// These secrets contain the data after the actual identifier "kind: Secret"
|
||||
"kubernetes.yaml": "apiVersion: v1'\n' kind: secret'\n' data:'\n' extra: YmFyCg=='\n' metadata:'\n' name: secret-sa-sample'\n' annotations:'\n' kubernetes.io/service-account.name: 'sa-name'", // gitleaks:allow
|
||||
"kubernetes.yml": "apiVersion: v1'\n' kind: Secret'\n' data:'\n' password: UyFCXCpkJHpEc2I9'\n' username: YWRtaW4='\n' metadata:'\n' creationTimestamp: '2022-06-28T17:44:13Z''\n' name: db-user-pass'\n' namespace: default'\n' type: Opaque", // gitleaks:allow
|
||||
// Quoted Test Cases
|
||||
"kubernetes-quoted-1.yaml": "apiVersion: v1'\n' kind: 'Secret''\n' data:'\n' password: UyFCXCpkJHpEc2I9'\n' username: YWRtaW4='\n' metadata:'\n' name: db-user-pass'\n' namespace: default'\n' type: Opaque", // gitleaks:allow
|
||||
"kubernetes-quoted-2.yaml": "apiVersion: v1'\n' kind: 'secret''\n' data:'\n' password: UyFCXCpkJHpEc2I9'\n' username: YWRtaW4='\n' metadata:'\n' name: db-user-pass'\n' namespace: default'\n' type: Opaque", // gitleaks:allow
|
||||
hQGMA3muqimBu2IIAQwAkhR19/6roLq06oaD12vqDMes3/8FweAHxa6TLKg+LRjp
|
||||
2/ntiRJHPBP9DYYFZbkTo8lAmIdVF7KfGIqWgPm5JiNhqfVRhyGPCRgBE7+I8qH6
|
||||
EML9Vo/76kJLHtIjs5rOg7OXgwwitaibs1q6uyVY8TuaGXYIOO1iwL9xVtbayIry
|
||||
NMQd1tFcNb6Vb86Plqm+T1VnSOJMUvryxrLelx89UNM0ctepyVu6YY9jpBjV0QLJ
|
||||
NqNkKAGIMv3RNa9bZHTwveo9T0oXtFnk5H33BxH0ky/DGpD+5Ch1YgbzbqVnr+Bm
|
||||
RX0R/GRhS9IDInd+eiyVX6y3LR5di0fc8TuK43+96wTG+2+ck+lbMrkHYsL2UJNv
|
||||
bAjlOWmIcL4UwGlEOj4EzwcEx+xP3dq57pJ+DasfNwVqps2Kk+ofodR7d6gx7ELH
|
||||
UQmLypCtkRic9v8fVSA2vEL8hAlg9bT8tpHLhHMOwe228cL5dTzFD60RoP+ovRar
|
||||
jIU59Pnu1bnM4pXWEVA20l4BzJ8Fd6gj3TfAg/7Mat+dnTaUwnPgRSybFn0ZZHMW
|
||||
RJDBPkMGFfSGRDfLeD37d61mI31360/w/61LaVp1sdDYodBJCRZFA1YzbqZcxnDl
|
||||
YRjRmpcVRnO+o72CnU/P
|
||||
=V4l4
|
||||
-----END PGP MESSAGE-----
|
||||
fp: 73019E949C1D3C3D1BE8B718C7CD51A565AB592C
|
||||
encrypted_suffix: Templates
|
||||
version: 3.6.1`, // https://github.com/luca-iachini/argocd-test/blob/af0c8eaba270bc918108c8bc3b909f26a4fe995d/kustomize/base/app1/secrets.enc.yaml#L4
|
||||
// The "data"-key is before the identifier "kind: Secret"
|
||||
"before-min-length.yaml": `apiVersion: v1
|
||||
data:
|
||||
extra: YmFyCg==
|
||||
kind: secret
|
||||
metadata:
|
||||
name: secret-sa-sample
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: 'sa-name'`,
|
||||
"before-template.yaml": `apiVersion: v1
|
||||
data:
|
||||
password: {{ .Values.Password }}
|
||||
kind: secret
|
||||
metadata:
|
||||
name: secret-sa-sample
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: 'sa-name'`,
|
||||
"before-externalsecret1.yml": `apiVersion: 'kubernetes-client.io/v1'
|
||||
metadata:
|
||||
name: actions-exporter
|
||||
namespace: github-actions-exporter
|
||||
spec:
|
||||
backendType: secretsManager
|
||||
data:
|
||||
- key: MySecretManagerKey
|
||||
name: github_token
|
||||
property: github_token
|
||||
kind: ExternalSecret
|
||||
`,
|
||||
"before-externalsecret2.yml": `apiVersion: external-secrets.io/v1beta1
|
||||
spec:
|
||||
secretStoreRef:
|
||||
kind: ClusterSecretStore
|
||||
name: aws-secretsmanager
|
||||
refreshInterval: 1h
|
||||
target:
|
||||
creationPolicy: Owner
|
||||
data:
|
||||
- secretKey: api-key
|
||||
remoteRef:
|
||||
key: my-secrets-manager-secret
|
||||
metadata:
|
||||
name: api-key
|
||||
namespace: my-namespace
|
||||
kind: ExternalSecret
|
||||
`,
|
||||
"before-sopssecret.yml": `apiVersion: isindir.github.com/v1alpha3
|
||||
spec:
|
||||
secretTemplates:
|
||||
- name: my-secret-name-1
|
||||
labels:
|
||||
label1: value1
|
||||
annotations:
|
||||
key1: value1
|
||||
data:
|
||||
data-name1: ZGF0YS12YWx1ZTE=
|
||||
data-nameM: ZGF0YS12YWx1ZU0=
|
||||
kind: SopsSecret
|
||||
metadata:
|
||||
name: sopssecret-sample
|
||||
`, // https://github.com/isindir/sops-secrets-operator/blob/8aaf8bb368dc841a2d57f251bd839f08216a9328/config/samples/isindir_v1alpha3_sopssecret.yaml#L4
|
||||
// The "data"-key is after the identifier "kind: Secret"
|
||||
"after-min-length.yaml": `apiVersion: v1
|
||||
kind: secret
|
||||
data:
|
||||
extra: YmFyCg==
|
||||
metadata:
|
||||
name: secret-sa-sample
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: 'sa-name'`,
|
||||
"after-externalsecret1.yml": `apiVersion: 'kubernetes-client.io/v1'
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: actions-exporter
|
||||
namespace: github-actions-exporter
|
||||
spec:
|
||||
backendType: secretsManager
|
||||
data:
|
||||
- key: MySecretManagerKey
|
||||
name: github_token
|
||||
property: github_token
|
||||
- key: MySecretManagerKey`,
|
||||
"after-externalsecret2.yml": `apiVersion: external-secrets.io/v1beta1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: api-key
|
||||
namespace: my-namespace
|
||||
spec:
|
||||
secretStoreRef:
|
||||
kind: ClusterSecretStore
|
||||
name: aws-secretsmanager
|
||||
refreshInterval: 1h
|
||||
target:
|
||||
creationPolicy: Owner
|
||||
data:
|
||||
- secretKey: api-key
|
||||
remoteRef:
|
||||
key: my-secrets-manager-secret`,
|
||||
"after-sopssecret.yml": `apiVersion: isindir.github.com/v1alpha3
|
||||
kind: SopsSecret
|
||||
metadata:
|
||||
name: sopssecret-sample
|
||||
spec:
|
||||
secretTemplates:
|
||||
- name: my-secret-name-0
|
||||
labels:
|
||||
label0: value0
|
||||
labelK: valueK
|
||||
annotations:
|
||||
key0: value0
|
||||
keyN: valueN
|
||||
stringData:
|
||||
data-name0: data-value0
|
||||
data-nameL: data-valueL
|
||||
- name: my-secret-name-1
|
||||
labels:
|
||||
label1: value1
|
||||
annotations:
|
||||
key1: value1
|
||||
data:
|
||||
data-name1: ZGF0YS12YWx1ZTE=
|
||||
data-nameM: ZGF0YS12YWx1ZU0=`,
|
||||
"after-empty-data.yaml": `apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
labels:
|
||||
k8s-app: kubernetes-dashboard
|
||||
addonmanager.kubernetes.io/mode: EnsureExists
|
||||
name: kubernetes-dashboard-csrf
|
||||
namespace: kubernetes-dashboard
|
||||
type: Opaque
|
||||
data:
|
||||
csrf: ""
|
||||
`,
|
||||
}
|
||||
|
||||
return utils.ValidateWithPaths(r, tps, nil)
|
||||
return utils.ValidateWithPaths(r, tps, fps)
|
||||
}
|
||||
@@ -11,17 +11,20 @@ func SquareAccessToken() *config.Rule {
|
||||
r := config.Rule{
|
||||
RuleID: "square-access-token",
|
||||
Description: "Detected a Square Access Token, risking unauthorized payment processing and financial transaction exposure.",
|
||||
Regex: utils.GenerateUniqueTokenRegex(`(EAAA|sq0atp-)[0-9A-Za-z\-_]{22,60}`, true),
|
||||
Regex: utils.GenerateUniqueTokenRegex(`(?:EAAA|sq0atp-)[\w-]{22,60}`, false),
|
||||
Keywords: []string{"sq0atp-", "EAAA"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("square", secrets.NewSecret(`sq0atp-[0-9A-Za-z\-_]{22}`)),
|
||||
utils.GenerateSampleSecret("square", secrets.NewSecret(`(?:EAAA|sq0atp-)[\w-]{22,60}`)),
|
||||
"ARG token=sq0atp-812erere3wewew45678901", // gitleaks:allow
|
||||
"ARG token=EAAAlsBxkkVgvmr7FasTFbM6VUGZ31EJ4jZKTJZySgElBDJ_wyafHuBFquFexY7E", // gitleaks:allow",
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
fps := []string{
|
||||
`aws-cli@sha256:eaaa7b11777babe28e6133a8b19ff71cea687e0d7f05158dee95a71f76ce3d00`,
|
||||
}
|
||||
return utils.Validate(r, tps, fps)
|
||||
}
|
||||
|
||||
func SquareSecret() *config.Rule {
|
||||
@@ -29,13 +32,13 @@ func SquareSecret() *config.Rule {
|
||||
r := config.Rule{
|
||||
RuleID: "square-secret",
|
||||
Description: "Square Secret",
|
||||
Regex: utils.GenerateUniqueTokenRegex(`sq0csp-[0-9A-Za-z\\-_]{43}`, true),
|
||||
Regex: utils.GenerateUniqueTokenRegex(`sq0csp-[\w-]{43}`, false),
|
||||
Keywords: []string{"sq0csp-"},
|
||||
}
|
||||
|
||||
// validate
|
||||
tps := []string{
|
||||
utils.GenerateSampleSecret("square", secrets.NewSecret(`sq0csp-[0-9A-Za-z\\-_]{43}`)),
|
||||
utils.GenerateSampleSecret("square", secrets.NewSecret(`sq0csp-[\w-]{43}`)),
|
||||
`value: "sq0csp-0p9h7g6f4s3s3s3-4a3ardgwa6ADRDJDDKUFYDYDYDY"`, // gitleaks:allow
|
||||
}
|
||||
return utils.Validate(r, tps, nil)
|
||||
|
||||
+6
-6
@@ -31,13 +31,13 @@ func runGit(cmd *cobra.Command, args []string) {
|
||||
)
|
||||
|
||||
// grab source
|
||||
source := "."
|
||||
if len(args) == 1 {
|
||||
source = args[0]
|
||||
if source == "" {
|
||||
source = "."
|
||||
source := "."
|
||||
if len(args) == 1 {
|
||||
source = args[0]
|
||||
if source == "" {
|
||||
source = "."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initConfig(source)
|
||||
|
||||
|
||||
+23
-8
@@ -131,9 +131,6 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
StopWords: r.Allowlist.StopWords,
|
||||
},
|
||||
}
|
||||
if err := r.Validate(); err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
orderedRules = append(orderedRules, r.RuleID)
|
||||
rulesMap[r.RuleID] = r
|
||||
@@ -171,7 +168,15 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
||||
} else if c.Extend.Path != "" {
|
||||
c.extendPath()
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the rules after everything has been assembled (including extended configs).
|
||||
if extendDepth == 0 {
|
||||
for _, rule := range rulesMap {
|
||||
if err := rule.Validate(); err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c, nil
|
||||
@@ -235,12 +240,22 @@ func (c *Config) extendURL() {
|
||||
}
|
||||
|
||||
func (c *Config) extend(extensionConfig Config) {
|
||||
for ruleID, rule := range extensionConfig.Rules {
|
||||
if _, ok := c.Rules[ruleID]; !ok {
|
||||
log.Trace().Msgf("adding %s to base config", ruleID)
|
||||
c.Rules[ruleID] = rule
|
||||
c.Keywords = append(c.Keywords, rule.Keywords...)
|
||||
for ruleID, baseRule := range extensionConfig.Rules {
|
||||
currentRule, ok := c.Rules[ruleID]
|
||||
if !ok {
|
||||
// Rule doesn't exist, add it to the config.
|
||||
c.Rules[ruleID] = baseRule
|
||||
c.Keywords = append(c.Keywords, baseRule.Keywords...)
|
||||
c.OrderedRules = append(c.OrderedRules, ruleID)
|
||||
} else {
|
||||
// Rule exists, merge our changes into the base.
|
||||
baseRule.Allowlist.Commits = append(baseRule.Allowlist.Commits, currentRule.Allowlist.Commits...)
|
||||
baseRule.Allowlist.Paths = append(baseRule.Allowlist.Paths, currentRule.Allowlist.Paths...)
|
||||
baseRule.Allowlist.Regexes = append(baseRule.Allowlist.Regexes, currentRule.Allowlist.Regexes...)
|
||||
baseRule.Allowlist.StopWords = append(baseRule.Allowlist.StopWords, currentRule.Allowlist.StopWords...)
|
||||
|
||||
delete(c.Rules, ruleID)
|
||||
c.Rules[ruleID] = baseRule
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+69
-8
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
@@ -91,11 +92,11 @@ func TestTranslate(t *testing.T) {
|
||||
cfg: Config{},
|
||||
wantError: fmt.Errorf("rule |id| is missing or empty, regex: (?i)(discord[a-z0-9_ .\\-,]{0,25})(=|>|:=|\\|\\|:|<=|=>|:).{0,5}['\\\"]([a-h0-9]{64})['\\\"]"),
|
||||
},
|
||||
//{
|
||||
// cfgName: "no_regex_or_path",
|
||||
// cfg: Config{},
|
||||
// wantError: fmt.Errorf("discord-api-key: both |regex| and |path| are empty, this rule will have no effect"),
|
||||
//},
|
||||
{
|
||||
cfgName: "no_regex_or_path",
|
||||
cfg: Config{},
|
||||
wantError: fmt.Errorf("discord-api-key: both |regex| and |path| are empty, this rule will have no effect"),
|
||||
},
|
||||
{
|
||||
cfgName: "bad_entropy_group",
|
||||
cfg: Config{},
|
||||
@@ -129,11 +130,58 @@ func TestTranslate(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
cfgName: "extend_rule_allowlist",
|
||||
cfg: Config{
|
||||
Rules: map[string]Rule{
|
||||
"aws-secret-key-again-again": {
|
||||
RuleID: "aws-secret-key-again-again",
|
||||
Description: "AWS Secret Key",
|
||||
Regex: regexp.MustCompile(`(?i)aws_(.{0,20})?=?.[\'\"0-9a-zA-Z\/+]{40}`),
|
||||
Tags: []string{"key", "AWS"},
|
||||
Keywords: []string{},
|
||||
Allowlist: Allowlist{
|
||||
Commits: []string{"abcdefg1"},
|
||||
Regexes: []*regexp.Regexp{
|
||||
regexp.MustCompile(`foo.+bar`),
|
||||
},
|
||||
Paths: []*regexp.Regexp{
|
||||
regexp.MustCompile(`ignore\.xaml`),
|
||||
},
|
||||
StopWords: []string{"example"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
cfgName: "extend_empty_regexpath",
|
||||
cfg: Config{
|
||||
Rules: map[string]Rule{
|
||||
"aws-secret-key-again-again": {
|
||||
RuleID: "aws-secret-key-again-again",
|
||||
Description: "AWS Secret Key",
|
||||
Regex: regexp.MustCompile(`(?i)aws_(.{0,20})?=?.[\'\"0-9a-zA-Z\/+]{40}`),
|
||||
Tags: []string{"key", "AWS"},
|
||||
Keywords: []string{},
|
||||
Allowlist: Allowlist{
|
||||
Paths: []*regexp.Regexp{
|
||||
regexp.MustCompile(`something.py`),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.cfgName, func(t *testing.T) {
|
||||
viper.Reset()
|
||||
t.Cleanup(func() {
|
||||
extendDepth = 0
|
||||
viper.Reset()
|
||||
})
|
||||
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigName(tt.cfgName)
|
||||
viper.SetConfigType("toml")
|
||||
@@ -144,8 +192,21 @@ func TestTranslate(t *testing.T) {
|
||||
err = viper.Unmarshal(&vc)
|
||||
require.NoError(t, err)
|
||||
cfg, err := vc.Translate()
|
||||
assert.Equal(t, tt.wantError, err)
|
||||
assert.Equal(t, cfg.Rules, tt.cfg.Rules)
|
||||
if !assert.Equal(t, tt.wantError, err) {
|
||||
return
|
||||
}
|
||||
|
||||
var regexComparer = func(x, y *regexp.Regexp) bool {
|
||||
// Compare the string representation of the regex patterns.
|
||||
if x == nil || y == nil {
|
||||
return x == y
|
||||
}
|
||||
return x.String() == y.String()
|
||||
}
|
||||
opts := cmp.Options{cmp.Comparer(regexComparer)}
|
||||
if diff := cmp.Diff(tt.cfg.Rules, cfg.Rules, opts); diff != "" {
|
||||
t.Errorf("%s diff: (-want +got)\n%s", tt.cfgName, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+34
-15
@@ -14,7 +14,7 @@ title = "gitleaks config"
|
||||
description = "global allow lists"
|
||||
paths = [
|
||||
'''gitleaks.toml''',
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe)$''',
|
||||
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$''',
|
||||
'''(go.mod|go.sum|go.work|go.work.sum)$''',
|
||||
'''gradle.lockfile''',
|
||||
'''verification-metadata.xml''',
|
||||
@@ -390,7 +390,8 @@ keywords = [
|
||||
[[rules]]
|
||||
id = "etsy-access-token"
|
||||
description = "Found an Etsy Access Token, potentially compromising Etsy shop management and customer data."
|
||||
regex = '''(?i)(?:etsy)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}([a-z0-9]{24})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
regex = '''(?i)(?:(?-i:ETSY|[Ee]tsy))(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}([a-z0-9]{24})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
entropy = 3
|
||||
keywords = [
|
||||
"etsy",
|
||||
]
|
||||
@@ -480,6 +481,15 @@ keywords = [
|
||||
"flwseck_test",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
id = "flyio-access-token"
|
||||
description = "Uncovered a Fly.io API key"
|
||||
regex = '''\b((?:fo1_[\w-]{43}|fm1[ar]_[a-zA-Z0-9+\/]{100,}={0,3}|fm2_[a-zA-Z0-9+\/]{100,}={0,3}))(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
entropy = 4
|
||||
keywords = [
|
||||
"fo1_","fm1","fm2_",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
id = "frameio-api-token"
|
||||
description = "Found a Frame.io API token, potentially compromising video collaboration and project management."
|
||||
@@ -499,7 +509,8 @@ keywords = [
|
||||
[[rules]]
|
||||
id = "gcp-api-key"
|
||||
description = "Uncovered a GCP API key, which could lead to unauthorized access to Google Cloud services and data breaches."
|
||||
regex = '''(?i)\b(AIza[0-9A-Za-z\\-_]{35})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
regex = '''\b(AIza[\w-]{35})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
entropy = 3
|
||||
keywords = [
|
||||
"aiza",
|
||||
]
|
||||
@@ -1995,6 +2006,7 @@ stopwords = [
|
||||
id = "github-app-token"
|
||||
description = "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security."
|
||||
regex = '''(?:ghu|ghs)_[0-9a-zA-Z]{36}'''
|
||||
entropy = 3
|
||||
keywords = [
|
||||
"ghu_","ghs_",
|
||||
]
|
||||
@@ -2002,7 +2014,8 @@ keywords = [
|
||||
[[rules]]
|
||||
id = "github-fine-grained-pat"
|
||||
description = "Found a GitHub Fine-Grained Personal Access Token, risking unauthorized repository access and code manipulation."
|
||||
regex = '''github_pat_[0-9a-zA-Z_]{82}'''
|
||||
regex = '''github_pat_\w{82}'''
|
||||
entropy = 3
|
||||
keywords = [
|
||||
"github_pat_",
|
||||
]
|
||||
@@ -2011,6 +2024,7 @@ keywords = [
|
||||
id = "github-oauth"
|
||||
description = "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks."
|
||||
regex = '''gho_[0-9a-zA-Z]{36}'''
|
||||
entropy = 3
|
||||
keywords = [
|
||||
"gho_",
|
||||
]
|
||||
@@ -2019,6 +2033,7 @@ keywords = [
|
||||
id = "github-pat"
|
||||
description = "Uncovered a GitHub Personal Access Token, potentially leading to unauthorized repository access and sensitive content exposure."
|
||||
regex = '''ghp_[0-9a-zA-Z]{36}'''
|
||||
entropy = 3
|
||||
keywords = [
|
||||
"ghp_",
|
||||
]
|
||||
@@ -2027,6 +2042,7 @@ keywords = [
|
||||
id = "github-refresh-token"
|
||||
description = "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services."
|
||||
regex = '''ghr_[0-9a-zA-Z]{36}'''
|
||||
entropy = 3
|
||||
keywords = [
|
||||
"ghr_",
|
||||
]
|
||||
@@ -2220,21 +2236,18 @@ keywords = [
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
id = "kubernetes-secret-with-data-after"
|
||||
id = "kubernetes-secret-yaml"
|
||||
description = "Possible Kubernetes Secret detected, posing a risk of leaking credentials/tokens from your deployments"
|
||||
regex = '''(?i)\b((?i)(?:\bkind:.{0,10}Secret\b)(?:.|\s){0,200}?\b(?:data:)\s*(.+))(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
regex = '''(?i)(?:\bkind:[ \t]*["']?secret["']?(?:.|\s){0,200}?\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))|\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))(?:.|\s){0,200}?\bkind:[ \t]*["']?secret["']?)'''
|
||||
path = '''(?i)\.ya?ml$'''
|
||||
keywords = [
|
||||
"secret",
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
id = "kubernetes-secret-with-data-before"
|
||||
description = "Possible Kubernetes Secret detected, posing a risk of leaking credentials/tokens from your deployments"
|
||||
regex = '''(?i)\b((?i)(?:\b(?:data:))(\W+(?:\w+\W+){0,200}?)\bkind:.{0,10}Secret\b)(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
path = '''(?i)\.ya?ml$'''
|
||||
keywords = [
|
||||
"secret",
|
||||
[rules.allowlist]
|
||||
|
||||
regexes = [
|
||||
'''[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')''',
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
@@ -2763,7 +2776,7 @@ keywords = [
|
||||
[[rules]]
|
||||
id = "square-access-token"
|
||||
description = "Detected a Square Access Token, risking unauthorized payment processing and financial transaction exposure."
|
||||
regex = '''(?i)\b((EAAA|sq0atp-)[0-9A-Za-z\-_]{22,60})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
regex = '''\b((?:EAAA|sq0atp-)[\w-]{22,60})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||
keywords = [
|
||||
"sq0atp-","eaaa",
|
||||
]
|
||||
@@ -2797,7 +2810,7 @@ keywords = [
|
||||
|
||||
regexTarget = "line"
|
||||
regexes = [
|
||||
"sumOf",
|
||||
'''sumOf''',
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
@@ -2906,6 +2919,12 @@ keywords = [
|
||||
"hvs","s.",
|
||||
]
|
||||
|
||||
[rules.allowlist]
|
||||
|
||||
regexes = [
|
||||
'''s\.[A-Za-z]{24}''',
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
id = "yandex-access-token"
|
||||
description = "Found a Yandex Access Token, posing a risk to Yandex service integrations and user data privacy."
|
||||
|
||||
+3
-5
@@ -60,12 +60,10 @@ func (r Rule) Validate() error {
|
||||
return fmt.Errorf("rule |id| is missing or empty" + context)
|
||||
}
|
||||
|
||||
// TODO: uncomment this once it works with |extend|.
|
||||
// See: https://github.com/gitleaks/gitleaks/issues/1507#issuecomment-2352559213
|
||||
// Ensure the rule actually matches something.
|
||||
//if r.Regex == nil && r.Path == nil {
|
||||
// return fmt.Errorf("%s: both |regex| and |path| are empty, this rule will have no effect", r.RuleID)
|
||||
//}
|
||||
if r.Regex == nil && r.Path == nil {
|
||||
return fmt.Errorf("%s: both |regex| and |path| are empty, this rule will have no effect", r.RuleID)
|
||||
}
|
||||
|
||||
// Ensure |secretGroup| works.
|
||||
if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() {
|
||||
|
||||
+5
-1
@@ -149,7 +149,11 @@ func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
for scanner.Scan() {
|
||||
d.gitleaksIgnore[scanner.Text()] = true
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
// Skip lines that start with a comment
|
||||
if line != "" && !strings.HasPrefix(line, "#") {
|
||||
d.gitleaksIgnore[line] = true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ require (
|
||||
|
||||
require (
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
|
||||
@@ -127,6 +127,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ title = "gitleaks extended 3"
|
||||
## This should not be loaded since we can only extend configs to a depth of 3
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
id = "aws-secret-key-again-again"
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws_(.{0,20})?=?.[\'\"0-9a-zA-Z\/+]{40}'''
|
||||
tags = ["key", "AWS"]
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
[extend]
|
||||
path="../testdata/config/extend_3.toml"
|
||||
|
||||
[[rules]]
|
||||
id = "aws-secret-key-again-again"
|
||||
[rules.allowlist]
|
||||
description = "False positive. Keys used for colors match the rule, and should be excluded."
|
||||
paths = ['''something.py''']
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
title = "gitleaks extended 3"
|
||||
|
||||
[extend]
|
||||
path="../testdata/config/extend_3.toml"
|
||||
|
||||
[[rules]]
|
||||
id = "aws-secret-key-again-again"
|
||||
[rules.allowlist]
|
||||
commits = ['''abcdefg1''']
|
||||
regexes = ['''foo.+bar''']
|
||||
paths = ['''ignore\.xaml''']
|
||||
stopwords = ['''example''']
|
||||
Vendored
+1
@@ -1,2 +1,3 @@
|
||||
api/ignoreGlobal.go:aws-access-key:20
|
||||
# test comment
|
||||
53cd7a3c6eb4937f413e3c25e4a9f39289afa69e:api/ignoreCommit.go:aws-access-key:20
|
||||
Reference in new issue
Block a user