Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Report indeterminacy in AWS verifier (#1480)
Cody Roseb803a0f7017c
diff --git a/pkg/detectors/aws/aws.go b/pkg/detectors/aws/aws.goindex 88f4a53ed..b8565645c 100644--- a/pkg/detectors/aws/aws.go+++ b/pkg/detectors/aws/aws.go@@ -191,7 +191,11 @@ func (s scanner) FromData(ctx context.Context, verify bool, data []byte) (resultif detectors.IsKnownFalsePositive(resSecretMatch, detectors.DefaultFalsePositives, true) {continue}++ s1.VerificationError = fmt.Errorf("request to %v returned unexpected status %d", res.Request.URL, res.StatusCode)}+ } else {+ s1.VerificationError = err}}diff --git a/pkg/detectors/aws/aws_test.go b/pkg/detectors/aws/aws_test.goindex 3628a9f58..1dfecccd3 100644--- a/pkg/detectors/aws/aws_test.go+++ b/pkg/detectors/aws/aws_test.go@@ -38,11 +38,12 @@ func TestAWS_FromChunk(t *testing.T) {verify bool}tests := []struct {- name string- s scanner- args args- want []detectors.Result- wantErr bool+ name string+ s scanner+ args args+ want []detectors.Result+ wantErr bool+ wantVerificationError bool}{{name: "found, verified",@@ -191,6 +192,24 @@ func TestAWS_FromChunk(t *testing.T) {},wantErr: false,},+ {+ name: "found, would be verified if not for http timeout",+ s: scanner{},+ args: args{+ ctx: timeoutContext(1 * time.Microsecond),+ data: []byte(fmt.Sprintf("You can find a aws secret %s within aws %s", secret, id)),+ verify: true,+ },+ want: []detectors.Result{+ {+ DetectorType: detectorspb.DetectorType_AWS,+ Verified: false,+ Redacted: "AKIASP2TPHJSQH3FJRUX",+ },+ },+ wantErr: false,+ wantVerificationError: true,+ },}for _, tt := range tests {t.Run(tt.name, func(t *testing.T) {@@ -204,8 +223,11 @@ func TestAWS_FromChunk(t *testing.T) {if len(got[i].Raw) == 0 {t.Fatalf("no raw secret present: \n %+v", got[i])}+ if (got[i].VerificationError != nil) != tt.wantVerificationError {+ t.Fatalf("verification error = %v, wantVerificationError %v", got[i].VerificationError, tt.wantVerificationError)+ }}- ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "RawV2", "Raw")+ ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "RawV2", "Raw", "VerificationError")if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" {t.Errorf("AWS.FromData() %s diff: (-got +want)\n%s", tt.name, diff)}@@ -227,3 +249,8 @@ func BenchmarkFromData(benchmark *testing.B) {})}}++func timeoutContext(timeout time.Duration) context.Context {+ c, _ := context.WithTimeout(context.Background(), timeout)+ return c+}diff --git a/pkg/pb/detectorspb/detectors.pb.go b/pkg/pb/detectorspb/detectors.pb.goindex 9b42f9dd3..158cfa7ff 100644--- a/pkg/pb/detectorspb/detectors.pb.go+++ b/pkg/pb/detectorspb/detectors.pb.go@@ -2877,9 +2877,7 @@ type Result struct {HashV2 string `protobuf:"bytes,8,opt,name=hash_v2,json=hashV2,proto3" json:"hash_v2,omitempty"`DecoderType DecoderType `protobuf:"varint,9,opt,name=decoder_type,json=decoderType,proto3,enum=detectors.DecoderType" json:"decoder_type,omitempty"`// This field should only be populated if the verification process itself failed in a way that provides no information- // about the verification status of the candidate secret. This is because if this field is set, the application will- // ignore the contents of the `verified` field. An example of such a situation is a verification request that timed- // out.+ // about the verification status of the candidate secret, such as if the verification request timed out.VerificationErrorMessage string `protobuf:"bytes,10,opt,name=verification_error_message,json=verificationErrorMessage,proto3" json:"verification_error_message,omitempty"`}