Make config generation utils public (#1480)

* chore(generate): make utils public

* chore(generate): change validate log messages

* chore(generate): split functions into files

* chore(config): add warning for public funcs
This commit is contained in:
Richard Gomez authored and GitHub committed 2024-08-26 13:11:18 -05:00
1 parent 3be7faa1ff
commit bd81872eee
114 files changed
+862 -713

No files matched your search

+33 -32
View File
@@ -1,6 +1,7 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -21,16 +22,16 @@ func TelegramBotToken() *config.Rule {
// validate
var (
validToken = secrets.NewSecret(numeric("8") + ":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") + `"/>`)
validToken = secrets.NewSecret(utils.Numeric("8") + ":A" + utils.AlphaNumericExtendedShort("34"))
minToken = secrets.NewSecret(utils.Numeric("5") + ":A" + utils.AlphaNumericExtendedShort("34"))
maxToken = secrets.NewSecret(utils.Numeric("16") + ":A" + utils.AlphaNumericExtendedShort("34"))
// xsdWithToken = secrets.NewSecret(`<xsd:element name="AgencyIdentificationCode" type="` + Numeric("5") + `:A` + AlphaNumericExtendedShort("34") + `"/>`)
)
tps := []string{
// variable assignment
generateSampleSecret("telegram", validToken),
utils.GenerateSampleSecret("telegram", validToken),
// 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
`const bot = new Telegraf("` + validToken + `")`,
// .env
@@ -38,43 +39,43 @@ func TelegramBotToken() *config.Rule {
// YAML
`telegram bot: ` + validToken,
// Token with min bot_id
generateSampleSecret("telegram", minToken),
utils.GenerateSampleSecret("telegram", minToken),
// Token with max bot_id
generateSampleSecret("telegram", maxToken),
utils.GenerateSampleSecret("telegram", maxToken),
// Valid token in XSD document TODO separate rule for this
// generateSampleSecret("telegram", xsdWithToken),
// GenerateSampleSecret("telegram", xsdWithToken),
}
var (
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") + `_\"`)
tooSmallToken = secrets.NewSecret(utils.Numeric("4") + ":A" + utils.AlphaNumericExtendedShort("34"))
tooBigToken = secrets.NewSecret(utils.Numeric("17") + ":A" + utils.AlphaNumericExtendedShort("34"))
xsdAgencyIdentificationCode1 = secrets.NewSecret(`<xsd:element name="AgencyIdentificationCode" type="clm`+utils.Numeric("5")+":AgencyIdentificationCodeContentType") + `"/>`
xsdAgencyIdentificationCode2 = secrets.NewSecret(`token:"clm` + utils.Numeric("5") + `:AgencyIdentificationCodeContentType"`)
xsdAgencyIdentificationCode3 = secrets.NewSecret(`<xsd:element name="AgencyIdentificationCode" type="clm` + utils.Numeric("8") + `:AgencyIdentificationCodeContentType"/>`)
prefixedToken1 = secrets.NewSecret(`telegram_api_token = \"` + utils.Numeric("8") + `:Ahello` + utils.AlphaNumericExtendedShort("34") + `\"`)
prefixedToken2 = secrets.NewSecret(`telegram_api_token = \"` + utils.Numeric("8") + `:A-some-other-thing-` + utils.AlphaNumericExtendedShort("34") + `\"`)
prefixedToken3 = secrets.NewSecret(`telegram_api_token = \"` + utils.Numeric("8") + `:A_` + utils.AlphaNumericExtendedShort("34") + `\"`)
suffixedToken1 = secrets.NewSecret(`telegram_api_token = \"` + utils.Numeric("8") + `:A` + utils.AlphaNumericExtendedShort("34") + `hello\"`)
suffixedToken2 = secrets.NewSecret(`telegram_api_token = \"` + utils.Numeric("8") + `:A` + utils.AlphaNumericExtendedShort("34") + `-some-other-thing\"`)
suffixedToken3 = secrets.NewSecret(`telegram_api_token = \"` + utils.Numeric("8") + `:A_` + utils.AlphaNumericExtendedShort("34") + `_\"`)
)
fps := []string{
// Token with too small bot_id
generateSampleSecret("telegram", tooSmallToken),
utils.GenerateSampleSecret("telegram", tooSmallToken),
// Token with too big bot_id
generateSampleSecret("telegram", tooBigToken),
utils.GenerateSampleSecret("telegram", tooBigToken),
// XSD file containing the string AgencyIdentificationCodeContentType
generateSampleSecret("telegram", xsdAgencyIdentificationCode1),
generateSampleSecret("telegram", xsdAgencyIdentificationCode2),
generateSampleSecret("telegram", xsdAgencyIdentificationCode3),
utils.GenerateSampleSecret("telegram", xsdAgencyIdentificationCode1),
utils.GenerateSampleSecret("telegram", xsdAgencyIdentificationCode2),
utils.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),
utils.GenerateSampleSecret("telegram", prefixedToken1),
utils.GenerateSampleSecret("telegram", prefixedToken2),
utils.GenerateSampleSecret("telegram", prefixedToken3),
utils.GenerateSampleSecret("telegram", suffixedToken1),
utils.GenerateSampleSecret("telegram", suffixedToken2),
utils.GenerateSampleSecret("telegram", suffixedToken3),
}
return validate(r, tps, fps)
return utils.Validate(r, tps, fps)
}