High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: actionable IDPI block, clean server restart, and config show allowlist
Bosch0ac312ae226c
diff --git a/cmd/pinchtab/cmd_config_test.go b/cmd/pinchtab/cmd_config_test.goindex 194150bf..da45700e 100644--- a/cmd/pinchtab/cmd_config_test.go+++ b/cmd/pinchtab/cmd_config_test.go@@ -207,6 +207,38 @@ func TestConfigShowIncludesTrustLoopbackProxy(t *testing.T) {}}+func TestConfigShowIncludesIDPIAndAllowedDomains(t *testing.T) {+ configPath := filepath.Join(t.TempDir(), "config.json")+ t.Setenv("PINCHTAB_CONFIG", configPath)+ t.Setenv("PINCHTAB_TOKEN", "")++ fc := config.DefaultFileConfig()+ if err := config.SaveFileConfig(&fc, configPath); err != nil {+ t.Fatalf("SaveFileConfig() error = %v", err)+ }++ t.Cleanup(func() { rootCmd.SetArgs(nil) })++ output := captureStdout(t, func() {+ rootCmd.SetArgs([]string{"config", "show"})+ if err := rootCmd.Execute(); err != nil {+ t.Fatalf("Execute() error = %v", err)+ }+ })++ // The browsing allowlist is the most security-relevant setting a user edits;+ // it must be visible in `config show` so an edit can be confirmed there.+ if !strings.Contains(output, "Allowed Domains:") {+ t.Errorf("config show output missing 'Allowed Domains:'; got %q", output)+ }+ if !strings.Contains(output, "IDPI:") {+ t.Errorf("config show output missing 'IDPI:'; got %q", output)+ }+ if !strings.Contains(output, "localhost") {+ t.Errorf("expected default allowlist (localhost) in output; got %q", output)+ }+}+func TestConfigGetMasksServerToken(t *testing.T) {configPath := filepath.Join(t.TempDir(), "config.json")t.Setenv("PINCHTAB_CONFIG", configPath)diff --git a/cmd/pinchtab/cmd_server_background_unix.go b/cmd/pinchtab/cmd_server_background_unix.goindex 1a57b287..d17d24ae 100644--- a/cmd/pinchtab/cmd_server_background_unix.go+++ b/cmd/pinchtab/cmd_server_background_unix.go@@ -2,10 +2,44 @@package main-import "syscall"+import (+ "fmt"+ "os"+ "strings"+ "syscall"+)func processAlive(pid int) bool {- return syscall.Kill(pid, 0) == nil+ if syscall.Kill(pid, 0) != nil {+ return false+ }+ // A zombie (defunct) process still answers kill(pid, 0) because its PID+ // lingers in the table until the parent reaps it, but it is not running. In+ // containers whose PID 1 doesn't reap (e.g. a bare `sleep infinity`), a+ // SIGKILLed server stays a zombie — which would otherwise make stop/restart+ // report a false "did not exit" failure and refuse to start over it. Treat a+ // zombie as dead. (The official image's dumb-init reaps, so this only bites+ // minimal/init-less containers, but the check is correct everywhere.)+ return !processIsZombie(pid)+}++// processIsZombie reports whether pid is in the Linux zombie ("Z") state. It+// reads /proc/<pid>/stat; where /proc is absent (e.g. macOS, where launchd+// reaps and this case doesn't arise) it returns false and processAlive keeps+// its plain kill(0) semantics.+func processIsZombie(pid int) bool {+ data, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))+ if err != nil {+ return false+ }+ // Format: "<pid> (<comm>) <state> ...". comm may contain spaces and ')', so+ // scan past the final ')' before reading the single-char state field.+ s := string(data)+ close := strings.LastIndexByte(s, ')')+ if close < 0 || close+2 >= len(s) {+ return false+ }+ return s[close+2] == 'Z'}func stopProcess(pid int) error {diff --git a/internal/cli/report/config_report.go b/internal/cli/report/config_report.goindex c21e10f0..6ab9abd3 100644--- a/internal/cli/report/config_report.go+++ b/internal/cli/report/config_report.go@@ -23,6 +23,8 @@ func HandleConfigShow(cfg *config.RuntimeConfig) {fmt.Printf(" Cookies: %v\n", cfg.AllowCookies)fmt.Printf(" Upload: %v\n", cfg.AllowUpload)fmt.Printf(" Trust Loopback Proxy: %v\n", cfg.TrustLoopbackProxy)+ fmt.Printf(" IDPI: %v\n", cfg.IDPI.Enabled)+ fmt.Printf(" Allowed Domains: %v\n", cfg.AllowedDomains)fmt.Println()fmt.Println(styleStdout(headingStyle, "Browser / Instance Defaults"))fmt.Printf(" Headless: %v\n", cfg.Headless)diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.goindex 4c85e76f..b40440bd 100644--- a/internal/handlers/navigation.go+++ b/internal/handlers/navigation.go@@ -188,6 +188,18 @@ func (h *Handlers) resolveNavigateBrowser(w http.ResponseWriter, r *http.Requestreturn routing, true}+// idpiAllowlistHint appends a copy-pasteable remediation to an IDPI domain-block+// error so the user isn't left knowing only the cause. Widening the allowlist+// reduces isolation, so the hint says so and points at the security guide.+func idpiAllowlistHint(url string) string {+ host, ok := navguard.ExtractHost(url)+ if !ok || strings.TrimSpace(host) == "" {+ return ""+ }+ return fmt.Sprintf(". To allow it, add the host: `pinchtab config set security.allowedDomains \"…,%s\"` "++ "then `pinchtab server restart` — this widens what automation may reach (see docs/guides/security.md)", host)+}+// validateNavigateTargets runs URL validation, the IDPI domain guard, and SSRF// target resolution, recording the navigate request on both the blocked and// accepted paths. On success it returns the resolved target and trusted-proxy CIDRs.@@ -201,7 +213,7 @@ func (h *Handlers) validateNavigateTargets(w http.ResponseWriter, r *http.RequesdomainResult := h.IDPIGuard.CheckDomain(url)if domainResult.Blocked {h.recordNavigateRequest(r, tabID, url)- httpx.Error(w, http.StatusForbidden, fmt.Errorf("navigation blocked by IDPI: %s", domainResult.Reason))+ httpx.Error(w, http.StatusForbidden, fmt.Errorf("navigation blocked by IDPI: %s%s", domainResult.Reason, idpiAllowlistHint(url)))return navTargets{}, false}if domainResult.Threat {diff --git a/internal/handlers/navigation_idpi_hint_test.go b/internal/handlers/navigation_idpi_hint_test.gonew file mode 100644index 00000000..0adfd860--- /dev/null+++ b/internal/handlers/navigation_idpi_hint_test.go@@ -0,0 +1,24 @@+package handlers++import (+ "strings"+ "testing"+)++func TestIDPIAllowlistHint(t *testing.T) {+ hint := idpiAllowlistHint("https://example.com/some/path")+ if !strings.Contains(hint, "example.com") {+ t.Errorf("hint should name the blocked host; got %q", hint)+ }+ if !strings.Contains(hint, "security.allowedDomains") {+ t.Errorf("hint should name the allowlist config key; got %q", hint)+ }+ if !strings.Contains(hint, "server restart") {+ t.Errorf("hint should remind the user to restart; got %q", hint)+ }++ // Hostless targets (e.g. about:blank) can't be allowlisted, so no hint.+ if got := idpiAllowlistHint("about:blank"); got != "" {+ t.Errorf("expected empty hint for hostless url; got %q", got)+ }+}