mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 12:14:22 +01:00
* 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ß <fabian.f.gross@deutschebahn.com>
29 lines
609 B
Go
29 lines
609 B
Go
package rules
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/zricethezav/gitleaks/v8/config"
|
|
)
|
|
|
|
func PrivateKey() *config.Rule {
|
|
// define 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----`),
|
|
Keywords: []string{"-----BEGIN"},
|
|
}
|
|
|
|
// validate
|
|
tps := []string{`-----BEGIN PRIVATE KEY-----
|
|
anything
|
|
-----END PRIVATE KEY-----`,
|
|
`-----BEGIN RSA PRIVATE KEY-----
|
|
abcdefghijklmnopqrstuvwxyz
|
|
-----END RSA PRIVATE KEY-----
|
|
`,
|
|
} // gitleaks:allow
|
|
return validate(r, tps, nil)
|
|
}
|