Skip to content

Commit

Permalink
fix(secret): add sec and space to secret prefix for `aws-secret-acc…
Browse files Browse the repository at this point in the history
…ess-key` (#5647)
  • Loading branch information
DmitriyLewen authored Nov 26, 2023
1 parent ad977a4 commit 8ff574e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/fanal/secret/builtin-rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var (
// Reusable regex patterns
const (
quote = `["']?`
connect = `\s*(:|=>|=)\s*`
connect = `\s*(:|=>|=)?\s*`
startSecret = `(^|\s+)`
endSecret = `(\s+|$)`

Expand Down Expand Up @@ -105,7 +105,7 @@ var builtinRules = []Rule{
Category: CategoryAWS,
Severity: "CRITICAL",
Title: "AWS Secret Access Key",
Regex: MustCompile(fmt.Sprintf(`(?i)%s%s%s(secret)?_?(access)?_?key%s%s%s(?P<secret>[A-Za-z0-9\/\+=]{40})%s%s`, startSecret, quote, aws, quote, connect, quote, quote, endSecret)),
Regex: MustCompile(fmt.Sprintf(`(?i)%s%s%s(sec(ret)?)?_?(access)?_?key%s%s%s(?P<secret>[A-Za-z0-9\/\+=]{40})%s%s`, startSecret, quote, aws, quote, connect, quote, quote, endSecret)),
SecretGroupName: "secret",
Keywords: []string{"key"},
},
Expand Down
33 changes: 32 additions & 1 deletion pkg/fanal/secret/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,37 @@ func TestSecretScanner(t *testing.T) {
},
},
}
wantFinding10 := types.SecretFinding{
RuleID: "aws-secret-access-key",
Category: secret.CategoryAWS,
Title: "AWS Secret Access Key",
Severity: "CRITICAL",
StartLine: 5,
EndLine: 5,
Match: `aws_sec_key "****************************************"`,
Code: types.Code{
Lines: []types.Line{
{
Number: 3,
Content: "\"aws_account_ID\":'1234-5678-9123'",
Highlighted: "\"aws_account_ID\":'1234-5678-9123'",
},
{
Number: 4,
Content: "AWS_example=AKIAIOSFODNN7EXAMPLE",
Highlighted: "AWS_example=AKIAIOSFODNN7EXAMPLE",
},
{
Number: 5,
Content: "aws_sec_key \"****************************************\"",
Highlighted: "aws_sec_key \"****************************************\"",
IsCause: true,
FirstCause: true,
LastCause: true,
},
},
},
}
wantFindingAsymmetricPrivateKeyJson := types.SecretFinding{
RuleID: "private-key",
Category: secret.CategoryAsymmetricPrivateKey,
Expand Down Expand Up @@ -548,7 +579,7 @@ func TestSecretScanner(t *testing.T) {
inputFilePath: filepath.Join("testdata", "aws-secrets.txt"),
want: types.Secret{
FilePath: filepath.Join("testdata", "aws-secrets.txt"),
Findings: []types.SecretFinding{wantFinding5, wantFinding9},
Findings: []types.SecretFinding{wantFinding5, wantFinding9, wantFinding10},
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion pkg/fanal/secret/testdata/aws-secrets.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'AWS_secret_KEY'="12ASD34qwe56CXZ78tyH10Tna543VBokN85RHCas"
AWS_ACCESS_KEY_ID=AKIA0123456789ABCDEF
"aws_account_ID":'1234-5678-9123'
AWS_example=AKIAIOSFODNN7EXAMPLE
AWS_example=AKIAIOSFODNN7EXAMPLE
aws_sec_key "KEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYK"

0 comments on commit 8ff574e

Please sign in to comment.