Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
[fix] Correctly initialize detectors with cloud endpoint customization (#3333)
Miccah4484bf443b78
diff --git a/pkg/detectors/gitlab/v2/gitlab_v2.go b/pkg/detectors/gitlab/v2/gitlab_v2.goindex f532939a9..19284fdd7 100644--- a/pkg/detectors/gitlab/v2/gitlab_v2.go+++ b/pkg/detectors/gitlab/v2/gitlab_v2.go@@ -23,8 +23,8 @@ var _ detectors.Detector = (*Scanner)(nil)var _ detectors.EndpointCustomizer = (*Scanner)(nil)var _ detectors.Versioner = (*Scanner)(nil)-func (Scanner) Version() int { return 2 }-func (Scanner) DefaultEndpoint() string { return "https://gitlab.com" }+func (Scanner) Version() int { return 2 }+func (Scanner) CloudEndpoint() string { return "https://gitlab.com" }var (defaultClient = common.SaneHttpClient()@@ -77,7 +77,7 @@ func (s Scanner) verifyGitlab(ctx context.Context, resMatch string) (bool, errorif client == nil {client = defaultClient}- for _, baseURL := range s.Endpoints(s.DefaultEndpoint()) {+ for _, baseURL := range s.Endpoints() {// test `read_user` scopereq, err := http.NewRequestWithContext(ctx, "GET", baseURL+"/api/v4/user", nil)if err != nil {diff --git a/pkg/engine/engine.go b/pkg/engine/engine.goindex dc7c61362..289d7acde 100644--- a/pkg/engine/engine.go+++ b/pkg/engine/engine.go@@ -268,6 +268,20 @@ func NewEngine(ctx context.Context, cfg *Config) (*Engine, error) {return nil, err}+ // Abuse filters to initialize endpoint customizer detectors.+ filters = append(filters, func(d detectors.Detector) bool {+ customizer, ok := d.(detectors.EndpointCustomizer)+ if !ok {+ return true+ }+ customizer.UseFoundEndpoints(true)+ customizer.UseCloudEndpoint(true)+ if cloudProvider, ok := d.(detectors.CloudProvider); ok {+ customizer.SetCloudEndpoint(cloudProvider.CloudEndpoint())+ }+ return true+ })+if len(detectorsWithCustomVerifierEndpoints) > 0 {filters = append(filters, func(d detectors.Detector) bool {urls, ok := getWithDetectorID(d, detectorsWithCustomVerifierEndpoints)diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.goindex 9850f4b3d..733d9d861 100644--- a/pkg/engine/engine_test.go+++ b/pkg/engine/engine_test.go@@ -1043,3 +1043,26 @@ func TestEngine_ShouldVerifyChunk(t *testing.T) {}}}++func TestEngineInitializesCloudProviderDetectors(t *testing.T) {+ ctx := context.Background()+ conf := Config{+ Concurrency: 1,+ Detectors: DefaultDetectors(),+ Verify: false,+ SourceManager: sources.NewManager(),+ Dispatcher: NewPrinterDispatcher(new(discardPrinter)),+ }++ e, err := NewEngine(ctx, &conf)+ assert.NoError(t, err)++ for _, det := range e.detectors {+ if endpoints, ok := det.(interface{ Endpoints(...string) []string }); ok {+ id := config.GetDetectorID(det)+ if len(endpoints.Endpoints()) == 0 {+ t.Fatalf("detector %q Endpoints() is empty", id.String())+ }+ }+ }+}