|
|
@@ -2,7 +2,9 @@ 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"
|
|
|
+ "regexp"
|
|
|
)
|
|
|
|
|
|
func GenericCredential() *config.Rule {
|
|
|
@@ -15,7 +17,8 @@ func GenericCredential() *config.Rule {
|
|
|
"api",
|
|
|
"token",
|
|
|
"secret",
|
|
|
- "client",
|
|
|
+ "credential",
|
|
|
+ "creds",
|
|
|
"passwd",
|
|
|
"password",
|
|
|
"auth",
|
|
|
@@ -26,7 +29,8 @@ func GenericCredential() *config.Rule {
|
|
|
"api",
|
|
|
"token",
|
|
|
"secret",
|
|
|
- "client",
|
|
|
+ "credential",
|
|
|
+ "creds",
|
|
|
"passwd",
|
|
|
"password",
|
|
|
"auth",
|
|
|
@@ -35,7 +39,22 @@ func GenericCredential() *config.Rule {
|
|
|
Entropy: 3.5,
|
|
|
Allowlists: []config.Allowlist{
|
|
|
{
|
|
|
- StopWords: DefaultStopWords,
|
|
|
+ Description: "Allowlist for Generic API Keys",
|
|
|
+ MatchCondition: config.AllowlistMatchOr,
|
|
|
+ Regexes: []*regexp.Regexp{
|
|
|
+ regexp.MustCompile(`(?i)(` +
|
|
|
+ `public[_.-]?(key|token)` + // public key -> not a secret
|
|
|
+ `|api[_.-]?(version|id)` + // version/id -> not a secret
|
|
|
+ `|(secret)[_.-]?name` + // name of e.g. env variable
|
|
|
+ `|issuerkeyhash` + // part of ssl cert
|
|
|
+ `|(?-i:[DdMm]onkey|[DM]ONKEY)|keying` + // common words containing "key"
|
|
|
+ `|(primary|foreign|natural|definition|hot)[_.-]?key` +
|
|
|
+ `|key[_.-]?(alias|board|code|stone|storetype|word|up|down|left|right)` +
|
|
|
+ `|rapid|capital` + // common words containing "api"
|
|
|
+ `)`),
|
|
|
+ },
|
|
|
+ RegexTarget: "match",
|
|
|
+ StopWords: DefaultStopWords,
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
@@ -44,14 +63,54 @@ func GenericCredential() *config.Rule {
|
|
|
tps := []string{
|
|
|
utils.GenerateSampleSecret("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443"), //gitleaks:allow
|
|
|
utils.GenerateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
|
|
|
- `"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
|
|
|
+ `"credentials" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
|
|
|
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
|
|
|
+ `passwd = ` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
|
|
+ `private-key: ` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{100}`),
|
|
|
+ `mySecretString=` + newPlausibleSecret(`[a-zA-Z0-9]{30}`),
|
|
|
+ `some_api_token_123 = "` + newPlausibleSecret(`[a-zA-Z0-9]{60}`) + `"`,
|
|
|
+ `todo_secret_do_not_commit = ` + newPlausibleSecret(`[a-zA-Z0-9]{30}`),
|
|
|
+ `creds = ` + newPlausibleSecret(`[a-zA-Z0-9]{30}`),
|
|
|
}
|
|
|
fps := []string{
|
|
|
`client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.client-vpn-endpoint.id`,
|
|
|
`password combination.
|
|
|
|
|
|
R5: Regulatory--21`,
|
|
|
+ `public_key = "9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit"`,
|
|
|
+ `publicToken = "9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit"`,
|
|
|
+ `clientId = "73082700-1f09-405b-80d0-3131bfd6272d"`,
|
|
|
+ `MantleAPI_version=9a038989604e8da62ecddbe2094b16ce1b778be1`,
|
|
|
+ `COMMUNICATION_API_VERSION=rc0.13.0_20230412_0712-SNAPSHOT`,
|
|
|
+ `LLM_SECRET_NAME = "NEXUS-GPT4-API-KEY"`,
|
|
|
+ `keyword: "Befaehigung_P2"`,
|
|
|
+ `minisat-master-keying:x64-uwp=fail`,
|
|
|
+ `monkeys-audio:mx64-uwp=fail`,
|
|
|
+ `rapidstring:marm64-uwp=fail`,
|
|
|
+ `<entry key="jetbrains.mps.v8_elimination" value="executed" />`,
|
|
|
+ `event-bus-message-api:rc0.15.0_20231217_1420-SNAPSHOT'`,
|
|
|
+ `primaryKey=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
|
|
+ `foreignKey=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
|
|
+ `key_down_event=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
|
|
+ `issuerKeyHash=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
|
|
|
}
|
|
|
return utils.Validate(r, tps, fps)
|
|
|
}
|
|
|
+
|
|
|
+func newPlausibleSecret(regex string) string {
|
|
|
+ allowList := config.Allowlist{StopWords: DefaultStopWords}
|
|
|
+ // attempt to generate a random secret,
|
|
|
+ // retrying until it contains at least one digit and no stop words
|
|
|
+ // TODO: currently the DefaultStopWords list contains many short words,
|
|
|
+ // so there is a significant chance of generating a secret that contains a stop word
|
|
|
+ for {
|
|
|
+ secret := secrets.NewSecret(regex)
|
|
|
+ if !regexp.MustCompile(`[1-9]`).MatchString(secret) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if allowList.ContainsStopWord(secret) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ return secret
|
|
|
+ }
|
|
|
+}
|