From c8681e4858008b9875aec68fb55f7463962cd16a Mon Sep 17 00:00:00 2001 From: very-doge-wow <95224950+very-doge-wow@users.noreply.github.com> Date: Mon, 5 Sep 2022 17:18:44 +0200 Subject: [PATCH] refactor: more precise rule for private keys (#930) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: more precise rule for private keys The current regex didn't match PGP private keys anymore, since they start with `BEGIN PGP PRIVATE KEY BLOCK` and the `BLOCK` never matched for the existing regex. I've made that part optional so that all strings matching for the current regex will still match for the new regex. * refactor: more precise rule for private keys Co-authored-by: Fabian F Groß --- 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 3897fb9e..9ca2a995 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-----[\s\S-]*KEY----`), + Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----`), Keywords: []string{"-----BEGIN"}, } diff --git a/config/gitleaks.toml b/config/gitleaks.toml index c8af8fa1..3e1b17bc 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -2365,7 +2365,7 @@ keywords = [ [[rules]] description = "Private Key" id = "private-key" -regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY-----[\s\S-]*KEY----''' +regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY----''' keywords = [ "-----begin", ]