Skip to content

Commit 18b16b0

Browse files
authored
feat(engine): make |detectionTimeout| configurable (#3768)
This partially fixes #2991. The default timeout of 10s is wholly inadequate and leads to a high rate of false negatives. I say "partially" because the MongoDB detector has a separate hard-coded timeout. It was bumped slightly in #3620 but ought to be higher.
1 parent 17a9eb0 commit 18b16b0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var (
6868
fail = cli.Flag("fail", "Exit with code 183 if results are found.").Bool()
6969
verifiers = cli.Flag("verifier", "Set custom verification endpoints.").StringMap()
7070
customVerifiersOnly = cli.Flag("custom-verifiers-only", "Only use custom verification endpoints.").Bool()
71+
detectorTimeout = cli.Flag("detector-timeout", "Maximum time to spend scanning chunks per detector (e.g., 30s).").Duration()
7172
archiveMaxSize = cli.Flag("archive-max-size", "Maximum size of archive to scan. (Byte units eg. 512B, 2KB, 4MB)").Bytes()
7273
archiveMaxDepth = cli.Flag("archive-max-depth", "Maximum depth of archive to scan.").Int()
7374
archiveTimeout = cli.Flag("archive-timeout", "Maximum time to spend extracting an archive.").Duration()
@@ -439,6 +440,9 @@ func run(state overseer.State) {
439440
}
440441
}
441442

443+
if *detectorTimeout != 0 {
444+
engine.SetDetectorTimeout(*detectorTimeout)
445+
}
442446
if *archiveMaxSize != 0 {
443447
handlers.SetArchiveMaxSize(int(*archiveMaxSize))
444448
}

pkg/engine/engine.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
3131
)
3232

33-
const detectionTimeout = 10 * time.Second
33+
var detectionTimeout = 10 * time.Second
3434

3535
var errOverlap = errors.New(
3636
"More than one detector has found this result. For your safety, verification has been disabled." +
@@ -316,6 +316,9 @@ func NewEngine(ctx context.Context, cfg *Config) (*Engine, error) {
316316
return engine, nil
317317
}
318318

319+
// SetDetectorTimeout sets the maximum timeout for each detector to scan a chunk.
320+
func SetDetectorTimeout(timeout time.Duration) { detectionTimeout = timeout }
321+
319322
// setDefaults ensures that if specific engine properties aren't provided,
320323
// they're set to reasonable default values. It makes the engine robust to
321324
// incomplete configuration.

0 commit comments

Comments
 (0)