From 81f00028458bbfa0827ebd3013a7ae4e238311ef Mon Sep 17 00:00:00 2001 From: Ben-grmbl <173737458+Ben-grmbl@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:49:06 +0100 Subject: [PATCH] fix(vault-service-token): ensure that TPS contains digits (#1614) * fix(vault-service-token): ensure that TPS contains digits Chances of randomly generating a 24 letter string without digits: P = ( (26+26) / (26+26+10) ) ^ 24 = 1.46 % * fixt --------- Co-authored-by: Zachary Rice Co-authored-by: Zachary Rice --- cmd/generate/config/rules/hashicorp_vault.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cmd/generate/config/rules/hashicorp_vault.go b/cmd/generate/config/rules/hashicorp_vault.go index 07c2653f..881f6763 100644 --- a/cmd/generate/config/rules/hashicorp_vault.go +++ b/cmd/generate/config/rules/hashicorp_vault.go @@ -1,10 +1,11 @@ package rules import ( + "regexp" + "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 { @@ -26,16 +27,14 @@ func VaultServiceToken() *config.Rule { } // validate - // Old - tps := utils.GenerateSampleSecrets("vault", "s."+secrets.NewSecret(`s\.[a-zA-Z0-9]{24}`)) - tps = append(tps, + tps := []string{ + // Old + utils.GenerateSampleSecret("vault", secrets.NewSecret(`s\.[0-9][a-zA-Z0-9]{23}`)), `token: s.ZC9Ecf4M5g9o34Q6RkzGsj0z`, - ) - // New - tps = append(tps, utils.GenerateSampleSecrets("vault", secrets.NewSecret(`hvs\.[\w\-]{90}`))...) - tps = append(tps, + // New + utils.GenerateSampleSecret("vault", secrets.NewSecret(`hvs\.[0-9][\w\-]{89}`)), `-vaultToken hvs.CAESIP2jTxc9S2K7Z6CtcFWQv7-044m_oSsxnPE1H3nF89l3GiYKHGh2cy5sQmlIZVNyTWJNcDRsYWJpQjlhYjVlb1cQh6PL8wEYAg"`, // longer than 100 chars - ) + } fps := []string{ // Old