High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: add security.trustedProxyCIDRs to bypass SSRF guard for known proxy IPs (#366)
Jamil Zakirov82bdc14f2b4f
diff --git a/internal/config/config_file.go b/internal/config/config_file.goindex bde90482..f893f0fc 100644--- a/internal/config/config_file.go+++ b/internal/config/config_file.go@@ -176,6 +176,7 @@ type securityConfigJSON struct {UploadMaxFileBytes *int `json:"uploadMaxFileBytes"`UploadMaxTotalBytes *int `json:"uploadMaxTotalBytes"`MaxRedirects *int `json:"maxRedirects"`+ TrustedProxyCIDRs []string `json:"trustedProxyCIDRs"`Attach attachJSON `json:"attach"`IDPI idpiConfigJSON `json:"idpi"`}@@ -296,6 +297,7 @@ func (fc FileConfig) MarshalJSON() ([]byte, error) {UploadMaxFileBytes: fc.Security.UploadMaxFileBytes,UploadMaxTotalBytes: fc.Security.UploadMaxTotalBytes,MaxRedirects: fc.Security.MaxRedirects,+ TrustedProxyCIDRs: copyStringSlice(fc.Security.TrustedProxyCIDRs),Attach: attachJSON{Enabled: fc.Security.Attach.Enabled,AllowHosts: copyStringSlice(fc.Security.Attach.AllowHosts),@@ -447,6 +449,7 @@ func FileConfigFromRuntime(cfg *RuntimeConfig) FileConfig {UploadMaxFileBytes: &uploadMaxFileBytes,UploadMaxTotalBytes: &uploadMaxTotalBytes,MaxRedirects: &maxRedirects,+ TrustedProxyCIDRs: append([]string(nil), cfg.TrustedProxyCIDRs...),Attach: AttachConfig{Enabled: &attachEnabled,AllowHosts: append([]string(nil), cfg.AttachAllowHosts...),diff --git a/internal/config/config_load.go b/internal/config/config_load.goindex 0c24ec1e..f37ed40a 100644--- a/internal/config/config_load.go+++ b/internal/config/config_load.go@@ -240,6 +240,7 @@ func applyFileConfig(cfg *RuntimeConfig, fc *FileConfig) {}cfg.AttachAllowHosts = append([]string(nil), fc.Security.Attach.AllowHosts...)cfg.AttachAllowSchemes = append([]string(nil), fc.Security.Attach.AllowSchemes...)+ cfg.TrustedProxyCIDRs = append([]string(nil), fc.Security.TrustedProxyCIDRs...)// IDPI – copy the whole struct; individual fields have safe zero-value defaults.cfg.IDPI = fc.Security.IDPIif fc.Observability.Activity.Enabled != nil {diff --git a/internal/config/config_types.go b/internal/config/config_types.goindex bbf14210..e9623c52 100644--- a/internal/config/config_types.go+++ b/internal/config/config_types.go@@ -27,7 +27,8 @@ type RuntimeConfig struct {UploadMaxFiles intUploadMaxFileBytes intUploadMaxTotalBytes int- MaxRedirects int // Max HTTP redirects (-1=unlimited, 0=none, default=-1)+ 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)// Browser/instance settingsHeadless bool@@ -190,6 +191,7 @@ type SecurityConfig struct {UploadMaxFileBytes *int `json:"uploadMaxFileBytes,omitempty"`UploadMaxTotalBytes *int `json:"uploadMaxTotalBytes,omitempty"`MaxRedirects *int `json:"maxRedirects,omitempty"`+ TrustedProxyCIDRs []string `json:"trustedProxyCIDRs,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 beff7f3c..ddbeeb08 100644--- a/internal/config/editor_get.go+++ b/internal/config/editor_get.go@@ -130,6 +130,8 @@ func getSecurityField(s *SecurityConfig, field string) (string, error) {return formatIntPtr(s.UploadMaxTotalBytes), nilcase "maxRedirects":return formatIntPtr(s.MaxRedirects), nil+ case "trustedProxyCIDRs":+ return strings.Join(s.TrustedProxyCIDRs, ","), nildefault:return "", fmt.Errorf("unknown field security.%s", field)}diff --git a/internal/config/editor_set.go b/internal/config/editor_set.goindex a27e543a..4b765d78 100644--- a/internal/config/editor_set.go+++ b/internal/config/editor_set.go@@ -142,6 +142,10 @@ func setSecurityField(s *SecurityConfig, field, value string) error {s.DownloadAllowedDomains = parseCSVList(value)return nil}+ if field == "trustedProxyCIDRs" {+ s.TrustedProxyCIDRs = parseCSVList(value)+ return nil+ }switch field {case "downloadMaxBytes":n, err := strconv.Atoi(value)diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.goindex 568583d7..2a8f2d06 100644--- a/internal/handlers/navigation.go+++ b/internal/handlers/navigation.go@@ -107,6 +107,7 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {httpx.Error(w, http.StatusForbidden, err)return}+ trustedCIDRs := parseCIDRs(h.Config.TrustedProxyCIDRs)h.recordNavigateRequest(r, req.TabID, req.URL)// --- Lite engine fast path ---@@ -185,7 +186,7 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {tCtx, tCancel := context.WithTimeout(newCtx, navTimeout)defer tCancel()go httpx.CancelOnClientDone(r.Context(), tCancel)- navGuard, err := installNavigateRuntimeGuard(tCtx, tCancel, target)+ navGuard, err := installNavigateRuntimeGuard(tCtx, tCancel, target, trustedCIDRs)if err != nil {httpx.Error(w, 500, fmt.Errorf("navigation guard: %w", err))return@@ -237,7 +238,7 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {tCtx, tCancel := context.WithTimeout(ctx, navTimeout)defer tCancel()go httpx.CancelOnClientDone(r.Context(), tCancel)- navGuard, err := installNavigateRuntimeGuard(tCtx, tCancel, target)+ navGuard, err := installNavigateRuntimeGuard(tCtx, tCancel, target, trustedCIDRs)if err != nil {httpx.Error(w, 500, fmt.Errorf("navigation guard: %w", err))returndiff --git a/internal/handlers/navigation_policy.go b/internal/handlers/navigation_policy.goindex a3bed2c4..483af8ef 100644--- a/internal/handlers/navigation_policy.go+++ b/internal/handlers/navigation_policy.go@@ -155,15 +155,39 @@ func extractNavigateHost(raw string) (string, bool) {return "", false}-func validateNavigateRemoteIPAddress(raw string) error {+func validateNavigateRemoteIPAddress(raw string, trustedCIDRs []*net.IPNet) error {normalized := netguard.NormalizeRemoteIP(raw)if err := netguard.ValidateRemoteIPAddress(raw); err != nil {+ if ip := net.ParseIP(normalized); ip != nil {+ for _, cidr := range trustedCIDRs {+ if cidr.Contains(ip) {+ return nil+ }+ }+ }return fmt.Errorf("navigation connected to blocked remote IP %s", normalized)}return nil}-func installNavigateRuntimeGuard(tCtx context.Context, tCancel context.CancelFunc, target *validatedNavigateTarget) (*navigateRuntimeGuard, error) {+func parseCIDRs(raw []string) []*net.IPNet {+ var nets []*net.IPNet+ for _, s := range raw {+ s = strings.TrimSpace(s)+ if s == "" {+ continue+ }+ if !strings.Contains(s, "/") {+ s += "/32"+ }+ if _, cidr, err := net.ParseCIDR(s); err == nil {+ nets = append(nets, cidr)+ }+ }+ return nets+}++func installNavigateRuntimeGuard(tCtx context.Context, tCancel context.CancelFunc, target *validatedNavigateTarget, trustedCIDRs []*net.IPNet) (*navigateRuntimeGuard, error) {if target == nil || target.allowInternal {return nil, nil}@@ -185,7 +209,7 @@ func installNavigateRuntimeGuard(tCtx context.Context, tCancel context.CancelFunif !guard.isMainDocumentResponse(string(e.RequestID)) {return}- if err := validateNavigateRemoteIPAddress(e.Response.RemoteIPAddress); err != nil {+ if err := validateNavigateRemoteIPAddress(e.Response.RemoteIPAddress, trustedCIDRs); err != nil {guard.setBlocked(err)tCancel()}