From e002920355ac91770a329cfa69d6359bd665ba66 Mon Sep 17 00:00:00 2001 From: very-doge-wow <95224950+very-doge-wow@users.noreply.github.com> Date: Thu, 12 Jan 2023 15:38:48 +0100 Subject: [PATCH] Fix rule for private keys (#1072) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: fix rule for private keys Wouldn't match old keys which have been created with the BLOCK statement at the beginning and end of the key. * fix: rule for private keys * fix: missing comma Co-authored-by: Fabian F Groß --- cmd/generate/config/rules/privatekey.go | 5 ++++- config/gitleaks.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/generate/config/rules/privatekey.go b/cmd/generate/config/rules/privatekey.go index 9ca2a995..15985857 100644 --- a/cmd/generate/config/rules/privatekey.go +++ b/cmd/generate/config/rules/privatekey.go @@ -11,7 +11,7 @@ func PrivateKey() *config.Rule { r := config.Rule{ Description: "Private Key", RuleID: "private-key", - Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----`), + Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----`), Keywords: []string{"-----BEGIN"}, } @@ -23,6 +23,9 @@ anything abcdefghijklmnopqrstuvwxyz -----END RSA PRIVATE KEY----- `, + `-----BEGIN PRIVATE KEY BLOCK----- +anything +-----END PRIVATE KEY BLOCK-----`, } // gitleaks:allow return validate(r, tps, nil) } diff --git a/config/gitleaks.toml b/config/gitleaks.toml index bd67318c..7a7f00da 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -2411,7 +2411,7 @@ keywords = [ [[rules]] description = "Private Key" id = "private-key" -regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----''' +regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----''' keywords = [ "-----begin", ]