Skip to content

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

fix: issue with dashboard empty settings

Luigi Agostie73780ac7cc0
diff --git a/internal/config/config_file.go b/internal/config/config_file.go
index 98d2564f..8b6425c3 100644
--- a/internal/config/config_file.go
+++ b/internal/config/config_file.go
@@ -82,6 +82,208 @@ func DefaultFileConfig() FileConfig {
}
}
+type fileConfigJSON struct {
+ Server serverConfigJSON `json:"server"`
+ Browser browserConfigJSON `json:"browser"`
+ InstanceDefaults instanceDefaultsConfigJSON `json:"instanceDefaults"`
+ Security securityConfigJSON `json:"security"`
+ Profiles profilesConfigJSON `json:"profiles"`
+ MultiInstance multiInstanceConfigJSON `json:"multiInstance"`
+ Timeouts timeoutsConfigJSON `json:"timeouts"`
+ Scheduler schedulerFileConfigJSON `json:"scheduler"`
+}
+
+type serverConfigJSON struct {
+ Port string `json:"port"`
+ Bind string `json:"bind"`
+ Token string `json:"token"`
+ StateDir string `json:"stateDir"`
+ Engine string `json:"engine"`
+}
+
+type browserConfigJSON struct {
+ ChromeVersion string `json:"version"`
+ ChromeBinary string `json:"binary"`
+ ChromeExtraFlags string `json:"extraFlags"`
+ ExtensionPaths []string `json:"extensionPaths"`
+}
+
+type instanceDefaultsConfigJSON struct {
+ Mode string `json:"mode"`
+ NoRestore *bool `json:"noRestore"`
+ Timezone string `json:"timezone"`
+ BlockImages *bool `json:"blockImages"`
+ BlockMedia *bool `json:"blockMedia"`
+ BlockAds *bool `json:"blockAds"`
+ MaxTabs *int `json:"maxTabs"`
+ MaxParallelTabs *int `json:"maxParallelTabs"`
+ UserAgent string `json:"userAgent"`
+ NoAnimations *bool `json:"noAnimations"`
+ StealthLevel string `json:"stealthLevel"`
+ TabEvictionPolicy string `json:"tabEvictionPolicy"`
+}
+
+type profilesConfigJSON struct {
+ BaseDir string `json:"baseDir"`
+ DefaultProfile string `json:"defaultProfile"`
+}
+
+type securityConfigJSON struct {
+ AllowEvaluate *bool `json:"allowEvaluate"`
+ AllowMacro *bool `json:"allowMacro"`
+ AllowScreencast *bool `json:"allowScreencast"`
+ AllowDownload *bool `json:"allowDownload"`
+ AllowUpload *bool `json:"allowUpload"`
+ MaxRedirects *int `json:"maxRedirects"`
+ Attach attachJSON `json:"attach"`
+ IDPI idpiConfigJSON `json:"idpi"`
+}
+
+type attachJSON struct {
+ Enabled *bool `json:"enabled"`
+ AllowHosts []string `json:"allowHosts"`
+ AllowSchemes []string `json:"allowSchemes"`
+}
+
+type idpiConfigJSON struct {
+ Enabled bool `json:"enabled"`
+ AllowedDomains []string `json:"allowedDomains"`
+ StrictMode bool `json:"strictMode"`
+ ScanContent bool `json:"scanContent"`
+ WrapContent bool `json:"wrapContent"`
+ CustomPatterns []string `json:"customPatterns"`
+ ScanTimeoutSec int `json:"scanTimeoutSec"`
+}
+
+type multiInstanceConfigJSON struct {
+ Strategy string `json:"strategy"`
+ AllocationPolicy string `json:"allocationPolicy"`
+ InstancePortStart *int `json:"instancePortStart"`
+ InstancePortEnd *int `json:"instancePortEnd"`
+ Restart multiInstanceRestartJSON `json:"restart"`
+}
+
+type multiInstanceRestartJSON struct {
+ MaxRestarts *int `json:"maxRestarts"`
+ InitBackoffSec *int `json:"initBackoffSec"`
+ MaxBackoffSec *int `json:"maxBackoffSec"`
+ StableAfterSec *int `json:"stableAfterSec"`
+}
+
+type timeoutsConfigJSON struct {
+ ActionSec int `json:"actionSec"`
+ NavigateSec int `json:"navigateSec"`
+ ShutdownSec int `json:"shutdownSec"`
+ WaitNavMs int `json:"waitNavMs"`
+}
+
+type schedulerFileConfigJSON struct {
+ Enabled *bool `json:"enabled"`
+ Strategy string `json:"strategy"`
+ MaxQueueSize *int `json:"maxQueueSize"`
+ MaxPerAgent *int `json:"maxPerAgent"`
+ MaxInflight *int `json:"maxInflight"`
+ MaxPerAgentFlight *int `json:"maxPerAgentInflight"`
+ ResultTTLSec *int `json:"resultTTLSec"`
+ WorkerCount *int `json:"workerCount"`
+}
+
+func copyStringSlice(items []string) []string {
+ if items == nil {
+ return []string{}
+ }
+ if len(items) == 0 {
+ return []string{}
+ }
+ return append([]string(nil), items...)
+}
+
+func (fc FileConfig) MarshalJSON() ([]byte, error) {
+ return json.Marshal(fileConfigJSON{
+ Server: serverConfigJSON{
+ Port: fc.Server.Port,
+ Bind: fc.Server.Bind,
+ Token: fc.Server.Token,
+ StateDir: fc.Server.StateDir,
+ Engine: fc.Server.Engine,
+ },
+ Browser: browserConfigJSON{
+ ChromeVersion: fc.Browser.ChromeVersion,
+ ChromeBinary: fc.Browser.ChromeBinary,
+ ChromeExtraFlags: fc.Browser.ChromeExtraFlags,
+ ExtensionPaths: copyStringSlice(fc.Browser.ExtensionPaths),
+ },
+ InstanceDefaults: instanceDefaultsConfigJSON{
+ Mode: fc.InstanceDefaults.Mode,
+ NoRestore: fc.InstanceDefaults.NoRestore,
+ Timezone: fc.InstanceDefaults.Timezone,
+ BlockImages: fc.InstanceDefaults.BlockImages,
+ BlockMedia: fc.InstanceDefaults.BlockMedia,
+ BlockAds: fc.InstanceDefaults.BlockAds,
+ MaxTabs: fc.InstanceDefaults.MaxTabs,
+ MaxParallelTabs: fc.InstanceDefaults.MaxParallelTabs,
+ UserAgent: fc.InstanceDefaults.UserAgent,
+ NoAnimations: fc.InstanceDefaults.NoAnimations,
+ StealthLevel: fc.InstanceDefaults.StealthLevel,
+ TabEvictionPolicy: fc.InstanceDefaults.TabEvictionPolicy,
+ },
+ Security: securityConfigJSON{
+ AllowEvaluate: fc.Security.AllowEvaluate,
+ AllowMacro: fc.Security.AllowMacro,
+ AllowScreencast: fc.Security.AllowScreencast,
+ AllowDownload: fc.Security.AllowDownload,
+ AllowUpload: fc.Security.AllowUpload,
+ MaxRedirects: fc.Security.MaxRedirects,
+ Attach: attachJSON{
+ Enabled: fc.Security.Attach.Enabled,
+ AllowHosts: copyStringSlice(fc.Security.Attach.AllowHosts),
+ AllowSchemes: copyStringSlice(fc.Security.Attach.AllowSchemes),
+ },
+ IDPI: idpiConfigJSON{
+ Enabled: fc.Security.IDPI.Enabled,
+ AllowedDomains: copyStringSlice(fc.Security.IDPI.AllowedDomains),
+ 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,
+ },
+ },
+ Profiles: profilesConfigJSON{
+ BaseDir: fc.Profiles.BaseDir,
+ DefaultProfile: fc.Profiles.DefaultProfile,
+ },
+ MultiInstance: multiInstanceConfigJSON{
+ Strategy: fc.MultiInstance.Strategy,
+ AllocationPolicy: fc.MultiInstance.AllocationPolicy,
+ InstancePortStart: fc.MultiInstance.InstancePortStart,
+ InstancePortEnd: fc.MultiInstance.InstancePortEnd,
+ Restart: multiInstanceRestartJSON{
+ MaxRestarts: fc.MultiInstance.Restart.MaxRestarts,
+ InitBackoffSec: fc.MultiInstance.Restart.InitBackoffSec,
+ MaxBackoffSec: fc.MultiInstance.Restart.MaxBackoffSec,
+ StableAfterSec: fc.MultiInstance.Restart.StableAfterSec,
+ },
+ },
+ Timeouts: timeoutsConfigJSON{
+ ActionSec: fc.Timeouts.ActionSec,
+ NavigateSec: fc.Timeouts.NavigateSec,
+ ShutdownSec: fc.Timeouts.ShutdownSec,
+ WaitNavMs: fc.Timeouts.WaitNavMs,
+ },
+ Scheduler: schedulerFileConfigJSON{
+ Enabled: fc.Scheduler.Enabled,
+ Strategy: fc.Scheduler.Strategy,
+ MaxQueueSize: fc.Scheduler.MaxQueueSize,
+ MaxPerAgent: fc.Scheduler.MaxPerAgent,
+ MaxInflight: fc.Scheduler.MaxInflight,
+ MaxPerAgentFlight: fc.Scheduler.MaxPerAgentFlight,
+ ResultTTLSec: fc.Scheduler.ResultTTLSec,
+ WorkerCount: fc.Scheduler.WorkerCount,
+ },
+ })
+}
+
// FileConfigFromRuntime converts the effective runtime configuration back into a
// nested file configuration shape.
func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {
diff --git a/internal/config/config_file_test.go b/internal/config/config_file_test.go
index e2f852d4..c0e01fbc 100644
--- a/internal/config/config_file_test.go
+++ b/internal/config/config_file_test.go
@@ -195,6 +195,49 @@ func TestDefaultFileConfigJSON(t *testing.T) {
}
}
+func TestFileConfigJSONPreservesExplicitZeroValues(t *testing.T) {
+ fc := DefaultFileConfig()
+ fc.Server.Bind = ""
+ fc.Browser.ExtensionPaths = []string{}
+ fc.InstanceDefaults.UserAgent = ""
+ fc.Security.IDPI.StrictMode = false
+ fc.Security.IDPI.AllowedDomains = []string{}
+ fc.Security.IDPI.CustomPatterns = []string{}
+
+ data, err := json.Marshal(fc)
+ if err != nil {
+ t.Fatalf("json.Marshal(FileConfig) error = %v", err)
+ }
+
+ var raw map[string]any
+ if err := json.Unmarshal(data, &raw); err != nil {
+ t.Fatalf("json.Unmarshal(FileConfig JSON) error = %v", err)
+ }
+
+ server := raw["server"].(map[string]any)
+ if bind, ok := server["bind"]; !ok || bind != "" {
+ t.Fatalf("server.bind = %#v, want explicit empty string", bind)
+ }
+
+ browser := raw["browser"].(map[string]any)
+ if ext, ok := browser["extensionPaths"]; !ok {
+ t.Fatal("browser.extensionPaths missing from JSON")
+ } else if items, ok := ext.([]any); !ok || len(items) != 0 {
+ t.Fatalf("browser.extensionPaths = %#v, want explicit empty list", ext)
+ }
+
+ security := raw["security"].(map[string]any)
+ idpi := security["idpi"].(map[string]any)
+ if strictMode, ok := idpi["strictMode"]; !ok || strictMode != false {
+ t.Fatalf("security.idpi.strictMode = %#v, want explicit false", strictMode)
+ }
+ if allowedDomains, ok := idpi["allowedDomains"]; !ok {
+ t.Fatal("security.idpi.allowedDomains missing from JSON")
+ } else if items, ok := allowedDomains.([]any); !ok || len(items) != 0 {
+ t.Fatalf("security.idpi.allowedDomains = %#v, want explicit empty list", allowedDomains)
+ }
+}
+
func boolPtr(b bool) *bool {
return &b
}
diff --git a/internal/config/editor.go b/internal/config/editor.go
index e81442fb..a7ee981d 100644
--- a/internal/config/editor.go
+++ b/internal/config/editor.go
@@ -627,9 +627,63 @@ func LoadFileConfig() (*FileConfig, string, error) {
if err := json.Unmarshal(data, &lc); err != nil {
return nil, configPath, fmt.Errorf("failed to parse legacy config: %w", err)
}
- fc = convertLegacyConfig(&lc)
+ defaults := DefaultFileConfig()
+ fc = &defaults
+ legacy := convertLegacyConfig(&lc)
+ if legacy.Server.Port != "" {
+ fc.Server.Port = legacy.Server.Port
+ }
+ if legacy.Server.Token != "" {
+ fc.Server.Token = legacy.Server.Token
+ }
+ if legacy.Server.StateDir != "" {
+ fc.Server.StateDir = legacy.Server.StateDir
+ }
+ if legacy.InstanceDefaults.Mode != "" {
+ fc.InstanceDefaults.Mode = legacy.InstanceDefaults.Mode
+ }
+ if legacy.InstanceDefaults.NoRestore != nil {
+ fc.InstanceDefaults.NoRestore = legacy.InstanceDefaults.NoRestore
+ }
+ if legacy.InstanceDefaults.MaxTabs != nil {
+ fc.InstanceDefaults.MaxTabs = legacy.InstanceDefaults.MaxTabs
+ }
+ if legacy.Profiles.BaseDir != "" {
+ fc.Profiles.BaseDir = legacy.Profiles.BaseDir
+ }
+ if legacy.Profiles.DefaultProfile != "" {
+ fc.Profiles.DefaultProfile = legacy.Profiles.DefaultProfile
+ }
+ if legacy.Security.AllowEvaluate != nil {
+ fc.Security.AllowEvaluate = legacy.Security.AllowEvaluate
+ }
+ if legacy.Security.AllowMacro != nil {
+ fc.Security.AllowMacro = legacy.Security.AllowMacro
+ }
+ if legacy.Security.AllowScreencast != nil {
+ fc.Security.AllowScreencast = legacy.Security.AllowScreencast
+ }
+ if legacy.Security.AllowDownload != nil {
+ fc.Security.AllowDownload = legacy.Security.AllowDownload
+ }
+ if legacy.Security.AllowUpload != nil {
+ fc.Security.AllowUpload = legacy.Security.AllowUpload
+ }
+ if legacy.Timeouts.ActionSec != 0 {
+ fc.Timeouts.ActionSec = legacy.Timeouts.ActionSec
+ }
+ if legacy.Timeouts.NavigateSec != 0 {
+ fc.Timeouts.NavigateSec = legacy.Timeouts.NavigateSec
+ }
+ if legacy.MultiInstance.InstancePortStart != nil {
+ fc.MultiInstance.InstancePortStart = legacy.MultiInstance.InstancePortStart
+ }
+ if legacy.MultiInstance.InstancePortEnd != nil {
+ fc.MultiInstance.InstancePortEnd = legacy.MultiInstance.InstancePortEnd
+ }
} else {
- fc = &FileConfig{}
+ defaults := DefaultFileConfig()
+ fc = &defaults
if err := json.Unmarshal(data, fc); err != nil {
return nil, configPath, fmt.Errorf("failed to parse config: %w", err)
}
diff --git a/internal/config/editor_test.go b/internal/config/editor_test.go
index 1339af00..d988ccc6 100644
--- a/internal/config/editor_test.go
+++ b/internal/config/editor_test.go
@@ -356,6 +356,44 @@ func TestLoadAndSaveFileConfig(t *testing.T) {
}
}
+func TestLoadAndSaveFileConfigPreservesExplicitZeroValues(t *testing.T) {
+ tmpDir := t.TempDir()
+ configPath := filepath.Join(tmpDir, "config.json")
+ _ = os.Setenv("PINCHTAB_CONFIG", configPath)
+ defer func() { _ = os.Unsetenv("PINCHTAB_CONFIG") }()
+
+ fc := DefaultFileConfig()
+ fc.Server.Bind = ""
+ fc.Server.Token = ""
+ fc.Browser.ExtensionPaths = []string{}
+ fc.InstanceDefaults.UserAgent = ""
+ fc.Security.IDPI.StrictMode = false
+ fc.Security.IDPI.AllowedDomains = []string{}
+ fc.Security.IDPI.CustomPatterns = []string{}
+
+ if err := SaveFileConfig(&fc, configPath); err != nil {
+ t.Fatalf("SaveFileConfig() error = %v", err)
+ }
+
+ loaded, _, err := LoadFileConfig()
+ if err != nil {
+ t.Fatalf("LoadFileConfig() error = %v", err)
+ }
+
+ if loaded.Server.Bind != "" {
+ t.Errorf("loaded bind = %q, want empty string", loaded.Server.Bind)
+ }
+ if loaded.Security.IDPI.StrictMode {
+ t.Errorf("loaded strictMode = %v, want false", loaded.Security.IDPI.StrictMode)
+ }
+ if len(loaded.Security.IDPI.AllowedDomains) != 0 {
+ t.Errorf("loaded allowedDomains = %v, want empty list", loaded.Security.IDPI.AllowedDomains)
+ }
+ if len(loaded.Browser.ExtensionPaths) != 0 {
+ t.Errorf("loaded extensionPaths = %v, want empty list", loaded.Browser.ExtensionPaths)
+ }
+}
+
func TestParseBool(t *testing.T) {
tests := []struct {
input string
diff --git a/internal/dashboard/config_api.go b/internal/dashboard/config_api.go
index 002371e8..b0211a8b 100644
--- a/internal/dashboard/config_api.go
+++ b/internal/dashboard/config_api.go
@@ -3,7 +3,6 @@ package dashboard
import (
"encoding/json"
"net/http"
- "strings"
"sync"
"time"
@@ -113,18 +112,12 @@ func (c *ConfigAPI) HandleGetConfig(w http.ResponseWriter, r *http.Request) {
}
func (c *ConfigAPI) HandlePutConfig(w http.ResponseWriter, r *http.Request) {
- var incoming config.FileConfig
- if err := json.NewDecoder(r.Body).Decode(&incoming); err != nil {
+ normalized := config.DefaultFileConfig()
+ if err := json.NewDecoder(r.Body).Decode(&normalized); err != nil {
web.ErrorCode(w, 400, "bad_config_json", "invalid config payload", false, nil)
return
}
- normalized, err := normalizeFileConfig(&incoming)
- if err != nil {
- web.Error(w, 400, err)
- return
- }
-
if errs := config.ValidateFileConfig(&normalized); len(errs) > 0 {
messages := make([]string, 0, len(errs))
for _, validationErr := range errs {
@@ -220,12 +213,8 @@ func (c *ConfigAPI) currentConfig() (config.FileConfig, string, []string, error)
if err != nil {
return config.FileConfig{}, "", nil, err
}
- normalized, err := normalizeFileConfig(fc)
- if err != nil {
- return config.FileConfig{}, "", nil, err
- }
- restartReasons := c.restartReasonsFor(normalized)
- return normalized, path, restartReasons, nil
+ restartReasons := c.restartReasonsFor(*fc)
+ return *fc, path, restartReasons, nil
}
func (c *ConfigAPI) restartReasonsFor(next config.FileConfig) []string {
@@ -256,24 +245,3 @@ func sameIntPtr(a, b *int) bool {
}
return *a == *b
}
-
-func normalizeFileConfig(fc *config.FileConfig) (config.FileConfig, error) {
- base := config.DefaultFileConfig()
- if fc == nil {
- return base, nil
- }
-
- data, err := json.Marshal(fc)
- if err != nil {
- return config.FileConfig{}, err
- }
- patch := strings.TrimSpace(string(data))
- if patch == "" || patch == "null" || patch == "{}" {
- return base, nil
- }
-
- if err := config.PatchConfigJSON(&base, patch); err != nil {
- return config.FileConfig{}, err
- }
- return base, nil
-}