Skip to content

Commit 8826e36

Browse files
AWS detector should detect with leading '+' (#698)
1 parent dfb7e9a commit 8826e36

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

pkg/detectors/aws/aws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2828
// Key types are from this list https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-unique-ids
2929
idPat = regexp.MustCompile(`\b((?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16})\b`)
30-
secretPat = regexp.MustCompile(`\b([A-Za-z0-9+/]{40})[ \r\n'"\x60]`)
30+
secretPat = regexp.MustCompile(`[^A-Za-z0-9+\/]{0,1}([A-Za-z0-9+\/]{40})[^A-Za-z0-9+\/]{0,1}`)
3131
// Hashes, like those for git, do technically match the secret pattern.
3232
// But they are extremely unlikely to be generated as an actual AWS secret.
3333
// So when we find them, if they're not verified, we should ignore the result.

pkg/detectors/aws/aws_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ func TestAWS_FromChunk(t *testing.T) {
144144
},
145145
wantErr: false,
146146
},
147+
{
148+
name: "found, unverified, with leading +",
149+
s: Scanner{},
150+
args: args{
151+
ctx: context.Background(),
152+
data: []byte(fmt.Sprintf("You can find a aws secret %s within aws %s but not valid", "+HaNv9cTwheDKGJaws/+BMF2GgybQgBWdhcOOdfF", id)), // the secret would satisfy the regex but not pass validation
153+
verify: true,
154+
},
155+
want: []detectors.Result{
156+
{
157+
DetectorType: detectorspb.DetectorType_AWS,
158+
Verified: false,
159+
Redacted: "AKIAWARWQKZNHMZBLY4I",
160+
},
161+
},
162+
wantErr: false,
163+
},
147164
}
148165
for _, tt := range tests {
149166
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)