High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(security): add trustLoopbackProxy escape hatch for system-proxy users
Xuheng Liu2565d456200c
diff --git a/internal/config/config_file.go b/internal/config/config_file.goindex 07dcff22..55fe462a 100644--- a/internal/config/config_file.go+++ b/internal/config/config_file.go@@ -132,6 +132,7 @@ func DefaultFileConfig() FileConfig {uploadMaxFileBytes := DefaultUploadMaxFileBytesuploadMaxTotalBytes := DefaultUploadMaxTotalBytesmaxRedirects := -1+ trustLoopbackProxy := falseattachEnabled := falseactivityEnabled := trueactivitySessionIdleSec := 1800@@ -194,6 +195,7 @@ func DefaultFileConfig() FileConfig {UploadMaxFileBytes: &uploadMaxFileBytes,UploadMaxTotalBytes: &uploadMaxTotalBytes,MaxRedirects: &maxRedirects,+ TrustLoopbackProxy: &trustLoopbackProxy,Attach: AttachConfig{Enabled: &attachEnabled,AllowHosts: []string{"127.0.0.1", "localhost", "::1"},diff --git a/internal/config/config_file_json.go b/internal/config/config_file_json.goindex 893bfbb1..39965fdc 100644--- a/internal/config/config_file_json.go+++ b/internal/config/config_file_json.go@@ -78,6 +78,7 @@ type securityConfigJSON struct {MaxRedirects *int `json:"maxRedirects"`TrustedProxyCIDRs []string `json:"trustedProxyCIDRs"`TrustedResolveCIDRs []string `json:"trustedResolveCIDRs"`+ TrustLoopbackProxy *bool `json:"trustLoopbackProxy"`Attach attachJSON `json:"attach"`IDPI idpiConfigJSON `json:"idpi"`}diff --git a/internal/config/config_file_marshal.go b/internal/config/config_file_marshal.goindex 98303bc8..c79a68af 100644--- a/internal/config/config_file_marshal.go+++ b/internal/config/config_file_marshal.go@@ -110,6 +110,7 @@ func (fc FileConfig) MarshalJSON() ([]byte, error) {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),@@ -262,6 +263,7 @@ func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {uploadMaxFileBytes := cfg.EffectiveUploadMaxFileBytes()uploadMaxTotalBytes := cfg.EffectiveUploadMaxTotalBytes()maxRedirects := cfg.MaxRedirects+ trustLoopbackProxy := cfg.TrustLoopbackProxyattachEnabled := cfg.AttachEnabledstart := cfg.InstancePortStartend := cfg.InstancePortEnd@@ -361,6 +363,7 @@ func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {MaxRedirects: &maxRedirects,TrustedProxyCIDRs: append([]string(nil), cfg.TrustedProxyCIDRs...),TrustedResolveCIDRs: append([]string(nil), cfg.TrustedResolveCIDRs...),+ TrustLoopbackProxy: &trustLoopbackProxy,Attach: AttachConfig{Enabled: &attachEnabled,AllowHosts: append([]string(nil), cfg.AttachAllowHosts...),diff --git a/internal/config/config_load.go b/internal/config/config_load.goindex 58b77506..c29bafbc 100644--- a/internal/config/config_load.go+++ b/internal/config/config_load.go@@ -305,6 +305,9 @@ func applyFileConfig(cfg *RuntimeConfig, fc *FileConfig) {cfg.AttachAllowSchemes = append([]string(nil), fc.Security.Attach.AllowSchemes...)cfg.TrustedProxyCIDRs = append([]string(nil), fc.Security.TrustedProxyCIDRs...)cfg.TrustedResolveCIDRs = append([]string(nil), fc.Security.TrustedResolveCIDRs...)+ if fc.Security.TrustLoopbackProxy != nil {+ cfg.TrustLoopbackProxy = *fc.Security.TrustLoopbackProxy+ }// IDPI – copy the whole struct; individual fields have safe zero-value defaults.cfg.IDPI = fc.Security.IDPIcfg.AllowedDomains = effectiveSecurityAllowedDomains(fc.Security)diff --git a/internal/config/config_types.go b/internal/config/config_types.goindex 56934111..de09d323 100644--- a/internal/config/config_types.go+++ b/internal/config/config_types.go@@ -42,6 +42,7 @@ type RuntimeConfig struct {MaxRedirects int // Max HTTP redirects (-1=unlimited, 0=none, default=-1)TrustedProxyCIDRs []string // CIDRs/IPs whose RemoteIPAddress is trusted in navigation responses (e.g. internal proxy)TrustedResolveCIDRs []string // CIDRs/IPs allowed when a navigation target resolves to non-public addresses+ TrustLoopbackProxy bool // when true, navigation responses with a loopback RemoteIPAddress (e.g. system HTTP/SOCKS proxy on 127.0.0.1) are not blocked; default false// Browser/instance settingsHeadless bool@@ -339,6 +340,7 @@ type SecurityConfig struct {MaxRedirects *int `json:"maxRedirects,omitempty"`TrustedProxyCIDRs []string `json:"trustedProxyCIDRs,omitempty"`TrustedResolveCIDRs []string `json:"trustedResolveCIDRs,omitempty"`+ TrustLoopbackProxy *bool `json:"trustLoopbackProxy,omitempty"`Attach AttachConfig `json:"attach,omitempty"`IDPI IDPIConfig `json:"idpi,omitempty"`}diff --git a/internal/config/editor_get.go b/internal/config/editor_get.goindex c50d7a61..9e7f3781 100644--- a/internal/config/editor_get.go+++ b/internal/config/editor_get.go@@ -242,6 +242,8 @@ func getSecurityField(s *SecurityConfig, field string) (string, error) {return strings.Join(s.TrustedProxyCIDRs, ","), nilcase "trustedResolveCIDRs":return strings.Join(s.TrustedResolveCIDRs, ","), nil+ case "trustLoopbackProxy":+ return formatBoolPtr(s.TrustLoopbackProxy), nildefault:return "", fmt.Errorf("unknown field security.%s", field)}diff --git a/internal/config/editor_set.go b/internal/config/editor_set.goindex 1e0a3085..5832475b 100644--- a/internal/config/editor_set.go+++ b/internal/config/editor_set.go@@ -384,6 +384,8 @@ func setSecurityField(s *SecurityConfig, field, value string) error {s.AllowNetworkIntercept = &bcase "enableActionGuards":s.EnableActionGuards = &b+ case "trustLoopbackProxy":+ s.TrustLoopbackProxy = &bdefault:return fmt.Errorf("unknown field security.%s", field)}diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.goindex ae3cbc80..fa6bed92 100644--- a/internal/handlers/navigation.go+++ b/internal/handlers/navigation.go@@ -109,7 +109,7 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {httpx.Error(w, http.StatusForbidden, err)return}- trustedCIDRs := parseCIDRs(h.Config.TrustedProxyCIDRs)+ trustedCIDRs := buildNavigateTrustedProxyCIDRs(h.Config)h.recordNavigateRequest(r, req.TabID, req.URL)// --- Lite engine fast path ---diff --git a/internal/handlers/navigation_policy.go b/internal/handlers/navigation_policy.goindex 176b5d8a..b4d53137 100644--- a/internal/handlers/navigation_policy.go+++ b/internal/handlers/navigation_policy.go@@ -15,9 +15,39 @@ import ("github.com/chromedp/cdproto/network""github.com/chromedp/chromedp"+ "github.com/pinchtab/pinchtab/internal/config""github.com/pinchtab/pinchtab/internal/netguard")+// loopbackProxyCIDRs are the CIDRs implicitly trusted as legitimate proxy hops+// when security.trustLoopbackProxy is enabled. Covers IPv4 and IPv6 loopback.+var loopbackProxyCIDRs = func() []*net.IPNet {+ cidrs := make([]*net.IPNet, 0, 2)+ for _, s := range []string{"127.0.0.0/8", "::1/128"} {+ if _, n, err := net.ParseCIDR(s); err == nil {+ cidrs = append(cidrs, n)+ }+ }+ return cidrs+}()++// buildNavigateTrustedProxyCIDRs returns the list of trusted CIDRs used by the+// runtime navigation guard when checking the response RemoteIPAddress. It+// merges security.trustedProxyCIDRs with the implicit loopback list when+// security.trustLoopbackProxy is enabled, giving users a one-flag escape from+// the SSRF guard tripping on a local HTTP/SOCKS proxy hop (e.g. macOS system+// proxy on 127.0.0.1) without having to hand-craft a CIDR list.+func buildNavigateTrustedProxyCIDRs(cfg *config.RuntimeConfig) []*net.IPNet {+ if cfg == nil {+ return nil+ }+ trusted := parseCIDRs(cfg.TrustedProxyCIDRs)+ if cfg.TrustLoopbackProxy {+ trusted = append(trusted, loopbackProxyCIDRs...)+ }+ return trusted+}+const maxNavigateURLLen = 8 << 10type validatedNavigateTarget struct {diff --git a/internal/handlers/navigation_policy_test.go b/internal/handlers/navigation_policy_test.gonew file mode 100644index 00000000..e85d536c--- /dev/null+++ b/internal/handlers/navigation_policy_test.go@@ -0,0 +1,93 @@+package handlers++import (+ "net"+ "testing"++ "github.com/pinchtab/pinchtab/internal/config"+)++func TestBuildNavigateTrustedProxyCIDRs_NilConfig(t *testing.T) {+ if got := buildNavigateTrustedProxyCIDRs(nil); got != nil {+ t.Fatalf("buildNavigateTrustedProxyCIDRs(nil) = %v, want nil", got)+ }+}++func TestBuildNavigateTrustedProxyCIDRs_FlagOff(t *testing.T) {+ cfg := &config.RuntimeConfig{+ TrustedProxyCIDRs: []string{"10.0.0.0/8"},+ TrustLoopbackProxy: false,+ }+ got := buildNavigateTrustedProxyCIDRs(cfg)+ if len(got) != 1 {+ t.Fatalf("got %d CIDRs, want 1 (only the configured one); got=%v", len(got), got)+ }+ if got[0].String() != "10.0.0.0/8" {+ t.Errorf("got[0] = %s, want 10.0.0.0/8", got[0].String())+ }+ // Sanity: loopback must NOT be in the list when flag is off.+ if cidrsContainIP(got, net.ParseIP("127.0.0.1")) {+ t.Errorf("loopback 127.0.0.1 must not be trusted when TrustLoopbackProxy=false")+ }+}++func TestBuildNavigateTrustedProxyCIDRs_FlagOn(t *testing.T) {+ cfg := &config.RuntimeConfig{+ TrustedProxyCIDRs: []string{"10.0.0.0/8"},+ TrustLoopbackProxy: true,+ }+ got := buildNavigateTrustedProxyCIDRs(cfg)+ if !cidrsContainIP(got, net.ParseIP("127.0.0.1")) {+ t.Errorf("127.0.0.1 must be trusted when TrustLoopbackProxy=true; got=%v", cidrStrings(got))+ }+ if !cidrsContainIP(got, net.ParseIP("::1")) {+ t.Errorf("::1 must be trusted when TrustLoopbackProxy=true; got=%v", cidrStrings(got))+ }+ // Existing configured CIDRs must still be present.+ if !cidrsContainIP(got, net.ParseIP("10.4.5.6")) {+ t.Errorf("configured CIDR 10.0.0.0/8 must remain trusted; got=%v", cidrStrings(got))+ }+ // Public IP must NOT be trusted.+ if cidrsContainIP(got, net.ParseIP("8.8.8.8")) {+ t.Errorf("public IP 8.8.8.8 must not be trusted; got=%v", cidrStrings(got))+ }+}++func TestValidateNavigateRemoteIPAddress_LoopbackProxyAllowed(t *testing.T) {+ cfg := &config.RuntimeConfig{TrustLoopbackProxy: true}+ trusted := buildNavigateTrustedProxyCIDRs(cfg)++ for _, ip := range []string{"127.0.0.1", "127.255.255.254", "::1"} {+ if err := validateNavigateRemoteIPAddress(ip, trusted, nil); err != nil {+ t.Errorf("validateNavigateRemoteIPAddress(%q) with TrustLoopbackProxy=true returned %v, want nil", ip, err)+ }+ }+}++func TestValidateNavigateRemoteIPAddress_LoopbackProxyBlockedByDefault(t *testing.T) {+ cfg := &config.RuntimeConfig{TrustLoopbackProxy: false}+ trusted := buildNavigateTrustedProxyCIDRs(cfg)++ for _, ip := range []string{"127.0.0.1", "::1"} {+ if err := validateNavigateRemoteIPAddress(ip, trusted, nil); err == nil {+ t.Errorf("validateNavigateRemoteIPAddress(%q) with TrustLoopbackProxy=false returned nil, want SSRF block", ip)+ }+ }+}++func cidrsContainIP(cidrs []*net.IPNet, ip net.IP) bool {+ for _, c := range cidrs {+ if c.Contains(ip) {+ return true+ }+ }+ return false+}++func cidrStrings(cidrs []*net.IPNet) []string {+ out := make([]string, len(cidrs))+ for i, c := range cidrs {+ out[i] = c.String()+ }+ return out+}diff --git a/internal/handlers/tab_lifecycle.go b/internal/handlers/tab_lifecycle.goindex dd0c1d62..76cde90f 100644--- a/internal/handlers/tab_lifecycle.go+++ b/internal/handlers/tab_lifecycle.go@@ -32,7 +32,7 @@ func (h *Handlers) HandleTab(w http.ResponseWriter, r *http.Request) {case tabActionNew:var target *validatedNavigateTargettrustedResolveCIDRs := parseCIDRs(h.Config.TrustedResolveCIDRs)- trustedCIDRs := parseCIDRs(h.Config.TrustedProxyCIDRs)+ trustedCIDRs := buildNavigateTrustedProxyCIDRs(h.Config)if req.URL != "" && req.URL != "about:blank" {if err := validateNavigateURL(req.URL); err != nil {httpx.Error(w, 400, err)