High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: warn when a running server enforces stale security config (m4)
Boschff035342ee00
diff --git a/cmd/pinchtab/cmd_security.go b/cmd/pinchtab/cmd_security.goindex 0ec669cf..92bd6277 100644--- a/cmd/pinchtab/cmd_security.go+++ b/cmd/pinchtab/cmd_security.go@@ -3,6 +3,7 @@ package mainimport ("fmt""os"+ "strings""github.com/pinchtab/pinchtab/internal/cli""github.com/pinchtab/pinchtab/internal/config"@@ -42,7 +43,31 @@ func init() {rootCmd.AddCommand(securityCmd)}+// printEnforcedDriftWarning flags when a server is running but was started with+// a different config than what's now on disk — i.e. the posture printed below is+// the user's intent, not necessarily what the live server enforces. The IDPI+// guard and allowlist are snapshotted at boot, so an edit without a restart left+// the running server enforcing stale policy with nothing signalling it; this is+// that signal.+func printEnforcedDriftWarning(cfg *config.RuntimeConfig) {+ if cfg == nil {+ return+ }+ snap, state := fetchHealthSnapshotWithToken(cfg.Port, resolveCLIToken(cfg))+ if state != healthSnapshotRunning || snap == nil || !snap.RestartRequired {+ return+ }+ fmt.Println(cli.StyleStdout(cli.WarningStyle,+ " ⚠ The running server started with a different config — the settings below are not all in effect yet."))+ if len(snap.RestartReasons) > 0 {+ fmt.Printf(" Pending (needs restart): %s\n", strings.Join(snap.RestartReasons, ", "))+ }+ fmt.Println(cli.StyleStdout(cli.MutedStyle, " Apply with: pinchtab server restart"))+ fmt.Println()+}+func printSecurityOverview(cfg *config.RuntimeConfig) {+ printEnforcedDriftWarning(cfg)posture := cli.AssessSecurityPosture(cfg)recommended := cli.RecommendedSecurityDefaultLines(cfg)warnings := cli.AssessSecurityWarnings(cfg)diff --git a/cmd/pinchtab/root_health.go b/cmd/pinchtab/root_health.goindex 58dea7bd..44ffedba 100644--- a/cmd/pinchtab/root_health.go+++ b/cmd/pinchtab/root_health.go@@ -13,10 +13,12 @@ import (// healthSnapshot is the subset of the /health response the landing banner and// `pinchtab health` care about.type healthSnapshot struct {- Status string `json:"status"`- Mode string `json:"mode"`- Version string `json:"version"`- Security *struct {+ Status string `json:"status"`+ Mode string `json:"mode"`+ Version string `json:"version"`+ RestartRequired bool `json:"restartRequired"`+ RestartReasons []string `json:"restartReasons"`+ Security *struct {Level string `json:"level"`AllowedDomains []string `json:"allowedDomains"`IDPIEnabled bool `json:"idpiEnabled"`@@ -51,7 +53,18 @@ func formatAllowedDomains(domains []string) string {// It is the only function here that performs network I/O, so callers that just// need to print help/landing text can avoid the probe latency entirely.func fetchHealthSnapshot(port string) (*healthSnapshot, healthSnapshotState) {- status, body, reachable := server.ProbeHealth(fmt.Sprintf("http://localhost:%s/health", port), 500*time.Millisecond, nil)+ return fetchHealthSnapshotWithToken(port, "")+}++// fetchHealthSnapshotWithToken is fetchHealthSnapshot with optional auth, so it+// can read fields like restartRequired from a server that requires auth on+// /health (the unauthenticated probe would just see a protected listener).+func fetchHealthSnapshotWithToken(port, token string) (*healthSnapshot, healthSnapshotState) {+ var headers map[string]string+ if strings.TrimSpace(token) != "" {+ headers = map[string]string{"Authorization": "Bearer " + token}+ }+ status, body, reachable := server.ProbeHealth(fmt.Sprintf("http://localhost:%s/health", port), 500*time.Millisecond, headers)if !reachable {return nil, healthSnapshotStopped}diff --git a/internal/dashboard/config_api_test.go b/internal/dashboard/config_api_test.goindex ed8bd79d..5086af36 100644--- a/internal/dashboard/config_api_test.go+++ b/internal/dashboard/config_api_test.go@@ -150,6 +150,22 @@ func TestRestartReasonsIncludeStealthLevel(t *testing.T) {}}+func TestRestartReasonsIncludeSecurityPolicy(t *testing.T) {+ cfg := config.DefaultFileConfig()+ api := NewConfigAPI(config.Load(), nil, nil, nil, nil, "test", time.Now())+ api.boot = cfg++ // Editing the allowlist changes the boot-snapshotted IDPI/security policy, so+ // it must register as restart-required (the running guard won't pick it up).+ next := cfg+ next.Security.AllowedDomains = append(append([]string(nil), cfg.Security.AllowedDomains...), "example.com")++ reasons := api.restartReasonsFor(next)+ if !slices.Contains(reasons, "Security policy") {+ t.Fatalf("restartReasonsFor() = %v, want Security policy", reasons)+ }+}+func TestHandleGetConfigRedactsToken(t *testing.T) {fc := config.DefaultFileConfig()fc.Server.Token = "secret-token"diff --git a/internal/dashboard/config_changes.go b/internal/dashboard/config_changes.goindex cd3ceeef..2d6c8de3 100644--- a/internal/dashboard/config_changes.go+++ b/internal/dashboard/config_changes.go@@ -77,8 +77,16 @@ func changedTargetProxyNames(current, next config.BrowserTargetsConfig) []string}func (c *ConfigAPI) restartReasonsFor(next config.FileConfig) []string {- reasons := make([]string, 0, 5)+ reasons := make([]string, 0, 6)+ // The IDPI guard, allowlist, and sensitive-endpoint policy are snapshotted+ // from the boot config when the server starts and are not rebuilt on a config+ // edit, so any change to the security block only takes effect after a restart.+ // Surfacing it here is what lets `pinchtab security`/`health` warn that the+ // running server is enforcing stale policy instead of silently diverging.+ if !reflect.DeepEqual(c.boot.Security, next.Security) {+ reasons = append(reasons, "Security policy")+ }if c.boot.Server.Port != next.Server.Port || c.boot.Server.Bind != next.Server.Bind {reasons = append(reasons, "Server address")}