Skip to content

Commit

Permalink
Fix: update the regex for secrets scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
jyothikumar authored and behara committed Sep 30, 2022
1 parent 4ffe746 commit e4cb7ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// To make sure SecretAnalyzer implements analyzer.Initializer
var _ analyzer.Initializer = &SecretAnalyzer{}

const version = 1
const version = 2

var (
skipFiles = []string{
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/secret/builtin-rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var builtinRules = []Rule{
Category: CategoryAsymmetricPrivateKey,
Title: "Asymmetric Private Key",
Severity: "HIGH",
Regex: MustCompile(`(?i)-----\s*?BEGIN[ A-Z0-9_-]*?PRIVATE KEY( BLOCK)?\s*?-----[\s]*?(?P<secret>[A-Za-z0-9=+/\\\r\n]+)[\s]*?-----\s*?END[ A-Z0-9_-]*? PRIVATE KEY( BLOCK)?\s*?-----`),
Regex: MustCompile(`(?i)-----\s*?BEGIN[ A-Z0-9_-]*?PRIVATE KEY( BLOCK)?\s*?-----[\s]*?(?P<secret>[ A-Za-z0-9=+/\\\r\n]+)[\s]*?-----\s*?END[ A-Z0-9_-]*? PRIVATE KEY( BLOCK)?\s*?-----`),
SecretGroupName: "secret",
Keywords: []string{"-----"},
},
Expand Down
30 changes: 30 additions & 0 deletions pkg/fanal/secret/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,27 @@ func TestSecretScanner(t *testing.T) {
},
},
}
wantFindingAsymmSecretKey := types.SecretFinding{
RuleID: "private-key",
Category: secret.CategoryAsymmetricPrivateKey,
Title: "Asymmetric Private Key",
Severity: "HIGH",
StartLine: 1,
EndLine: 1,
Match: "----BEGIN RSA PRIVATE KEY-----**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************-----END RSA PRIVATE",
Code: types.Code{
Lines: []types.Line{
{
Number: 1,
Content: "-----BEGIN RSA PRIVATE KEY-----**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************-----END RSA PRIVATE KEY-----",
Highlighted: "-----BEGIN RSA PRIVATE KEY-----**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************-----END RSA PRIVATE KEY-----",
IsCause: true,
FirstCause: true,
LastCause: true,
},
},
},
}

tests := []struct {
name string
Expand Down Expand Up @@ -674,6 +695,15 @@ func TestSecretScanner(t *testing.T) {
inputFilePath: "testdata/invalid-aws-secrets.txt",
want: types.Secret{},
},
{
name: "asymmetric file",
configPath: "",
inputFilePath: "testdata/asymmetric-private-key.txt",
want: types.Secret{
FilePath: "testdata/asymmetric-private-key.txt",
Findings: []types.SecretFinding{wantFindingAsymmSecretKey},
},
},
}

for _, tt := range tests {
Expand Down
4 changes: 4 additions & 0 deletions pkg/fanal/secret/testdata/asymmetric-private-key.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAu/Nua0/1y08gkbnBfKd6VDHia8Na0ATgMQqZ4YEbi/t73g84IEPQPkLbPF3X De++JA1QzqTZbbePLsW44DbbgMX/5jj+Sh2SvGe5IXNeNwyyMox+DKQccJUPxbCxnhF/gSnF76cM BXJC63nDnG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