Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(secret): add sec and space to secret prefix for aws-secret-access-key #5647

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"