High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(config): make an absent security block mean at save what it means at boot, so a timeout edit cannot install idpi or an allowlist the runtime never enforced (PIN-277)
Luigi Agosti9340c948027f
diff --git a/cmd/pinchtab/cmd_wizard.go b/cmd/pinchtab/cmd_wizard.goindex 93a24a4c..afcaf9ce 100644--- a/cmd/pinchtab/cmd_wizard.go+++ b/cmd/pinchtab/cmd_wizard.go@@ -188,10 +188,12 @@ func applyPosture(cfg *config.FileConfig, p securityPosture) {cfg.Security.AllowUpload = boolPtr(p.allowUpload)cfg.Security.AllowMacro = boolPtr(p.allowMacro)cfg.Security.AllowScreencast = boolPtr(p.allowScreencast)- cfg.Security.IDPI.Enabled = p.idpiOn- cfg.Security.IDPI.StrictMode = p.idpiOn- cfg.Security.IDPI.ScanContent = p.idpiOn- cfg.Security.IDPI.WrapContent = p.idpiOn+ idpi := cfg.Security.EffectiveIDPI()+ idpi.Enabled = p.idpiOn+ idpi.StrictMode = p.idpiOn+ idpi.ScanContent = p.idpiOn+ idpi.WrapContent = p.idpiOn+ cfg.Security.IDPI = &idpicfg.Security.AllowedDomains = append([]string(nil), p.allowedDomains...)if p.bind != "" {cfg.Server.Bind = p.binddiff --git a/internal/cli/report/security_test.go b/internal/cli/report/security_test.goindex a35559c4..31b57abe 100644--- a/internal/cli/report/security_test.go+++ b/internal/cli/report/security_test.go@@ -244,7 +244,7 @@ func TestApplyRecommendedSecurityDefaults(t *testing.T) {Enabled: &attachEnabled,AllowHosts: []string{"chrome.internal"},},- IDPI: config.IDPIConfig{+ IDPI: &config.IDPIConfig{Enabled: false,},},@@ -301,7 +301,7 @@ func TestRestoreSecurityDefaults(t *testing.T) {Enabled: &attachEnabled,AllowHosts: []string{"chrome.internal"},},- IDPI: config.IDPIConfig{+ IDPI: &config.IDPIConfig{Enabled: false,},},diff --git a/internal/config/config_file.go b/internal/config/config_file.goindex 217a7ef4..39a99aba 100644--- a/internal/config/config_file.go+++ b/internal/config/config_file.go@@ -187,7 +187,6 @@ func DefaultFileConfig() FileConfig {AllowDownload: &allowDownload,AllowCookies: &allowCookies,AllowNetworkIntercept: &allowNetworkIntercept,- AllowedDomains: append([]string(nil), defaultLocalAllowedDomains...),DownloadAllowedDomains: []string{},DownloadMaxBytes: &downloadMaxBytes,AllowUpload: &allowUpload,@@ -206,7 +205,7 @@ func DefaultFileConfig() FileConfig {AllowSchemes: []string{"ws", "wss", "http", "https"},ForwardProxyAuth: &attachForwardProxyAuth,},- IDPI: IDPIConfig{+ IDPI: &IDPIConfig{Enabled: true,StrictMode: true,ScanContent: true,diff --git a/internal/config/config_file_marshal.go b/internal/config/config_file_marshal.goindex 7f27a950..a6078ae3 100644--- a/internal/config/config_file_marshal.go+++ b/internal/config/config_file_marshal.go@@ -209,46 +209,7 @@ func (fc FileConfig) MarshalJSON() ([]byte, error) {TabPolicy: fc.InstanceDefaults.TabPolicy,DialogAutoAccept: fc.InstanceDefaults.DialogAutoAccept,},- Security: securityConfigJSON{- AllowEvaluate: fc.Security.AllowEvaluate,- AllowMacro: fc.Security.AllowMacro,- AllowScreencast: fc.Security.AllowScreencast,- AllowDownload: fc.Security.AllowDownload,- AllowCookies: fc.Security.AllowCookies,- AllowNetworkIntercept: fc.Security.AllowNetworkIntercept,- AllowFileScheme: fc.Security.AllowFileScheme,- AllowedDomains: effectiveSecurityAllowedDomains(fc.Security),- DownloadAllowedDomains: copyStringSlice(fc.Security.DownloadAllowedDomains),- DownloadMaxBytes: fc.Security.DownloadMaxBytes,- AllowUpload: fc.Security.AllowUpload,- AllowClipboard: fc.Security.AllowClipboard,- AllowStateExport: fc.Security.AllowStateExport,- StateEncryptionKey: fc.Security.StateEncryptionKey,- EnableActionGuards: fc.Security.EnableActionGuards,- UploadMaxRequestBytes: fc.Security.UploadMaxRequestBytes,- UploadMaxFiles: fc.Security.UploadMaxFiles,- UploadMaxFileBytes: fc.Security.UploadMaxFileBytes,- UploadMaxTotalBytes: fc.Security.UploadMaxTotalBytes,- MaxRedirects: fc.Security.MaxRedirects,- TrustedProxyCIDRs: copyStringSlice(fc.Security.TrustedProxyCIDRs),- TrustedResolveCIDRs: copyStringSlice(fc.Security.TrustedResolveCIDRs),- TrustLoopbackProxy: fc.Security.TrustLoopbackProxy,- Attach: attachJSON{- Enabled: fc.Security.Attach.Enabled,- AllowHosts: copyStringSlice(fc.Security.Attach.AllowHosts),- AllowSchemes: copyStringSlice(fc.Security.Attach.AllowSchemes),- ForwardProxyAuth: fc.Security.Attach.ForwardProxyAuth,- },- IDPI: idpiConfigJSON{- Enabled: fc.Security.IDPI.Enabled,- StrictMode: fc.Security.IDPI.StrictMode,- ScanContent: fc.Security.IDPI.ScanContent,- WrapContent: fc.Security.IDPI.WrapContent,- CustomPatterns: copyStringSlice(fc.Security.IDPI.CustomPatterns),- ScanTimeoutSec: fc.Security.IDPI.ScanTimeoutSec,- ShieldThreshold: fc.Security.IDPI.ShieldThreshold,- },- },+ Security: fc.Security.wire(),Profiles: profilesConfigJSON{BaseDir: fc.Profiles.BaseDir,DefaultProfile: fc.Profiles.DefaultProfile,@@ -352,6 +313,56 @@ func (fc FileConfig) MarshalJSON() ([]byte, error) {})}+func (s SecurityConfig) wire() securityConfigJSON {+ return securityConfigJSON{+ AllowEvaluate: s.AllowEvaluate,+ AllowMacro: s.AllowMacro,+ AllowScreencast: s.AllowScreencast,+ AllowDownload: s.AllowDownload,+ AllowCookies: s.AllowCookies,+ AllowNetworkIntercept: s.AllowNetworkIntercept,+ AllowFileScheme: s.AllowFileScheme,+ AllowedDomains: effectiveSecurityAllowedDomains(s),+ DownloadAllowedDomains: copyStringSlice(s.DownloadAllowedDomains),+ DownloadMaxBytes: s.DownloadMaxBytes,+ AllowUpload: s.AllowUpload,+ AllowClipboard: s.AllowClipboard,+ AllowStateExport: s.AllowStateExport,+ StateEncryptionKey: s.StateEncryptionKey,+ EnableActionGuards: s.EnableActionGuards,+ UploadMaxRequestBytes: s.UploadMaxRequestBytes,+ UploadMaxFiles: s.UploadMaxFiles,+ UploadMaxFileBytes: s.UploadMaxFileBytes,+ UploadMaxTotalBytes: s.UploadMaxTotalBytes,+ MaxRedirects: s.MaxRedirects,+ TrustedProxyCIDRs: copyStringSlice(s.TrustedProxyCIDRs),+ TrustedResolveCIDRs: copyStringSlice(s.TrustedResolveCIDRs),+ TrustLoopbackProxy: s.TrustLoopbackProxy,+ Attach: attachJSON{+ Enabled: s.Attach.Enabled,+ AllowHosts: copyStringSlice(s.Attach.AllowHosts),+ AllowSchemes: copyStringSlice(s.Attach.AllowSchemes),+ ForwardProxyAuth: s.Attach.ForwardProxyAuth,+ },+ IDPI: s.IDPI.wire(),+ }+}++func (i *IDPIConfig) wire() idpiConfigJSON {+ if i == nil {+ i = &IDPIConfig{}+ }+ return idpiConfigJSON{+ Enabled: i.Enabled,+ StrictMode: i.StrictMode,+ ScanContent: i.ScanContent,+ WrapContent: i.WrapContent,+ CustomPatterns: copyStringSlice(i.CustomPatterns),+ ScanTimeoutSec: i.ScanTimeoutSec,+ ShieldThreshold: i.ShieldThreshold,+ }+}+func (fc *FileConfig) UnmarshalJSON(data []byte) error {type rawFileConfig FileConfigtmp := rawFileConfig(*fc)@@ -398,6 +409,7 @@ func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {trustLoopbackProxy := cfg.TrustLoopbackProxyattachEnabled := cfg.AttachEnabledattachForwardProxyAuth := cfg.AttachForwardProxyAuth+ idpi := cfg.IDPIstart := cfg.InstancePortStartend := cfg.InstancePortEndrestartMaxRestarts := cfg.RestartMaxRestarts@@ -536,7 +548,7 @@ func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {AllowSchemes: append([]string(nil), cfg.AttachAllowSchemes...),ForwardProxyAuth: &attachForwardProxyAuth,},- IDPI: cfg.IDPI,+ IDPI: &idpi,},Profiles: ProfilesConfig{BaseDir: cfg.ProfilesBaseDir,diff --git a/internal/config/config_file_test.go b/internal/config/config_file_test.goindex 84a46f8f..cf1fb9cc 100644--- a/internal/config/config_file_test.go+++ b/internal/config/config_file_test.go@@ -84,8 +84,8 @@ func TestDefaultFileConfig(t *testing.T) {if !fc.Security.IDPI.Enabled {t.Errorf("DefaultFileConfig.Security.IDPI.Enabled = %v, want true", fc.Security.IDPI.Enabled)}- if len(fc.Security.AllowedDomains) != 3 || fc.Security.AllowedDomains[0] != "127.0.0.1" {- t.Errorf("DefaultFileConfig.Security.AllowedDomains = %v, want local-only allowlist", fc.Security.AllowedDomains)+ if len(fc.Security.AllowedDomains) != 0 {+ t.Errorf("DefaultFileConfig.Security.AllowedDomains = %v, want none", fc.Security.AllowedDomains)}if !fc.Security.IDPI.StrictMode {t.Errorf("DefaultFileConfig.Security.IDPI.StrictMode = %v, want true", fc.Security.IDPI.StrictMode)@@ -462,8 +462,8 @@ func TestDefaultFileConfigJSON(t *testing.T) {if !parsed.Security.IDPI.Enabled {t.Errorf("round-trip Security.IDPI.Enabled = %v, want true", parsed.Security.IDPI.Enabled)}- if len(parsed.Security.AllowedDomains) != 3 || parsed.Security.AllowedDomains[0] != "127.0.0.1" {- t.Errorf("round-trip Security.AllowedDomains = %v, want local-only allowlist", parsed.Security.AllowedDomains)+ if len(parsed.Security.AllowedDomains) != 0 {+ t.Errorf("round-trip Security.AllowedDomains = %v, want none", parsed.Security.AllowedDomains)}if !parsed.Security.IDPI.StrictMode {t.Errorf("round-trip Security.IDPI.StrictMode = %v, want true", parsed.Security.IDPI.StrictMode)diff --git a/internal/config/config_load.go b/internal/config/config_load.goindex 7432fd38..2448c104 100644--- a/internal/config/config_load.go+++ b/internal/config/config_load.go@@ -205,7 +205,7 @@ func LoadConfig() (*RuntimeConfig, []LoadDiagnostic, error) {AllowFileScheme: false,RetainNetworkBodies: false,RetainNetworkBodyMaxBytes: 256 * 1024,- AllowedDomains: append([]string(nil), defaultLocalAllowedDomains...),+ AllowedDomains: nil,DownloadAllowedDomains: nil,DownloadMaxBytes: DefaultDownloadMaxBytes,AllowUpload: false,@@ -262,14 +262,6 @@ func LoadConfig() (*RuntimeConfig, []LoadDiagnostic, error) {AttachAllowHosts: []string{"127.0.0.1", "localhost", "::1"},AttachAllowSchemes: []string{"ws", "wss", "http", "https"},- IDPI: IDPIConfig{- Enabled: true,- StrictMode: true,- ScanContent: true,- WrapContent: true,- ScanTimeoutSec: 5,- },-Observability: ObservabilityConfig{Activity: ActivityConfig{Enabled: true,@@ -517,7 +509,9 @@ func applySecurityConfig(cfg *RuntimeConfig, s SecurityConfig) {if s.TrustLoopbackProxy != nil {cfg.TrustLoopbackProxy = *s.TrustLoopbackProxy}- cfg.IDPI = s.IDPI+ if s.IDPI != nil {+ cfg.IDPI = *s.IDPI+ }cfg.AllowedDomains = effectiveSecurityAllowedDomains(s)if s.Attach.Enabled != nil {cfg.AttachEnabled = *s.Attach.Enableddiff --git a/internal/config/config_load_test.go b/internal/config/config_load_test.goindex 9b556809..ce23f453 100644--- a/internal/config/config_load_test.go+++ b/internal/config/config_load_test.go@@ -7,6 +7,7 @@ import ("log/slog""os""path/filepath"+ "reflect""strings""testing""time"@@ -106,20 +107,11 @@ func TestLoadConfigDefaults(t *testing.T) {if strings.Join(cfg.AttachAllowSchemes, ",") != strings.Join(wantAttachSchemes, ",") {t.Errorf("default AttachAllowSchemes = %v, want %v", cfg.AttachAllowSchemes, wantAttachSchemes)}- if !cfg.IDPI.Enabled {- t.Errorf("default IDPI.Enabled = %v, want true", cfg.IDPI.Enabled)- }- if len(cfg.AllowedDomains) != 3 || cfg.AllowedDomains[0] != "127.0.0.1" {- t.Errorf("default AllowedDomains = %v, want local-only allowlist", cfg.AllowedDomains)- }- if !cfg.IDPI.StrictMode {- t.Errorf("default IDPI.StrictMode = %v, want true", cfg.IDPI.StrictMode)- }- if !cfg.IDPI.ScanContent {- t.Errorf("default IDPI.ScanContent = %v, want true", cfg.IDPI.ScanContent)+ if !reflect.DeepEqual(cfg.IDPI, IDPIConfig{}) {+ t.Errorf("default IDPI = %+v, want the zero value: a file that says nothing about IDPI boots with it off, and the starter file states it explicitly", cfg.IDPI)}- if !cfg.IDPI.WrapContent {- t.Errorf("default IDPI.WrapContent = %v, want true", cfg.IDPI.WrapContent)+ if len(cfg.AllowedDomains) != 0 {+ t.Errorf("default AllowedDomains = %v, want none: a localhost-only default refuses every external navigation, so it is not a live policy", cfg.AllowedDomains)}if !cfg.Observability.Activity.Enabled {t.Errorf("default Observability.Activity.Enabled = %v, want true", cfg.Observability.Activity.Enabled)@@ -490,8 +482,8 @@ func TestApplyFileConfigToRuntimeResetsSecurityFlagsToSafeDefaults(t *testing.T)if !cfg.IDPI.Enabled {t.Errorf("ApplyFileConfigToRuntime IDPI.Enabled = %v, want true", cfg.IDPI.Enabled)}- if len(cfg.AllowedDomains) != 3 || cfg.AllowedDomains[0] != "127.0.0.1" {- t.Errorf("ApplyFileConfigToRuntime AllowedDomains = %v, want local-only allowlist", cfg.AllowedDomains)+ if len(cfg.AllowedDomains) != 0 {+ t.Errorf("ApplyFileConfigToRuntime AllowedDomains = %v, want none; a file that names no allowlist must not receive one", cfg.AllowedDomains)}if !cfg.IDPI.StrictMode || !cfg.IDPI.ScanContent || !cfg.IDPI.WrapContent {t.Errorf("ApplyFileConfigToRuntime IDPI = %+v, want strict+scan+wrap enabled", cfg.IDPI)diff --git a/internal/config/config_types.go b/internal/config/config_types.goindex 008099fe..c18bbd1d 100644--- a/internal/config/config_types.go+++ b/internal/config/config_types.go@@ -1,6 +1,7 @@package configimport (+ "encoding/json""time""github.com/pinchtab/pinchtab/internal/session"@@ -167,8 +168,6 @@ type DashboardSessionRuntimeConfig struct {RequireElevation bool `json:"requireElevation,omitempty"`}-// IDPIConfig holds the configuration for the Indirect Prompt Injection (IDPI)-// defense layer.type IDPIConfig struct {Enabled bool `json:"enabled,omitempty"`StrictMode bool `json:"strictMode,omitempty"`@@ -478,7 +477,29 @@ type SecurityConfig struct {TrustedResolveCIDRs []string `json:"trustedResolveCIDRs,omitempty"`TrustLoopbackProxy *bool `json:"trustLoopbackProxy,omitempty"`Attach AttachConfig `json:"attach,omitempty"`- IDPI IDPIConfig `json:"idpi,omitempty"`+ IDPI *IDPIConfig `json:"idpi,omitempty"`+}++func (s *SecurityConfig) ensureIDPI() *IDPIConfig {+ if s.IDPI == nil {+ s.IDPI = &IDPIConfig{}+ }+ return s.IDPI+}++func (s SecurityConfig) EffectiveIDPI() IDPIConfig {+ if s.IDPI == nil {+ return IDPIConfig{}+ }+ return *s.IDPI+}++func (s SecurityConfig) MarshalJSON() ([]byte, error) {+ type tagged SecurityConfig+ return json.Marshal(struct {+ tagged+ IDPI IDPIConfig `json:"idpi"`+ }{tagged(s), s.EffectiveIDPI()})}type MultiInstanceConfig struct {diff --git a/internal/config/config_utils.go b/internal/config/config_utils.goindex cb124409..f3f59e45 100644--- a/internal/config/config_utils.go+++ b/internal/config/config_utils.go@@ -11,8 +11,6 @@ import ("strings")-var defaultLocalAllowedDomains = []string{"127.0.0.1", "localhost", "::1"}-func homeDir() string {if home := os.Getenv("HOME"); home != "" {return homediff --git a/internal/config/default_reachability_test.go b/internal/config/default_reachability_test.gonew file mode 100644index 00000000..61ce08db--- /dev/null+++ b/internal/config/default_reachability_test.go@@ -0,0 +1,76 @@+package config++import (+ "os"+ "path/filepath"+ "reflect"+ "testing"+)++func TestApplyingAFileThatSaysNothingLeavesEveryRuntimeDefaultInPlace(t *testing.T) {+ clearConfigEnvVars(t)+ t.Setenv("PINCHTAB_CONFIG", filepath.Join(t.TempDir(), "nonexistent.json"))++ cfg, _, err := LoadConfig()+ if err != nil {+ t.Fatal(err)+ }+ before := FileConfigFromRuntime(cfg).Security++ ApplyFileConfigToRuntime(cfg, &FileConfig{})++ after := FileConfigFromRuntime(cfg).Security+ if !reflect.DeepEqual(before, after) {+ t.Errorf("a file with no security section changed the security defaults\nbefore: %+v\nafter: %+v", before, after)+ }+}++func TestAnAbsentIDPIBlockIsNotAnExplicitlyOffOne(t *testing.T) {+ live := IDPIConfig{Enabled: true, StrictMode: true, ScanTimeoutSec: 5}++ cfg := &RuntimeConfig{IDPI: live}+ ApplyFileConfigToRuntime(cfg, &FileConfig{})+ if !reflect.DeepEqual(cfg.IDPI, live) {+ t.Errorf("a file with no idpi block overwrote the runtime value: got %+v, want %+v", cfg.IDPI, live)+ }++ cfg = &RuntimeConfig{IDPI: live}+ ApplyFileConfigToRuntime(cfg, &FileConfig{Security: SecurityConfig{IDPI: &IDPIConfig{}}})+ if !reflect.DeepEqual(cfg.IDPI, IDPIConfig{}) {+ t.Errorf("an explicit all-off idpi block did not switch IDPI off: got %+v", cfg.IDPI)+ }+}++func TestASparseFileLoadsWithoutAnIDPIBlockWhileTheStarterStatesOne(t *testing.T) {+ clearConfigEnvVars(t)+ path := filepath.Join(t.TempDir(), "config.json")+ t.Setenv("PINCHTAB_CONFIG", path)+ if err := os.WriteFile(path, []byte(`{"server":{"port":"18799","token":"t"}}`), 0o600); err != nil {+ t.Fatal(err)+ }++ fc, _, err := LoadFileConfig()+ if err != nil {+ t.Fatal(err)+ }+ if fc.Security.IDPI != nil {+ t.Errorf("a file that says nothing about IDPI loaded a block: %+v; the next save would install it as an explicit setting the boot never enforced", *fc.Security.IDPI)+ }++ starter := DefaultFileConfig().Security.IDPI+ if starter == nil || !starter.Enabled {+ t.Errorf("the starter file no longer states IDPI on: %+v", starter)+ }+}++func TestTheSecuritySectionComparesAnAbsentIDPIBlockEqualToAnAllOffOne(t *testing.T) {+ absent := SecurityConfig{}+ explicitOff := SecurityConfig{IDPI: &IDPIConfig{}}+ if !sameJSONValue(absent, explicitOff) {+ t.Error("an absent idpi block and an all-off one render differently, so a dashboard save that echoes the values in effect reads as a security edit")+ }+ on := SecurityConfig{IDPI: &IDPIConfig{Enabled: true}}+ if sameJSONValue(absent, on) {+ t.Error("an absent idpi block renders the same as an enabled one, so the comparison cannot see IDPI being switched on")+ }+}diff --git a/internal/config/editor_get.go b/internal/config/editor_get.goindex 110495ee..ca8351b6 100644--- a/internal/config/editor_get.go+++ b/internal/config/editor_get.go@@ -335,7 +335,7 @@ func getSecurityField(s *SecurityConfig, field string) (string, error) {return getAttachField(&s.Attach, strings.TrimPrefix(field, "attach."))}if strings.HasPrefix(field, "idpi.") {- return getIDPIField(&s.IDPI, strings.TrimPrefix(field, "idpi."))+ return getIDPIField(s.IDPI, strings.TrimPrefix(field, "idpi."))}switch field {@@ -456,6 +456,9 @@ func getAttachField(a *AttachConfig, field string) (string, error) {}func getIDPIField(i *IDPIConfig, field string) (string, error) {+ if i == nil {+ i = &IDPIConfig{}+ }switch field {case "enabled":return strconv.FormatBool(i.Enabled), nildiff --git a/internal/config/editor_get_effective_test.go b/internal/config/editor_get_effective_test.goindex c5fd3676..5e41f807 100644--- a/internal/config/editor_get_effective_test.go+++ b/internal/config/editor_get_effective_test.go@@ -101,6 +101,7 @@ var blankIsTheAnswer = map[string]string{"browser.fallbackOrder": "no fallback configured; an implicit launch then tries the primary target only","instanceDefaults.timezone": "unset means the host timezone","instanceDefaults.userAgent": "unset means the browser's own user agent",+ "security.allowedDomains": "empty list; an absent allowlist is not a restriction, so every host is permitted. A localhost-only default used to be printed here, and honouring it would have refused every external navigation","security.downloadAllowedDomains": "empty list, downloads follow the main allowlist","security.trustedProxyCIDRs": "empty list","security.trustedResolveCIDRs": "empty list",diff --git a/internal/config/editor_set.go b/internal/config/editor_set.goindex 50129193..f952b2f7 100644--- a/internal/config/editor_set.go+++ b/internal/config/editor_set.go@@ -745,7 +745,7 @@ func setAttachField(a *AttachConfig, field, value string) error {}func setIDPIField(s *SecurityConfig, field, value string) error {- i := &s.IDPI+ i := s.ensureIDPI()switch field {case "enabled":b, err := parseBool(value)diff --git a/internal/config/fileio.go b/internal/config/fileio.goindex e7091dbb..b1516345 100644--- a/internal/config/fileio.go+++ b/internal/config/fileio.go@@ -72,6 +72,7 @@ func tightenConfigPermsOnRead(path string) error {func savedConfigBaseline() *FileConfig {defaults := DefaultFileConfig()defaults.ConfigVersion = ""+ defaults.Security.IDPI = nilreturn &defaults}diff --git a/internal/config/validate.go b/internal/config/validate.goindex 06c3039c..2e2c16ad 100644--- a/internal/config/validate.go+++ b/internal/config/validate.go@@ -253,7 +253,7 @@ func ValidateFileConfig(fc *FileConfig) []error {errs = append(errs, validateBrowserExtraFlags(fc.Browser.BrowserExtraFlags)...)}- errs = append(errs, validateIDPIConfig(fc.Security.IDPI, effectiveSecurityAllowedDomains(fc.Security))...)+ errs = append(errs, validateIDPIConfig(fc.Security.EffectiveIDPI(), effectiveSecurityAllowedDomains(fc.Security))...)errs = append(errs, validateAllowedDomainList("security.downloadAllowedDomains", fc.Security.DownloadAllowedDomains)...)errs = append(errs, validateTrustedCIDRList("security.trustedProxyCIDRs", fc.Security.TrustedProxyCIDRs)...)errs = append(errs, validateTrustedCIDRList("security.trustedResolveCIDRs", fc.Security.TrustedResolveCIDRs)...)diff --git a/internal/config/validate_test.go b/internal/config/validate_test.goindex 3108e29f..31abc50f 100644--- a/internal/config/validate_test.go+++ b/internal/config/validate_test.go@@ -961,7 +961,7 @@ func TestValidateFileConfig_IDPIPassthrough(t *testing.T) {fc := &FileConfig{Security: SecurityConfig{AllowedDomains: []string{""}, // invalid- IDPI: IDPIConfig{+ IDPI: &IDPIConfig{Enabled: true,CustomPatterns: []string{" "}, // invalid},diff --git a/internal/config/workflow/security.go b/internal/config/workflow/security.goindex e5669d95..b0b8758d 100644--- a/internal/config/workflow/security.go+++ b/internal/config/workflow/security.go@@ -205,7 +205,7 @@ func securityDefaultsSnapshot(fc *config.FileConfig) securityDefaultsState {Bind: fc.Server.Bind,Token: fc.Server.Token,Security: securityConfigValues{- IDPI: fc.Security.IDPI,+ IDPI: fc.Security.EffectiveIDPI(),},}if fc.Security.AllowEvaluate != nil {diff --git a/internal/dashboard/config_api_security_default_test.go b/internal/dashboard/config_api_security_default_test.gonew file mode 100644index 00000000..d0f1c2c5--- /dev/null+++ b/internal/dashboard/config_api_security_default_test.go@@ -0,0 +1,83 @@+package dashboard++import (+ "bytes"+ "encoding/json"+ "net/http"+ "net/http/httptest"+ "os"+ "reflect"+ "testing"++ "github.com/pinchtab/pinchtab/internal/authn"+)++const sparseUserConfigJSON = `{"server":{"port":"18799","token":"secret-token"}}`++func TestSavingOneTimeoutLeavesTheSecurityPostureByteIdentical(t *testing.T) {+ api := newConfigAPIOverFile(t, []byte(sparseUserConfigJSON))+ path := os.Getenv("PINCHTAB_CONFIG")+ fileBefore, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ before := runtimeSecurityInfo(api.cfg())+ if before.IDPIEnabled || len(before.AllowedDomains) != 0 {+ t.Fatalf("a sparse file booted with a policy it never stated: %+v", before)+ }++ getRes := httptest.NewRecorder()+ api.HandleGetConfig(getRes, httptest.NewRequest(http.MethodGet, "/api/config", nil))+ if getRes.Code != http.StatusOK {+ t.Fatalf("HandleGetConfig() status = %d", getRes.Code)+ }+ body := putBodyFromGetPayloadWithActionTimeout(t, getRes, 45)++ putReq := httptest.NewRequest(http.MethodPut, "/api/config", bytes.NewReader(body))+ putReq.AddCookie(&http.Cookie{Name: authn.CookieName, Value: "dashboard-session"})+ putRes := httptest.NewRecorder()+ api.HandlePutConfig(putRes, putReq)+ if putRes.Code != http.StatusOK {+ t.Fatalf("HandlePutConfig() status = %d: %s", putRes.Code, putRes.Body.String())+ }++ after := runtimeSecurityInfo(api.cfg())+ if !reflect.DeepEqual(before, after) {+ t.Errorf("saving a timeout changed the reported security posture\nbefore: %+v\nafter: %+v", before, after)+ }+ env := decodeConfigEnvelope(t, putRes)+ if env.RestartRequired || len(env.RestartReasons) != 0 {+ t.Errorf("a save that changed no security field reports restartRequired=%v reasons=%v", env.RestartRequired, env.RestartReasons)+ }+ if env.Config.Timeouts.ActionSec != 45 {+ t.Errorf("the one field the caller changed did not land: %+v", env.Config.Timeouts)+ }+ fileAfter, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ if !bytes.Contains(fileAfter, []byte(`"actionSec": 45`)) || bytes.Contains(fileAfter, []byte(`"idpi"`)) {+ t.Errorf("the file gained something other than the edited timeout:\nbefore: %s\nafter: %s", fileBefore, fileAfter)+ }+}++func putBodyFromGetPayloadWithActionTimeout(t *testing.T, getRes *httptest.ResponseRecorder, actionSec int) []byte {+ t.Helper()++ var envelope struct {+ Config map[string]any `json:"config"`+ }+ if err := json.Unmarshal(getRes.Body.Bytes(), &envelope); err != nil {+ t.Fatalf("Unmarshal GET payload: %v", err)+ }+ timeouts, ok := envelope.Config["timeouts"].(map[string]any)+ if !ok {+ t.Fatalf("GET payload has no timeouts section: %v", envelope.Config)+ }+ timeouts["actionSec"] = actionSec+ body, err := json.Marshal(envelope.Config)+ if err != nil {+ t.Fatalf("Marshal PUT body: %v", err)+ }+ return body+}diff --git a/internal/orchestrator/handlers_instances.go b/internal/orchestrator/handlers_instances.goindex e2876e44..c857a2c4 100644--- a/internal/orchestrator/handlers_instances.go+++ b/internal/orchestrator/handlers_instances.go@@ -312,7 +312,7 @@ func validateStartInstanceSecurityPolicy(policy *bridge.SecurityPolicy) error {errs := config.ValidateFileConfig(&config.FileConfig{Security: config.SecurityConfig{AllowedDomains: append([]string(nil), policy.AllowedDomains...),- IDPI: config.IDPIConfig{+ IDPI: &config.IDPIConfig{Enabled: true,},},