Skip to content

Commit

Permalink
Fix rule for private keys (gitleaks#1072)
Browse files Browse the repository at this point in the history
* 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ß <fabian.f.gross@deutschebahn.com>
  • Loading branch information
very-doge-wow and Fabian F Groß authored Jan 12, 2023
1 parent d805fb9 commit e002920
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cmd/generate/config/rules/privatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}

Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion config/gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down

0 comments on commit e002920

Please sign in to comment.