High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor(navguard): drop the receiver-ignoring validator method and a test-only wrapper
Luigi Agostibaa4cf24c243
diff --git a/internal/handlers/navigation_policy.go b/internal/handlers/navigation_policy.goindex c05b7603..e311704f 100644--- a/internal/handlers/navigation_policy.go+++ b/internal/handlers/navigation_policy.go@@ -4,7 +4,6 @@ import ("context""fmt""net"- "net/netip""sync""github.com/pinchtab/pinchtab/internal/bridge"@@ -95,10 +94,6 @@ func validateNavigateTarget(raw string, allowExplicitInternal bool, trustedResolreturn v.ValidateTarget(context.Background(), raw, allowExplicitInternal)}-func validateNavigateRemoteIPAddress(raw string, trustedCIDRs []*net.IPNet, trustedIPs []netip.Addr) error {- return navguard.ValidateRemoteIP(raw, trustedCIDRs, trustedIPs)-}-func parseCIDRs(raw []string) []*net.IPNet {return navguard.ParseCIDRs(raw)}diff --git a/internal/handlers/navigation_policy_test.go b/internal/handlers/navigation_policy_test.goindex e85d536c..ae102ddb 100644--- a/internal/handlers/navigation_policy_test.go+++ b/internal/handlers/navigation_policy_test.go@@ -5,6 +5,7 @@ import ("testing""github.com/pinchtab/pinchtab/internal/config"+ "github.com/pinchtab/pinchtab/internal/navguard")func TestBuildNavigateTrustedProxyCIDRs_NilConfig(t *testing.T) {@@ -58,8 +59,8 @@ func TestValidateNavigateRemoteIPAddress_LoopbackProxyAllowed(t *testing.T) {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)+ if err := navguard.ValidateRemoteIP(ip, trusted, nil); err != nil {+ t.Errorf("navguard.ValidateRemoteIP(%q) with TrustLoopbackProxy=true returned %v, want nil", ip, err)}}}@@ -69,8 +70,8 @@ func TestValidateNavigateRemoteIPAddress_LoopbackProxyBlockedByDefault(t *testintrusted := 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)+ if err := navguard.ValidateRemoteIP(ip, trusted, nil); err == nil {+ t.Errorf("navguard.ValidateRemoteIP(%q) with TrustLoopbackProxy=false returned nil, want SSRF block", ip)}}}diff --git a/internal/handlers/navigation_test.go b/internal/handlers/navigation_test.goindex 09759193..c4db8142 100644--- a/internal/handlers/navigation_test.go+++ b/internal/handlers/navigation_test.go@@ -380,13 +380,13 @@ func TestHandleNavigate_AllowsPrivateIPWithTrustedResolveCIDR(t *testing.T) {}func TestValidateNavigateRemoteIPAddress_AllowsExactTrustedResolvedIP(t *testing.T) {- if err := validateNavigateRemoteIPAddress("10.1.2.3", nil, []netip.Addr{netip.MustParseAddr("10.1.2.3")}); err != nil {+ if err := navguard.ValidateRemoteIP("10.1.2.3", nil, []netip.Addr{netip.MustParseAddr("10.1.2.3")}); err != nil {t.Fatalf("expected exact trusted resolved IP to be allowed, got %v", err)}}func TestValidateNavigateRemoteIPAddress_RejectsDifferentIPInSameCIDR(t *testing.T) {- err := validateNavigateRemoteIPAddress("10.1.2.4", nil, []netip.Addr{netip.MustParseAddr("10.1.2.3")})+ err := navguard.ValidateRemoteIP("10.1.2.4", nil, []netip.Addr{netip.MustParseAddr("10.1.2.3")})if err == nil {t.Fatal("expected different runtime IP in same CIDR to be blocked")}diff --git a/internal/navguard/guard_integration_test.go b/internal/navguard/guard_integration_test.goindex 1a039e4b..bdbb9582 100644--- a/internal/navguard/guard_integration_test.go+++ b/internal/navguard/guard_integration_test.go@@ -21,7 +21,7 @@ func TestIntegration_FullPipeline_PublicURLAllowed(t *testing.T) {v := &Validator{}rawURL := "https://example.com/page"- if err := v.ValidateURL(rawURL); err != nil {+ if err := ValidateURL(rawURL); err != nil {t.Fatalf("ValidateURL failed: %v", err)}@@ -51,7 +51,7 @@ func TestIntegration_FullPipeline_PrivateIPBlocked(t *testing.T) {v := &Validator{}rawURL := "https://internal-service.example.com/api"- if err := v.ValidateURL(rawURL); err != nil {+ if err := ValidateURL(rawURL); err != nil {t.Fatalf("ValidateURL failed: %v", err)}@@ -74,7 +74,7 @@ func TestIntegration_FullPipeline_AllowedDomainPermitsPrivateIP(t *testing.T) {v := &Validator{}rawURL := "https://trusted-internal.corp.example.com/dashboard"- if err := v.ValidateURL(rawURL); err != nil {+ if err := ValidateURL(rawURL); err != nil {t.Fatalf("ValidateURL failed: %v", err)}@@ -121,7 +121,7 @@ func TestIntegration_FullPipeline_TrustedCIDRBypass(t *testing.T) {}rawURL := "https://k8s-service.internal.example.com/health"- if err := v.ValidateURL(rawURL); err != nil {+ if err := ValidateURL(rawURL); err != nil {t.Fatalf("ValidateURL failed: %v", err)}diff --git a/internal/navguard/url.go b/internal/navguard/url.goindex 6bb78460..b31d8faa 100644--- a/internal/navguard/url.go+++ b/internal/navguard/url.go@@ -12,12 +12,9 @@ const MaxURLLen = 8 << 10// ValidateURL checks that raw is a well-formed, scheme-safe navigation URL.// It allows http, https, about:blank, and bare hostnames (no scheme).-func (v *Validator) ValidateURL(raw string) error {- return ValidateURL(raw)-}--// ValidateURL is the standalone (non-method) URL validator, usable without a-// Validator instance.+//+// Not a Validator method: the answer depends on nothing a Validator carries, and+// hanging it off one implied that TrustedResolveCIDRs applied to it.func ValidateURL(raw string) error {return ValidateURLAllowingFile(raw, false)}