1
1
package secret
2
2
3
3
import (
4
+ "fmt"
5
+
4
6
"github.com/aquasecurity/fanal/types"
5
7
)
6
8
@@ -64,21 +66,32 @@ var (
64
66
CategoryTypeform = types .SecretRuleCategory ("Typeform" )
65
67
)
66
68
69
+ // Reusable regex patterns
70
+ const (
71
+ quote = `["']?`
72
+ connect = `\s*(:|=>|=)\s*`
73
+ startSecret = `(^|\s+)`
74
+ endSecret = `(\s+|$)`
75
+
76
+ aws = `(aws)?_?`
77
+ )
78
+
67
79
var builtinRules = []Rule {
68
80
{
69
- ID : "aws-access-key-id" ,
70
- Category : CategoryAWS ,
71
- Severity : "CRITICAL" ,
72
- Title : "AWS Access Key ID" ,
73
- Regex : MustCompile (`(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}` ),
74
- Keywords : []string {"AKIA" , "AGPA" , "AIDA" , "AROA" , "AIPA" , "ANPA" , "ANVA" , "ASIA" },
81
+ ID : "aws-access-key-id" ,
82
+ Category : CategoryAWS ,
83
+ Severity : "CRITICAL" ,
84
+ Title : "AWS Access Key ID" ,
85
+ Regex : MustCompile (fmt .Sprintf (`(?P<secret>(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16})%s` , endSecret )),
86
+ SecretGroupName : "secret" ,
87
+ Keywords : []string {"AKIA" , "AGPA" , "AIDA" , "AROA" , "AIPA" , "ANPA" , "ANVA" , "ASIA" },
75
88
},
76
89
{
77
90
ID : "aws-secret-access-key" ,
78
91
Category : CategoryAWS ,
79
92
Severity : "CRITICAL" ,
80
93
Title : "AWS Secret Access Key" ,
81
- Regex : MustCompile (`(?i)["']?(aws)?_?( secret)?_?(access)?_?key["']?\s*(:|=>|=)\s* (?P<secret>["']?[ A-Za-z0-9\/\+=]{40})["']?` ),
94
+ 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 ) ),
82
95
SecretGroupName : "secret" ,
83
96
Keywords : []string {"key" },
84
97
},
@@ -87,7 +100,7 @@ var builtinRules = []Rule{
87
100
Category : CategoryAWS ,
88
101
Severity : "HIGH" ,
89
102
Title : "AWS Account ID" ,
90
- Regex : MustCompile (`(?i)["']?(aws)?_?account_?( id)?["']?\s*(:|=>|=)\s*['"]? (?P<secret>[0-9]{4}\-?[0-9]{4}\-?[0-9]{4})['"]?` ),
103
+ Regex : MustCompile (fmt . Sprintf ( `(?i)%s%s%saccount_?( id)?%s%s%s (?P<secret>[0-9]{4}\-?[0-9]{4}\-?[0-9]{4})%s%s` , startSecret , quote , aws , quote , connect , quote , quote , endSecret ) ),
91
104
SecretGroupName : "secret" ,
92
105
Keywords : []string {"account" },
93
106
},
0 commit comments