mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02808f45d0 | ||
|
|
07e1c30592 | ||
|
|
db63fc1bf4 | ||
|
|
9a4538c4d6 | ||
|
|
fe94ef9ca3 | ||
|
|
bb4424d454 | ||
|
|
575e923cf8 |
No files matched your search
@@ -402,13 +402,19 @@ class CustomClass:
|
|||||||
You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is experimental and is subject to change in the future.
|
You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is experimental and is subject to change in the future.
|
||||||
|
|
||||||
## Sponsorships
|
## Sponsorships
|
||||||
|
<p align="left">
|
||||||
|
<h3><a href="https://coderabbit.ai/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">coderabbit.ai</h3>
|
||||||
|
<a href="https://coderabbit.ai/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">
|
||||||
|
<img alt="CodeRabbit.ai Sponsorship" src="https://github.com/gitleaks/gitleaks/assets/15034943/76c30a85-887b-47ca-9956-17a8e55c6c41" width=200>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
<p align="left">
|
<p align="left">
|
||||||
<a href="https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">
|
<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>
|
<img alt="Tines Sponsorship" src="https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png" width=200>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
## Exit Codes
|
## Exit Codes
|
||||||
|
|
||||||
You can always set the exit code when leaks are encountered with the --exit-code flag. Default exit codes below:
|
You can always set the exit code when leaks are encountered with the --exit-code flag. Default exit codes below:
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ func main() {
|
|||||||
rules.HuggingFaceAccessToken(),
|
rules.HuggingFaceAccessToken(),
|
||||||
rules.HuggingFaceOrganizationApiToken(),
|
rules.HuggingFaceOrganizationApiToken(),
|
||||||
rules.Intercom(),
|
rules.Intercom(),
|
||||||
|
rules.Intra42ClientSecret(),
|
||||||
rules.JFrogAPIKey(),
|
rules.JFrogAPIKey(),
|
||||||
rules.JFrogIdentityToken(),
|
rules.JFrogIdentityToken(),
|
||||||
rules.JWT(),
|
rules.JWT(),
|
||||||
@@ -132,6 +133,7 @@ func main() {
|
|||||||
rules.NewRelicUserID(),
|
rules.NewRelicUserID(),
|
||||||
rules.NewRelicUserKey(),
|
rules.NewRelicUserKey(),
|
||||||
rules.NewRelicBrowserAPIKey(),
|
rules.NewRelicBrowserAPIKey(),
|
||||||
|
rules.NewRelicInsertKey(),
|
||||||
rules.NPM(),
|
rules.NPM(),
|
||||||
rules.NytimesAccessToken(),
|
rules.NytimesAccessToken(),
|
||||||
rules.OktaAccessToken(),
|
rules.OktaAccessToken(),
|
||||||
|
|||||||
@@ -32,17 +32,20 @@ func HashicorpField() *config.Rule {
|
|||||||
RuleID: "hashicorp-tf-password",
|
RuleID: "hashicorp-tf-password",
|
||||||
Regex: generateSemiGenericRegex(keywords, fmt.Sprintf(`"%s"`, alphaNumericExtended("8,20")), true),
|
Regex: generateSemiGenericRegex(keywords, fmt.Sprintf(`"%s"`, alphaNumericExtended("8,20")), true),
|
||||||
Keywords: keywords,
|
Keywords: keywords,
|
||||||
|
Path: regexp.MustCompile(`\.(tf|hcl)$`),
|
||||||
}
|
}
|
||||||
|
|
||||||
tps := []string{
|
tps := map[string]string{
|
||||||
// Example from: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_server.html
|
// Example from: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_server.html
|
||||||
"administrator_login_password = " + `"thisIsDog11"`,
|
"file.tf": "administrator_login_password = " + `"thisIsDog11"`,
|
||||||
// https://registry.terraform.io/providers/petoju/mysql/latest/docs
|
// https://registry.terraform.io/providers/petoju/mysql/latest/docs
|
||||||
"password = " + `"rootpasswd"`,
|
"file.hcl": "password = " + `"rootpasswd"`,
|
||||||
}
|
}
|
||||||
fps := []string{
|
fps := map[string]string{
|
||||||
"administrator_login_password = var.db_password",
|
"file.tf": "administrator_login_password = var.db_password",
|
||||||
`password = "${aws_db_instance.default.password}"`,
|
"file.hcl": `password = "${aws_db_instance.default.password}"`,
|
||||||
|
"unrelated.js": "password = " + `"rootpasswd"`,
|
||||||
}
|
}
|
||||||
return validate(r, tps, fps)
|
|
||||||
|
return validateWithPaths(r, tps, fps)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package rules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
|
||||||
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Intra42ClientSecret() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "Found a Intra42 client secret, which could lead to unauthorized access to the 42School API and sensitive data.",
|
||||||
|
RuleID: "intra42-client-secret",
|
||||||
|
Regex: generateUniqueTokenRegex(`s-s4t2(?:ud|af)-[abcdef0123456789]{64}`, true),
|
||||||
|
Keywords: []string{
|
||||||
|
"intra",
|
||||||
|
"s-s4t2ud-",
|
||||||
|
"s-s4t2af-",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
"clientSecret := \"s-s4t2ud-" + secrets.NewSecret(hex("64")) + "\"",
|
||||||
|
"clientSecret := \"s-s4t2af-" + secrets.NewSecret(hex("64")) + "\"",
|
||||||
|
"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", // gitleaks:allow
|
||||||
|
"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", // gitleaks:allow
|
||||||
|
}
|
||||||
|
return validate(r, tps, nil)
|
||||||
|
}
|
||||||
@@ -75,3 +75,26 @@ func NewRelicBrowserAPIKey() *config.Rule {
|
|||||||
}
|
}
|
||||||
return validate(r, tps, nil)
|
return validate(r, tps, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewRelicInsertKey() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
RuleID: "new-relic-insert-key",
|
||||||
|
Description: "Discovered a New Relic insight insert key, compromising data injection into the platform.",
|
||||||
|
Regex: generateSemiGenericRegex([]string{
|
||||||
|
"new-relic",
|
||||||
|
"newrelic",
|
||||||
|
"new_relic",
|
||||||
|
}, `NRII-[a-z0-9-]{32}`, true),
|
||||||
|
|
||||||
|
Keywords: []string{
|
||||||
|
"NRII-",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
generateSampleSecret("new-relic", "NRII-"+secrets.NewSecret(hex("32"))),
|
||||||
|
}
|
||||||
|
return validate(r, tps, nil)
|
||||||
|
}
|
||||||
@@ -97,6 +97,34 @@ func validate(r config.Rule, truePositives []string, falsePositives []string) *c
|
|||||||
return &r
|
return &r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateWithPaths(r config.Rule, truePositives map[string]string, falsePositives map[string]string) *config.Rule {
|
||||||
|
var keywords []string
|
||||||
|
for _, k := range r.Keywords {
|
||||||
|
keywords = append(keywords, strings.ToLower(k))
|
||||||
|
}
|
||||||
|
r.Keywords = keywords
|
||||||
|
|
||||||
|
rules := make(map[string]config.Rule)
|
||||||
|
rules[r.RuleID] = r
|
||||||
|
d := detect.NewDetector(config.Config{
|
||||||
|
Rules: rules,
|
||||||
|
Keywords: keywords,
|
||||||
|
})
|
||||||
|
for path, tp := range truePositives {
|
||||||
|
f := detect.Fragment{Raw: tp, FilePath: path}
|
||||||
|
if len(d.Detect(f)) != 1 {
|
||||||
|
log.Fatal().Msgf("Failed to validate. For rule ID [%s], true positive [%s] in %s was not detected by regexp [%s] path [%s]", r.RuleID, tp, path, r.Regex, r.Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for path, fp := range falsePositives {
|
||||||
|
f := detect.Fragment{Raw: fp, FilePath: path}
|
||||||
|
if len(d.Detect(f)) != 0 {
|
||||||
|
log.Fatal().Msgf("Failed to validate. For rule ID [%s], false positive [%s] in %s was detected by regexp [%s] path [%s]", r.RuleID, fp, path, r.Regex, r.Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &r
|
||||||
|
}
|
||||||
|
|
||||||
func numeric(size string) string {
|
func numeric(size string) string {
|
||||||
return fmt.Sprintf(`[0-9]{%s}`, size)
|
return fmt.Sprintf(`[0-9]{%s}`, size)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,44 +13,67 @@ func TelegramBotToken() *config.Rule {
|
|||||||
Description: "Detected a Telegram Bot API Token, risking unauthorized bot operations and message interception on Telegram.",
|
Description: "Detected a Telegram Bot API Token, risking unauthorized bot operations and message interception on Telegram.",
|
||||||
RuleID: "telegram-bot-api-token",
|
RuleID: "telegram-bot-api-token",
|
||||||
|
|
||||||
Regex: regexp.MustCompile(`(?i)(?:^|[^0-9])([0-9]{5,16}:A[a-zA-Z0-9_\-]{34})(?:$|[^a-zA-Z0-9_\-])`),
|
Regex: regexp.MustCompile(`(?i:(?:telegr)(?:[0-9a-z\(-_\t .\\]{0,40})(?:[\s|']|[\s|"]){0,3})(?:=|\|\|:|<=|=>|:|\?=|\()(?:'|\"|\s|=|\x60){0,5}([0-9]{5,16}:A[a-z0-9_\-]{34})(?:['|\"|\n|\r|\s|\x60|;|\\]|$)`),
|
||||||
Keywords: []string{
|
Keywords: []string{
|
||||||
"telegram",
|
"telegr",
|
||||||
"api",
|
|
||||||
"bot",
|
|
||||||
"token",
|
|
||||||
"url",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
validToken := secrets.NewSecret(numeric("8") + ":A" + alphaNumericExtendedShort("34"))
|
var (
|
||||||
minToken := secrets.NewSecret(numeric("5") + ":A" + alphaNumericExtendedShort("34"))
|
validToken = secrets.NewSecret(numeric("8") + ":A" + alphaNumericExtendedShort("34"))
|
||||||
maxToken := secrets.NewSecret(numeric("16") + ":A" + alphaNumericExtendedShort("34"))
|
minToken = secrets.NewSecret(numeric("5") + ":A" + alphaNumericExtendedShort("34"))
|
||||||
|
maxToken = secrets.NewSecret(numeric("16") + ":A" + alphaNumericExtendedShort("34"))
|
||||||
|
// xsdWithToken = secrets.NewSecret(`<xsd:element name="AgencyIdentificationCode" type="` + numeric("5") + `:A` + alphaNumericExtendedShort("34") + `"/>`)
|
||||||
|
)
|
||||||
tps := []string{
|
tps := []string{
|
||||||
// variable assignment
|
// variable assignment
|
||||||
generateSampleSecret("telegram", validToken),
|
generateSampleSecret("telegram", validToken),
|
||||||
// URL containing token
|
// URL containing token TODO add another url based rule
|
||||||
generateSampleSecret("url", "https://api.telegram.org/bot"+validToken+"/sendMessage"),
|
// generateSampleSecret("url", "https://api.telegram.org/bot"+validToken+"/sendMessage"),
|
||||||
// object constructor
|
// object constructor
|
||||||
`const bot = new Telegraf("` + validToken + `")`,
|
`const bot = new Telegraf("` + validToken + `")`,
|
||||||
// .env
|
// .env
|
||||||
`API_TOKEN = ` + validToken,
|
`TELEGRAM_API_TOKEN = ` + validToken,
|
||||||
// YAML
|
// YAML
|
||||||
`bot: ` + validToken,
|
`telegram bot: ` + validToken,
|
||||||
// Token with min bot_id
|
// Token with min bot_id
|
||||||
generateSampleSecret("telegram", minToken),
|
generateSampleSecret("telegram", minToken),
|
||||||
// Token with max bot_id
|
// Token with max bot_id
|
||||||
generateSampleSecret("telegram", maxToken),
|
generateSampleSecret("telegram", maxToken),
|
||||||
|
// Valid token in XSD document TODO separate rule for this
|
||||||
|
// generateSampleSecret("telegram", xsdWithToken),
|
||||||
}
|
}
|
||||||
|
|
||||||
tooSmallToken := secrets.NewSecret(numeric("4") + ":A" + alphaNumericExtendedShort("34"))
|
var (
|
||||||
tooBigToken := secrets.NewSecret(numeric("17") + ":A" + alphaNumericExtendedShort("34"))
|
tooSmallToken = secrets.NewSecret(numeric("4") + ":A" + alphaNumericExtendedShort("34"))
|
||||||
|
tooBigToken = secrets.NewSecret(numeric("17") + ":A" + alphaNumericExtendedShort("34"))
|
||||||
|
xsdAgencyIdentificationCode1 = secrets.NewSecret(`<xsd:element name="AgencyIdentificationCode" type="clm`+numeric("5")+":AgencyIdentificationCodeContentType") + `"/>`
|
||||||
|
xsdAgencyIdentificationCode2 = secrets.NewSecret(`token:"clm` + numeric("5") + `:AgencyIdentificationCodeContentType"`)
|
||||||
|
xsdAgencyIdentificationCode3 = secrets.NewSecret(`<xsd:element name="AgencyIdentificationCode" type="clm` + numeric("8") + `:AgencyIdentificationCodeContentType"/>`)
|
||||||
|
prefixedToken1 = secrets.NewSecret(`telegram_api_token = \"` + numeric("8") + `:Ahello` + alphaNumericExtendedShort("34") + `\"`)
|
||||||
|
prefixedToken2 = secrets.NewSecret(`telegram_api_token = \"` + numeric("8") + `:A-some-other-thing-` + alphaNumericExtendedShort("34") + `\"`)
|
||||||
|
prefixedToken3 = secrets.NewSecret(`telegram_api_token = \"` + numeric("8") + `:A_` + alphaNumericExtendedShort("34") + `\"`)
|
||||||
|
suffixedToken1 = secrets.NewSecret(`telegram_api_token = \"` + numeric("8") + `:A` + alphaNumericExtendedShort("34") + `hello\"`)
|
||||||
|
suffixedToken2 = secrets.NewSecret(`telegram_api_token = \"` + numeric("8") + `:A` + alphaNumericExtendedShort("34") + `-some-other-thing\"`)
|
||||||
|
suffixedToken3 = secrets.NewSecret(`telegram_api_token = \"` + numeric("8") + `:A_` + alphaNumericExtendedShort("34") + `_\"`)
|
||||||
|
)
|
||||||
fps := []string{
|
fps := []string{
|
||||||
// Token with too small bot_id
|
// Token with too small bot_id
|
||||||
generateSampleSecret("telegram", tooSmallToken),
|
generateSampleSecret("telegram", tooSmallToken),
|
||||||
// Token with too big bot_id
|
// Token with too big bot_id
|
||||||
generateSampleSecret("telegram", tooBigToken),
|
generateSampleSecret("telegram", tooBigToken),
|
||||||
|
// XSD file containing the string AgencyIdentificationCodeContentType
|
||||||
|
generateSampleSecret("telegram", xsdAgencyIdentificationCode1),
|
||||||
|
generateSampleSecret("telegram", xsdAgencyIdentificationCode2),
|
||||||
|
generateSampleSecret("telegram", xsdAgencyIdentificationCode3),
|
||||||
|
// Prefix and suffix variations that shouldn't match
|
||||||
|
generateSampleSecret("telegram", prefixedToken1),
|
||||||
|
generateSampleSecret("telegram", prefixedToken2),
|
||||||
|
generateSampleSecret("telegram", prefixedToken3),
|
||||||
|
generateSampleSecret("telegram", suffixedToken1),
|
||||||
|
generateSampleSecret("telegram", suffixedToken2),
|
||||||
|
generateSampleSecret("telegram", suffixedToken3),
|
||||||
}
|
}
|
||||||
|
|
||||||
return validate(r, tps, fps)
|
return validate(r, tps, fps)
|
||||||
|
|||||||
+19
-2
@@ -2105,6 +2105,7 @@ keywords = [
|
|||||||
id = "hashicorp-tf-password"
|
id = "hashicorp-tf-password"
|
||||||
description = "Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches."
|
description = "Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches."
|
||||||
regex = '''(?i)(?:administrator_login_password|password)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}("[a-z0-9=_\-]{8,20}")(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
regex = '''(?i)(?:administrator_login_password|password)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}("[a-z0-9=_\-]{8,20}")(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||||
|
path = '''\.(tf|hcl)$'''
|
||||||
keywords = [
|
keywords = [
|
||||||
"administrator_login_password","password",
|
"administrator_login_password","password",
|
||||||
]
|
]
|
||||||
@@ -2159,6 +2160,14 @@ keywords = [
|
|||||||
"intercom",
|
"intercom",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
id = "intra42-client-secret"
|
||||||
|
description = "Found a Intra42 client secret, which could lead to unauthorized access to the 42School API and sensitive data."
|
||||||
|
regex = '''(?i)\b(s-s4t2(?:ud|af)-[abcdef0123456789]{64})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||||
|
keywords = [
|
||||||
|
"intra","s-s4t2ud-","s-s4t2af-",
|
||||||
|
]
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "jfrog-api-key"
|
id = "jfrog-api-key"
|
||||||
description = "Found a JFrog API Key, posing a risk of unauthorized access to software artifact repositories and build pipelines."
|
description = "Found a JFrog API Key, posing a risk of unauthorized access to software artifact repositories and build pipelines."
|
||||||
@@ -2359,6 +2368,14 @@ keywords = [
|
|||||||
"nrjs-",
|
"nrjs-",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
id = "new-relic-insert-key"
|
||||||
|
description = "Discovered a New Relic insight insert key, compromising data injection into the platform."
|
||||||
|
regex = '''(?i)(?:new-relic|newrelic|new_relic)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}(NRII-[a-z0-9-]{32})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
|
||||||
|
keywords = [
|
||||||
|
"nrii-",
|
||||||
|
]
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "new-relic-user-api-id"
|
id = "new-relic-user-api-id"
|
||||||
description = "Found a New Relic user API ID, posing a risk to application monitoring services and data integrity."
|
description = "Found a New Relic user API ID, posing a risk to application monitoring services and data integrity."
|
||||||
@@ -2758,9 +2775,9 @@ keywords = [
|
|||||||
[[rules]]
|
[[rules]]
|
||||||
id = "telegram-bot-api-token"
|
id = "telegram-bot-api-token"
|
||||||
description = "Detected a Telegram Bot API Token, risking unauthorized bot operations and message interception on Telegram."
|
description = "Detected a Telegram Bot API Token, risking unauthorized bot operations and message interception on Telegram."
|
||||||
regex = '''(?i)(?:^|[^0-9])([0-9]{5,16}:A[a-zA-Z0-9_\-]{34})(?:$|[^a-zA-Z0-9_\-])'''
|
regex = '''(?i:(?:telegr)(?:[0-9a-z\(-_\t .\\]{0,40})(?:[\s|']|[\s|"]){0,3})(?:=|\|\|:|<=|=>|:|\?=|\()(?:'|\"|\s|=|\x60){0,5}([0-9]{5,16}:A[a-z0-9_\-]{34})(?:['|\"|\n|\r|\s|\x60|;|\\]|$)'''
|
||||||
keywords = [
|
keywords = [
|
||||||
"telegram","api","bot","token","url",
|
"telegr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
|
|||||||
Reference in new issue
Block a user