Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
[SCAN-1018] Treat SlackWebhook invalid_token (HTTP 400) as determinate not-live (#5177)
Drew LaFiandra7d8f10c04d80
diff --git a/pkg/detectors/slackwebhook/slackwebhook.go b/pkg/detectors/slackwebhook/slackwebhook.goindex 1f5800d8a..3f1925155 100644--- a/pkg/detectors/slackwebhook/slackwebhook.go+++ b/pkg/detectors/slackwebhook/slackwebhook.go@@ -88,6 +88,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results1.Verified = truecase res.StatusCode == http.StatusBadRequest && bytes.Equal(bodyBytes, []byte("invalid_payload")):s1.Verified = true+ case res.StatusCode == http.StatusBadRequest && bytes.Contains(bodyBytes, []byte("invalid_token")):+ // Slack may return the bare error code or embed it in a longer body, hence Contains not Equal.+ // Revoked webhook / gone workspace or channel is determinate verified=false.case res.StatusCode == http.StatusNotFound || res.StatusCode == http.StatusForbidden:// Not a real webhook or the owning app's OAuth token has been revoked or the app has been deleted// You might want to handle this case or log it.diff --git a/pkg/detectors/slackwebhook/slackwebhook_test.go b/pkg/detectors/slackwebhook/slackwebhook_test.goindex 1a63f0c86..5bbbded1c 100644--- a/pkg/detectors/slackwebhook/slackwebhook_test.go+++ b/pkg/detectors/slackwebhook/slackwebhook_test.go@@ -2,10 +2,12 @@ package slackwebhookimport ("context"+ "net/http""testing""github.com/google/go-cmp/cmp"+ "github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/engine/ahocorasick")@@ -78,3 +80,61 @@ func TestSlackWebHook_Pattern(t *testing.T) {})}}++func TestSlackWebhook_InvalidTokenVerification(t *testing.T) {+ tests := []struct {+ name string+ statusCode int+ body string+ wantVerified bool+ wantVerificationErr bool+ }{+ {+ name: "invalid_token is determinate not-live",+ statusCode: http.StatusBadRequest,+ body: "invalid_token",+ wantVerified: false,+ wantVerificationErr: false,+ },+ {+ name: "invalid_token substring is determinate not-live",+ statusCode: http.StatusBadRequest,+ body: "error: invalid_token for webhook",+ wantVerified: false,+ wantVerificationErr: false,+ },+ {+ name: "unexpected 400 remains indeterminate",+ statusCode: http.StatusBadRequest,+ body: "something_else",+ wantVerified: false,+ wantVerificationErr: true,+ },+ {+ name: "invalid_payload is verified",+ statusCode: http.StatusBadRequest,+ body: "invalid_payload",+ wantVerified: true,+ wantVerificationErr: false,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ s := Scanner{client: common.ConstantResponseHttpClient(tt.statusCode, tt.body)}+ got, err := s.FromData(context.Background(), true, []byte(validPattern))+ if err != nil {+ t.Fatalf("FromData error: %v", err)+ }+ if len(got) != 1 {+ t.Fatalf("expected 1 result, got %d", len(got))+ }+ if got[0].Verified != tt.wantVerified {+ t.Errorf("Verified = %v, want %v", got[0].Verified, tt.wantVerified)+ }+ if (got[0].VerificationError() != nil) != tt.wantVerificationErr {+ t.Errorf("VerificationError = %v, wantVerificationErr %v", got[0].VerificationError(), tt.wantVerificationErr)+ }+ })+ }+}