Skip to content

Find, verify, and analyze leaked credentials

[chore] Log possible duplicate detectors (#1266)

Miccahdfc5a9f5db08
diff --git a/pkg/config/detectors.go b/pkg/config/detectors.go
index 6ee31c61b..8fc9f71ee 100644
--- a/pkg/config/detectors.go
+++ b/pkg/config/detectors.go
@@ -6,6 +6,7 @@ import (
"strconv"
"strings"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
dpb "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
)
@@ -36,6 +37,17 @@ type DetectorID struct {
Version int
}
+func GetDetectorID(d detectors.Detector) DetectorID {
+ var version int
+ if v, ok := d.(detectors.Versioner); ok {
+ version = v.Version()
+ }
+ return DetectorID{
+ ID: d.Type(),
+ Version: version,
+ }
+}
+
// ParseDetectors parses user supplied string into a list of detectors types.
// "all" will return the list of all available detectors. The input is comma
// separated and may use the case-insensitive detector name defined in the
diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go
index 1603a01f4..99cabf131 100644
--- a/pkg/engine/engine.go
+++ b/pkg/engine/engine.go
@@ -13,6 +13,7 @@ import (
"google.golang.org/protobuf/proto"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/config"
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/decoders"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -149,13 +150,28 @@ func Start(ctx context.Context, options ...EngineOption) *Engine {
})
e.prefilter = builder.Build(keywords)
- ctx.Logger().V(2).Info("loaded decoders", "count", len(e.decoders))
- ctx.Logger().V(2).Info("loaded detectors",
+ ctx.Logger().Info("loaded decoders", "count", len(e.decoders))
+ ctx.Logger().Info("loaded detectors",
"total", len(e.detectors[true])+len(e.detectors[false]),
"verification_enabled", len(e.detectors[true]),
"verification_disabled", len(e.detectors[false]),
)
+ // Sanity check detectors for duplicate configuration. Only log in case
+ // a detector has been configured in a way that isn't represented by
+ // the DetectorID (type and version).
+ {
+ dets := append(e.detectors[true], e.detectors[false]...)
+ seenDetectors := make(map[config.DetectorID]struct{}, len(dets))
+ for _, det := range dets {
+ id := config.GetDetectorID(det)
+ if _, ok := seenDetectors[id]; ok {
+ ctx.Logger().Info("possible duplicate detector configured", "detector", id)
+ }
+ seenDetectors[id] = struct{}{}
+ }
+ }
+
// Start the workers.
for i := 0; i < e.concurrency; i++ {
e.workersWg.Add(1)