Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

refactor(config): promote AllowedDomains to top-level runtime config

Boschcf5ac7a4bb54
diff --git a/cmd/pinchtab/cmd_security.go b/cmd/pinchtab/cmd_security.go
index 61f009b6..c9cd31ce 100644
--- a/cmd/pinchtab/cmd_security.go
+++ b/cmd/pinchtab/cmd_security.go
@@ -254,7 +254,7 @@ func editSecurityCheck(cfg *config.RuntimeConfig, check cli.SecurityPostureCheck
}
return workflow.UpdateValue("security.attach.allowHosts", value)
case "idpi_whitelist_scoped":
- value, err := promptInput("Set security.allowedDomains (comma-separated):", strings.Join(cfg.IDPI.AllowedDomains, ","))
+ value, err := promptInput("Set security.allowedDomains (comma-separated):", strings.Join(cfg.AllowedDomains, ","))
if err != nil {
return nil, false, err
}
diff --git a/cmd/pinchtab/cmd_security_test.go b/cmd/pinchtab/cmd_security_test.go
index 21aa11aa..b32d19cf 100644
--- a/cmd/pinchtab/cmd_security_test.go
+++ b/cmd/pinchtab/cmd_security_test.go
@@ -127,12 +127,12 @@ func testRuntimeConfig() *config.RuntimeConfig {
AttachEnabled: false,
AttachAllowHosts: []string{"127.0.0.1", "localhost", "::1"},
AttachAllowSchemes: []string{"ws", "wss"},
+ AllowedDomains: []string{"127.0.0.1", "localhost", "::1"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"127.0.0.1", "localhost", "::1"},
- StrictMode: true,
- ScanContent: true,
- WrapContent: true,
+ Enabled: true,
+ StrictMode: true,
+ ScanContent: true,
+ WrapContent: true,
},
}
}
diff --git a/internal/bridge/tab_policy.go b/internal/bridge/tab_policy.go
index 4c536d8a..7463725e 100644
--- a/internal/bridge/tab_policy.go
+++ b/internal/bridge/tab_policy.go
@@ -34,7 +34,7 @@ func (tm *TabManager) idpiDomainPolicyActive() bool {
return tm != nil &&
tm.config != nil &&
tm.config.IDPI.Enabled &&
- len(tm.config.IDPI.AllowedDomains) > 0
+ len(tm.config.AllowedDomains) > 0
}
func (tm *TabManager) startTabPolicyWatcher(tabID string, ctx context.Context) {
diff --git a/internal/cli/report/security.go b/internal/cli/report/security.go
index 451cca73..94bc8a38 100644
--- a/internal/cli/report/security.go
+++ b/internal/cli/report/security.go
@@ -61,7 +61,7 @@ func AssessSecurityPosture(cfg *config.RuntimeConfig) SecurityPosture {
{
ID: "idpi_whitelist_scoped",
Label: "website whitelist",
- Passed: cfg.IDPI.Enabled && len(cfg.IDPI.AllowedDomains) > 0 && !allowsAllDomains(cfg.IDPI.AllowedDomains),
+ Passed: cfg.IDPI.Enabled && len(cfg.AllowedDomains) > 0 && !allowsAllDomains(cfg.AllowedDomains),
Detail: formatWhitelistStatus(cfg),
},
{
@@ -159,13 +159,13 @@ func AssessSecurityWarnings(cfg *config.RuntimeConfig) []SecurityWarning {
Attrs: []any{"setting", "security.idpi.enabled", "hint", "enable IDPI and keep security.allowedDomains scoped to approved websites"},
})
} else {
- if len(cfg.IDPI.AllowedDomains) == 0 {
+ if len(cfg.AllowedDomains) == 0 {
warnings = append(warnings, SecurityWarning{
ID: "idpi_whitelist_not_set",
Message: "website whitelist is not set for IDPI",
Attrs: []any{"setting", "security.allowedDomains", "hint", "configure allowedDomains to restrict which websites navigation may reach"},
})
- } else if allowsAllDomains(cfg.IDPI.AllowedDomains) {
+ } else if allowsAllDomains(cfg.AllowedDomains) {
warnings = append(warnings, SecurityWarning{
ID: "idpi_whitelist_allows_all",
Message: "website whitelist allows all domains",
@@ -299,13 +299,13 @@ func formatWhitelistStatus(cfg *config.RuntimeConfig) string {
if !cfg.IDPI.Enabled {
return "disabled"
}
- if len(cfg.IDPI.AllowedDomains) == 0 {
+ if len(cfg.AllowedDomains) == 0 {
return "not set"
}
- if allowsAllDomains(cfg.IDPI.AllowedDomains) {
+ if allowsAllDomains(cfg.AllowedDomains) {
return "wildcard"
}
- return strings.Join(cfg.IDPI.AllowedDomains, ", ")
+ return strings.Join(cfg.AllowedDomains, ", ")
}
func formatStrictModeStatus(cfg *config.RuntimeConfig) string {
diff --git a/internal/cli/report/security_test.go b/internal/cli/report/security_test.go
index 668e4ab8..d98c73a6 100644
--- a/internal/cli/report/security_test.go
+++ b/internal/cli/report/security_test.go
@@ -15,12 +15,12 @@ func TestAssessSecurityWarnings(t *testing.T) {
Token: "secret",
AttachAllowHosts: []string{"127.0.0.1", "localhost", "::1"},
AttachAllowSchemes: []string{"ws", "wss"},
+ AllowedDomains: []string{"127.0.0.1", "localhost", "::1"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"127.0.0.1", "localhost", "::1"},
- StrictMode: true,
- ScanContent: true,
- WrapContent: true,
+ Enabled: true,
+ StrictMode: true,
+ ScanContent: true,
+ WrapContent: true,
},
}
@@ -76,13 +76,13 @@ func TestAssessSecurityWarnings(t *testing.T) {
t.Run("wildcard whitelist is warned", func(t *testing.T) {
cfg := &config.RuntimeConfig{
- Bind: "127.0.0.1",
- Token: "secret",
+ Bind: "127.0.0.1",
+ Token: "secret",
+ AllowedDomains: []string{"*"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"*"},
- StrictMode: true,
- ScanContent: true,
+ Enabled: true,
+ StrictMode: true,
+ ScanContent: true,
},
}
@@ -157,12 +157,12 @@ func TestAssessSecurityPosture(t *testing.T) {
Token: "secret",
AttachAllowHosts: []string{"127.0.0.1", "localhost", "::1"},
AttachAllowSchemes: []string{"ws", "wss"},
+ AllowedDomains: []string{"127.0.0.1", "localhost", "::1"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"127.0.0.1", "localhost", "::1"},
- StrictMode: true,
- ScanContent: true,
- WrapContent: true,
+ Enabled: true,
+ StrictMode: true,
+ ScanContent: true,
+ WrapContent: true,
},
}
@@ -181,12 +181,12 @@ func TestAssessSecurityPosture(t *testing.T) {
Token: "secret",
AttachAllowHosts: []string{"*"},
AttachAllowSchemes: []string{"http", "https"},
+ AllowedDomains: []string{"example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"example.com"},
- StrictMode: true,
- ScanContent: true,
- WrapContent: true,
+ Enabled: true,
+ StrictMode: true,
+ ScanContent: true,
+ WrapContent: true,
},
}
diff --git a/internal/config/config_load.go b/internal/config/config_load.go
index 7c5ffeaa..55b2fd77 100644
--- a/internal/config/config_load.go
+++ b/internal/config/config_load.go
@@ -278,7 +278,11 @@ func applyFileConfig(cfg *RuntimeConfig, fc *FileConfig) {
cfg.TrustedResolveCIDRs = append([]string(nil), fc.Security.TrustedResolveCIDRs...)
// IDPI – copy the whole struct; individual fields have safe zero-value defaults.
cfg.IDPI = fc.Security.IDPI
- cfg.IDPI.AllowedDomains = effectiveSecurityAllowedDomains(fc.Security)
+ // Unified allowlist: security.allowedDomains is the canonical source,
+ // with a legacy fallback to security.idpi.allowedDomains.
+ cfg.AllowedDomains = effectiveSecurityAllowedDomains(fc.Security)
+ // Mirror onto IDPI for existing consumers that still read the deprecated field.
+ cfg.IDPI.AllowedDomains = append([]string(nil), cfg.AllowedDomains...)
if fc.Observability.Activity.Enabled != nil {
cfg.Observability.Activity.Enabled = *fc.Observability.Activity.Enabled
}
diff --git a/internal/config/config_types.go b/internal/config/config_types.go
index 3c675ad0..08996574 100644
--- a/internal/config/config_types.go
+++ b/internal/config/config_types.go
@@ -18,10 +18,15 @@ type RuntimeConfig struct {
CookieSecure *bool // Nil = auto-detect based on request scheme/host for backward compatibility
// Security settings
- AllowEvaluate bool
- AllowMacro bool
- AllowScreencast bool
- AllowDownload bool
+ AllowEvaluate bool
+ AllowMacro bool
+ AllowScreencast bool
+ AllowDownload bool
+ // AllowedDomains is the unified per-instance allowlist sourced from
+ // security.allowedDomains in the file config. Consumers (IDPI guard,
+ // download handler, tab policy) should prefer this list over the
+ // deprecated IDPI.AllowedDomains duplicate.
+ AllowedDomains []string
DownloadAllowedDomains []string
DownloadMaxBytes int
AllowUpload bool
diff --git a/internal/handlers/download.go b/internal/handlers/download.go
index d1688591..f689228d 100644
--- a/internal/handlers/download.go
+++ b/internal/handlers/download.go
@@ -255,12 +255,11 @@ func (h *Handlers) HandleDownload(w http.ResponseWriter, r *http.Request) {
maxDownloadBytes := h.Config.EffectiveDownloadMaxBytes()
// Download allowlist: prefer the explicit per-feature list, but fall
- // back to the unified security.allowedDomains (surfaced on the runtime
- // config as IDPI.AllowedDomains). This way operators only need to
- // configure trusted domains once.
+ // back to the unified security.allowedDomains. This way operators only
+ // need to configure trusted domains once.
allowed := h.Config.DownloadAllowedDomains
if len(allowed) == 0 {
- allowed = h.Config.IDPI.AllowedDomains
+ allowed = h.Config.AllowedDomains
}
validator := newDownloadURLGuard(allowed)
if err := validator.Validate(dlURL); err != nil {
diff --git a/internal/handlers/download_test.go b/internal/handlers/download_test.go
index 4c9c8e69..9fa7b62e 100644
--- a/internal/handlers/download_test.go
+++ b/internal/handlers/download_test.go
@@ -321,10 +321,10 @@ func TestHandleDownload_TabScopedCrossOriginBlockedForCookieAuth(t *testing.T) {
},
}
h := New(b, &config.RuntimeConfig{
- AllowDownload: true,
+ AllowDownload: true,
+ AllowedDomains: []string{"pinchtab.com", "example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"pinchtab.com"},
+ Enabled: true,
},
}, nil, nil, nil)
req := httptest.NewRequest("GET", "/download?tabId=tab1&url=https://example.com/file.txt", nil)
@@ -354,10 +354,10 @@ func TestHandleDownload_TabScopedCrossOriginAllowedForHeaderAuth(t *testing.T) {
},
}
h := New(b, &config.RuntimeConfig{
- AllowDownload: true,
+ AllowDownload: true,
+ AllowedDomains: []string{"pinchtab.com", "example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"pinchtab.com"},
+ Enabled: true,
},
}, nil, nil, nil)
req := httptest.NewRequest("GET", "/download?tabId=tab1&url=https://example.com/file.txt", nil)
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go
index 4641e74f..6cf60921 100644
--- a/internal/handlers/handlers_test.go
+++ b/internal/handlers/handlers_test.go
@@ -354,10 +354,10 @@ func TestHandleGetConsoleLogs_BlocksWhenCachedTabPolicyIsBlocked(t *testing.T) {
hasState: true,
}
h := New(b, &config.RuntimeConfig{
+ AllowedDomains: []string{"example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"example.com"},
- StrictMode: true,
+ Enabled: true,
+ StrictMode: true,
},
}, nil, nil, nil)
@@ -382,10 +382,10 @@ func TestHandleGetErrorLogs_BlocksWhenCachedTabPolicyIsBlocked(t *testing.T) {
hasState: true,
}
h := New(b, &config.RuntimeConfig{
+ AllowedDomains: []string{"example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"example.com"},
- StrictMode: true,
+ Enabled: true,
+ StrictMode: true,
},
}, nil, nil, nil)
diff --git a/internal/handlers/tab_policy.go b/internal/handlers/tab_policy.go
index 3b276665..ed1a790d 100644
--- a/internal/handlers/tab_policy.go
+++ b/internal/handlers/tab_policy.go
@@ -25,7 +25,7 @@ func (h *Handlers) currentTabDomainPolicyEnabled() bool {
return h != nil &&
h.Config != nil &&
h.Config.IDPI.Enabled &&
- len(h.Config.IDPI.AllowedDomains) > 0
+ len(h.Config.AllowedDomains) > 0
}
func (h *Handlers) enforceCurrentTabDomainPolicy(w http.ResponseWriter, r *http.Request, ctx context.Context, tabID string) (string, bool) {
diff --git a/internal/handlers/tab_policy_test.go b/internal/handlers/tab_policy_test.go
index 8c4ac027..62b4b25a 100644
--- a/internal/handlers/tab_policy_test.go
+++ b/internal/handlers/tab_policy_test.go
@@ -45,11 +45,11 @@ func TestHandleActionBlocksWhenCachedTabPolicyIsBlocked(t *testing.T) {
hasState: true,
}
h := New(b, &config.RuntimeConfig{
- ActionTimeout: time.Second,
+ ActionTimeout: time.Second,
+ AllowedDomains: []string{"example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"example.com"},
- StrictMode: true,
+ Enabled: true,
+ StrictMode: true,
},
}, nil, nil, nil)
@@ -85,11 +85,11 @@ func TestHandleActionWarnsWhenCachedTabPolicyIsThreatOnly(t *testing.T) {
hasState: true,
}
h := New(b, &config.RuntimeConfig{
- ActionTimeout: time.Second,
+ ActionTimeout: time.Second,
+ AllowedDomains: []string{"example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"example.com"},
- StrictMode: false,
+ Enabled: true,
+ StrictMode: false,
},
}, nil, nil, nil)
@@ -120,11 +120,11 @@ func TestHandleBackIgnoresCachedTabPolicyBlock(t *testing.T) {
hasState: true,
}
h := New(b, &config.RuntimeConfig{
- ActionTimeout: time.Second,
+ ActionTimeout: time.Second,
+ AllowedDomains: []string{"example.com"},
IDPI: config.IDPIConfig{
- Enabled: true,
- AllowedDomains: []string{"example.com"},
- StrictMode: true,
+ Enabled: true,
+ StrictMode: true,
},
}, nil, nil, nil)