Files
w3cjandClaude Opus 5.5 4e925492ca fix(proxy): every host is read in one form, proxy.NormHost, guarded by the structure test
Every check that judges or compares a host now reads it through
proxy.NormHost (internal/proxy/host.go), which also holds HostOK,
splitHostPort, hostASCII and asciiEqualFold: a host of printable ASCII is
lowercased in ASCII alone and loses its one trailing dot; any other host
stays as it is, so HostOK refuses it and no Unicode fold makes another
name match. A host with two trailing dots or more, or a dot after a
closing bracket, keeps them, so NormHost is idempotent and reading a host
twice can't turn evil.test.. into evil.test. A proxy.Host is what the
matchers take (rule.matchHost, noProxyRule.matches, local, sniMatches).

Brackets are strict (hostAddr): HostOK, Host.Addr and splitHostPort take
an address bare or an IPv6 address in one pair of brackets, never a stray
bracket ([[::1]], 1.2.3.4]) or brackets around a name or an IPv4 address
([evil.com]:443, [1.2.3.4]:443), which get 400.

Migrated: splitHostPort, sniMatches, sniHost, parseHostRule, the
policy's rulesFor, quiet, byName and coversOn, secrets.forHost,
parseNoProxy, route and local in internal/proxy; netpolicy.RiskOf,
Tickable and sameRule (devvm network rm and the duplicate check, so a
Kelvin sign never names the rule with a k); secrets.CheckHost;
from.publicHost (a name HostOK refuses isn't public);
agentlogin.claudeHost; vm.urlHostPort and privateHost. vm.urlHost
(cloneseed.go) keeps its own reading: it's a remote's ssh host, which ssh
lowercases and keeps the trailing dot of, to find a VM's alias.

Differential fuzz targets keep a frozen copy of each reader as it was and
allow only the decided differences: FuzzHostSites (proxy), FuzzRiskSites,
FuzzCheckHostSite, FuzzPublicHostSite, FuzzClaudeHostSite and
FuzzPromisorHostSite. A rule line is the same rule or no rule exactly as
before, so a broken deny stays a broken deny. TestFixtureHosts reads the
frozen v0.1.0 state's secrets.policy, secrets.json and links.json hosts
and finds them unchanged.

The structure test's new hosts check refuses, outside host.go and tests:
Trim, TrimLeft or TrimRight with a cutset holding ".", TrimSuffix or
CutSuffix with "."; ToLower, ToUpper, EqualFold and the TrimFunc family on
an argument named for a host; and a conversion to proxy.Host of anything
but a literal. Exceptions are by file and function, each with why
(request.go:trimDots, cloneseed.go:urlHost, cloneworktree.go:safeIndexPath,
cloneconfig.go:transportHelper, lima/start.go:machines.fillPassword). It
doesn't see slicing, strings.Map or variables not named for a host. The
owners doc, the proxy README, structure.md, design.md (One form of a
host), network.md and safety/network.md say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:28 -07:00

52 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package from
import (
"net"
"net/netip"
"strings"
"testing"
"github.com/devvmhq/devvm/internal/proxy"
)
// legacyPublicHost is publicHost as it was before proxy.NormHost read its host, frozen for
// FuzzPublicHostSite.
func legacyPublicHost(host string) bool {
if h, _, err := net.SplitHostPort(host); err == nil {
host = h
}
host = strings.ToLower(strings.TrimSuffix(strings.Trim(host, "[]"), "."))
if host == "localhost" || strings.HasSuffix(host, ".localhost") {
return false
}
if ip, err := netip.ParseAddr(host); err == nil {
return proxy.Public(ip)
}
return true
}
// FuzzPublicHostSite: --from's registry host reads as it did, and is never more public than it
// was. Divergence: a name the proxy doesn't take (proxy.HostOK) isn't public, where it was unless
// strings.ToLower folded it into localhost's: one with anything but printable ASCII, a bracket a
// trailing dot hid from strings.Trim ([::1]., read as the name ::1]), an empty label or a shorthand
// address (10.1). No registry's name is one of those.
func FuzzPublicHostSite(f *testing.F) {
for _, s := range []string{
"ghcr.io", "GHCR.io.", "localhost", "LOCALHOST.:5000", "x.localhost", "127.0.0.1:5000", "[::1]:5000",
"[::1].", "10.0.0.1.", "Kubernetes.io", "localhost..", "",
} {
f.Add(s)
}
f.Fuzz(func(t *testing.T, host string) {
got, was := publicHost(host), legacyPublicHost(host)
h := host
if hh, _, err := net.SplitHostPort(host); err == nil {
h = hh
}
taken := proxy.NormHost(strings.Trim(h, "[]")).OK()
if got != was && (got || taken) {
t.Fatalf("publicHost(%q) = %v, was %v", host, got, was)
}
})
}