Fix enumeration config initialization and add test script

- Fix SetEnumerationConfig to create detector if not exists
  Previously, the config would be silently discarded if called before
  the detector was lazily initialized by GetEnumerationDetector

- Add test_enumeration.py script for sandbox testing
  Includes fire-and-forget mode (--no-wait) for proper scanner simulation
This commit is contained in:
Ryan Malloy 2025-12-07 15:39:30 -07:00
parent c73fa9d3d1
commit 95a794ba69
2 changed files with 162 additions and 6 deletions

View file

@ -99,17 +99,26 @@ func GetEnumerationDetector(logger *zap.Logger) *EnumerationDetector {
}
// SetEnumerationConfig updates the global detector configuration
// If the detector doesn't exist yet, it creates one with the given config
func SetEnumerationConfig(config EnumerationConfig) {
enumDetectorMu.Lock()
defer enumDetectorMu.Unlock()
if globalEnumDetector != nil {
globalEnumDetector.config = config
// Rebuild exempt set
globalEnumDetector.exemptSet = make(map[string]bool)
for _, ext := range config.ExemptExtensions {
globalEnumDetector.exemptSet[ext] = true
if globalEnumDetector == nil {
// Create detector with the provided config
globalEnumDetector = &EnumerationDetector{
config: config,
tracker: make(map[string]*ExtensionAttempts),
logger: zap.NewNop(), // Will be replaced on first use
}
} else {
globalEnumDetector.config = config
}
// Rebuild exempt set
globalEnumDetector.exemptSet = make(map[string]bool)
for _, ext := range config.ExemptExtensions {
globalEnumDetector.exemptSet[ext] = true
}
}