Files
ai/proxy/public_test.go
zeekay 99f2e88361 A tenant's URL is fetched by outbound's rule, and never read as a path
Every address a request names now reaches the network through one client,
github.com/hanzoai/outbound (proxy.Public), which judges the address at
the dial, on the IP the socket connects to, and re-dials and re-judges
every redirect.

What it replaces failed three ways. A message href was checked by
util.Fetchable and then fetched by a different client: the name was
resolved twice, so a rebinding answer passed the check, and a redirect
to 169.254.169.254 was followed unchecked. The check itself was
net.IP's predicates, which admit NAT64 64:ff9b::a9fe:a9fe, 6to4,
Teredo, 198.18/15, 240/4 and the TEST-NETs; proxy/public.go's routable
admitted the same. And /v1/ai/rag/embed's url and /v1/ai/rag/ingest's
files[].url had no check at all: a loopback or metadata URL was
fetched, and a scheme-less string was read off this machine's disk.

A tenant document now goes through txt.GetParsedTextFromAddress (http
and https only, over proxy.Public); txt.GetParsedTextFromUrl is for
addresses this system stored. The Go crawler fetches every page and
robots.txt through proxy.Public, and the browser engine is handed only
addresses outbound.Host finds public.
2026-10-18 22:21:42 -07:00

40 lines
1.1 KiB
Go

// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
package proxy
import (
"errors"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
"github.com/hanzoai/outbound"
)
// The client a tenant's address is fetched with is outbound's: a server on this
// network, and every spelling of the metadata endpoint, are refused with its
// sentinel before a byte is sent. The table that decides is outbound's own.
func TestPublicIsTheOutboundRule(t *testing.T) {
var reached atomic.Int32
srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { reached.Add(1) }))
defer srv.Close()
for _, u := range []string{
srv.URL,
"http://localhost/",
"http://169.254.169.254/latest/meta-data/",
"http://[fd00:ec2::254]/latest/meta-data/",
"http://[64:ff9b::a9fe:a9fe]/latest/meta-data/",
"http://[2002:a9fe:a9fe::1]/",
"http://198.18.0.1/",
"http://240.0.0.1/",
} {
if _, err := Public.Get(u); !errors.Is(err, outbound.ErrRefused) {
t.Errorf("GET %s: err = %v, want outbound.ErrRefused", u, err)
}
}
if n := reached.Load(); n != 0 {
t.Errorf("the server on this network was reached %d times", n)
}
}