fix(browser,stagehand): contain Chrome egress with an SSRF-validating proxy
Chrome's --host-resolver-rules only glob-matches host strings, so the CIDR entries (127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 169.254.0.0/16, 192.168.0.0/16) never matched: pages could fetch private IP literals and names resolving to private IPs, and the live SSRF test hung dialing 169.254.169.254 until its deadline. Replace the rules with web.EgressProxy, a loopback HTTP proxy (CONNECT and absolute-URI HTTP) that resolves each destination, refuses it if any address is private, and dials the validated IP directly. Chrome is pointed at it with --proxy-server and <-loopback>, and WebRTC is limited to proxied UDP. Stagehand's local mode allows only Chrome's own debugging port through, which its extension needs. SafeHTTPClient and the proxy now share one safe dialer, which races the validated addresses happy-eyeballs style so dual-stack hosts with broken IPv6 don't stall. isPrivateIP also covers multicast, reserved, benchmark, Teredo and NAT64/6to4/IPv4-compatible addresses embedding a private IPv4.
This commit is contained in:
1 parent
49616eec19
commit
60e6077408
10 files changed
+871
-101
No files matched your search
@@ -4,23 +4,12 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHostResolverRules_BlocksPrivateRanges(t *testing.T) {
|
||||
require.Contains(t, hostResolverRules, "127.0.0.0/8")
|
||||
require.Contains(t, hostResolverRules, "169.254.0.0/16")
|
||||
require.Contains(t, hostResolverRules, "10.0.0.0/8")
|
||||
require.Contains(t, hostResolverRules, "192.168.0.0/16")
|
||||
require.Contains(t, hostResolverRules, "172.16.0.0/12")
|
||||
require.Contains(t, hostResolverRules, "localhost")
|
||||
require.True(t, strings.Contains(hostResolverRules, "~NOTFOUND"))
|
||||
}
|
||||
|
||||
func TestBrowserToolName(t *testing.T) {
|
||||
tool := &BrowserTool{}
|
||||
assert.Equal(t, "browser", tool.Name())
|
||||
|
||||
Reference in new issue
Block a user