From bf8a49fc29cfc697fdc5c342fc6b96b909fc7934 Mon Sep 17 00:00:00 2001 From: bplaxco Date: Thu, 3 Oct 2024 10:50:15 -0400 Subject: [PATCH] Make private key check less greedy and include fifth dash (#1440) * Make private key check less greedy and include fifth dash * Remove trailing space --- cmd/generate/config/rules/privatekey.go | 2 +- config/gitleaks.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/generate/config/rules/privatekey.go b/cmd/generate/config/rules/privatekey.go index 55e4245a..ad6a5577 100644 --- a/cmd/generate/config/rules/privatekey.go +++ b/cmd/generate/config/rules/privatekey.go @@ -12,7 +12,7 @@ func PrivateKey() *config.Rule { r := config.Rule{ Description: "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.", RuleID: "private-key", - Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*KEY(?: BLOCK)?----`), + Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*?KEY(?: BLOCK)?-----`), Keywords: []string{"-----BEGIN"}, } diff --git a/config/gitleaks.toml b/config/gitleaks.toml index 9c16f8b3..290a9a0e 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -2544,7 +2544,7 @@ keywords = [ [[rules]] id = "private-key" description = "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption." -regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*KEY(?: BLOCK)?----''' +regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*?KEY(?: BLOCK)?-----''' keywords = [ "-----begin", ]