fix(browser): block private-IP resolution via host-resolver-rules (S3)

This commit is contained in:
sausheong committed 2026-06-13 11:25:22 +08:00
1 parent 7d85074509
commit 01b55a1446
3 files changed
+54

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
//go:build live
package browser
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
// TestInPageFetchPrivateIPBlocked_Live verifies host-resolver-rules stops an
// in-page fetch to a metadata IP. Requires a real Chrome. Run:
// go test -tags live ./tools/browser/ -run TestInPageFetchPrivateIPBlocked_Live
func TestInPageFetchPrivateIPBlocked_Live(t *testing.T) {
tool := NewBrowserTool()
defer tool.Shutdown()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
res, err := tool.Execute(ctx, []byte(`{"action":"evaluate","url":"https://example.com","session":"ssrf","script":"fetch('http://169.254.169.254/').then(()=>'REACHED').catch(e=>'BLOCKED:'+e)"}`))
require.NoError(t, err)
require.NotContains(t, res.Output, "REACHED")
}