High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(idpi): expose scanTimeoutSec in IDPIConfig
Djain912da934020b3c3
diff --git a/internal/config/config.go b/internal/config/config.goindex 11156ee1..015fa785 100644--- a/internal/config/config.go+++ b/internal/config/config.go@@ -207,6 +207,12 @@ type IDPIConfig struct {// CustomPatterns is a user-extensible list of additional injection-detection// phrases. Matched case-insensitively, same as the built-in patterns.CustomPatterns []string `json:"customPatterns,omitempty"`++ // ScanTimeoutSec is the maximum number of seconds the CDP page-text fetch+ // (body.innerText) may take during content scanning. Capped to prevent the+ // IDPI scan from consuming the full action-timeout budget.+ // Defaults to 5. A value ≤ 0 is treated as the default.+ ScanTimeoutSec int `json:"scanTimeoutSec,omitempty"`}var defaultLocalAllowedDomains = []string{"127.0.0.1", "localhost", "::1"}@@ -531,6 +537,7 @@ func Load() *RuntimeConfig {StrictMode: true,ScanContent: true,WrapContent: true,+ ScanTimeoutSec: 5,},}finalizeProfileConfig(cfg)@@ -794,6 +801,7 @@ func DefaultFileConfig() FileConfig {StrictMode: true,ScanContent: true,WrapContent: true,+ ScanTimeoutSec: 5,},},Profiles: ProfilesConfig{diff --git a/internal/config/validate.go b/internal/config/validate.goindex c1a63121..f4541e9b 100644--- a/internal/config/validate.go+++ b/internal/config/validate.go@@ -273,6 +273,13 @@ func validateIDPIConfig(cfg IDPIConfig) []error {}}+ if cfg.ScanTimeoutSec < 0 {+ errs = append(errs, ValidationError{+ Field: "security.idpi.scanTimeoutSec",+ Message: "scanTimeoutSec must not be negative",+ })+ }+return errs}diff --git a/internal/config/validate_test.go b/internal/config/validate_test.goindex 84d8ae02..40cc78f1 100644--- a/internal/config/validate_test.go+++ b/internal/config/validate_test.go@@ -457,3 +457,40 @@ func TestValidateFileConfig_IDPIPassthrough(t *testing.T) {t.Errorf("expected at least 2 IDPI errors via ValidateFileConfig, got %d: %v", len(errs), errs)}}++// TestValidateIDPIConfig_ScanTimeoutSec verifies that negative values are rejected+// and zero/positive values are accepted (zero means use the default).+func TestValidateIDPIConfig_ScanTimeoutSec(t *testing.T) {+ t.Run("NegativeIsInvalid", func(t *testing.T) {+ errs := validateIDPIConfig(IDPIConfig{+ Enabled: true,+ ScanTimeoutSec: -1,+ })+ if len(errs) == 0 {+ t.Error("expected error for negative scanTimeoutSec, got none")+ }+ if len(errs) > 0 && !strings.Contains(errs[0].Error(), "scanTimeoutSec") {+ t.Errorf("expected scanTimeoutSec field in error, got: %v", errs[0])+ }+ })++ t.Run("ZeroIsValid", func(t *testing.T) {+ errs := validateIDPIConfig(IDPIConfig{+ Enabled: true,+ ScanTimeoutSec: 0, // zero → use built-in default of 5s+ })+ if len(errs) != 0 {+ t.Errorf("expected no error for scanTimeoutSec=0, got: %v", errs)+ }+ })++ t.Run("PositiveIsValid", func(t *testing.T) {+ errs := validateIDPIConfig(IDPIConfig{+ Enabled: true,+ ScanTimeoutSec: 10,+ })+ if len(errs) != 0 {+ t.Errorf("expected no error for scanTimeoutSec=10, got: %v", errs)+ }+ })+}diff --git a/internal/handlers/find.go b/internal/handlers/find.goindex 3af868a4..47dd832b 100644--- a/internal/handlers/find.go+++ b/internal/handlers/find.go@@ -135,8 +135,12 @@ func (h *Handlers) HandleFind(w http.ResponseWriter, r *http.Request) {}// Augment with full body text to catch injection in non-interactive// content that the interactive AX filter omits (paragraphs, headings).+ scanTimeout := time.Duration(h.Config.IDPI.ScanTimeoutSec) * time.Second+ if scanTimeout <= 0 {+ scanTimeout = 5 * time.Second+ }var bodyText string- scanCtx, scanCancel := context.WithTimeout(ctxTab, 3*time.Second)+ scanCtx, scanCancel := context.WithTimeout(ctxTab, scanTimeout)_ = chromedp.Run(scanCtx, chromedp.Evaluate(`document.body ? document.body.innerText : ""`, &bodyText))scanCancel()sb.WriteString(bodyText)diff --git a/internal/handlers/pdf.go b/internal/handlers/pdf.goindex 03164e7c..494966f0 100644--- a/internal/handlers/pdf.go+++ b/internal/handlers/pdf.go@@ -125,11 +125,15 @@ func (h *Handlers) HandlePDF(w http.ResponseWriter, r *http.Request) {// IDPI: scan page title, URL, and body text for injection patterns before// rendering to PDF. PDF output is opaque binary — any signal is conveyed- // via response headers. A 5-second sub-deadline prevents the scan from- // consuming the full action timeout budget.+ // via response headers. The scan timeout is taken from IDPI config so+ // operators can tune it without recompiling.if h.Config.IDPI.Enabled && h.Config.IDPI.ScanContent {+ scanTimeout := time.Duration(h.Config.IDPI.ScanTimeoutSec) * time.Second+ if scanTimeout <= 0 {+ scanTimeout = 5 * time.Second+ }var pageTitle, pageURL, pageText string- scanCtx, scanCancel := context.WithTimeout(tCtx, 5*time.Second)+ scanCtx, scanCancel := context.WithTimeout(tCtx, scanTimeout)defer scanCancel()_ = chromedp.Run(scanCtx,chromedp.Title(&pageTitle),