mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
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]>
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
package secrets
|
||
|
||
import (
|
||
"net/netip"
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/devvmhq/devvm/internal/proxy"
|
||
)
|
||
|
||
// legacyCheckHost is CheckHost as it was before proxy.NormHost read its host, frozen for
|
||
// FuzzCheckHostSite: its result, and whether it took the host.
|
||
func legacyCheckHost(given string) (string, bool) {
|
||
h := strings.ToLower(given)
|
||
if rest, port, ok := strings.Cut(h, ":"); ok {
|
||
if port != "443" {
|
||
return "", false
|
||
}
|
||
h = rest
|
||
}
|
||
h = strings.TrimSuffix(h, ".")
|
||
_, addrErr := netip.ParseAddr(strings.Trim(h, "[]"))
|
||
if addrErr == nil || strings.Contains(h, "*") || !strings.Contains(h, ".") || !proxy.HostOK(h) || !proxy.ValidRule(h) || internalName(h) {
|
||
return "", false
|
||
}
|
||
return h, true
|
||
}
|
||
|
||
// FuzzCheckHostSite: a secret's --host reads as it did. Divergence: a host with anything but
|
||
// printable ASCII is refused, where strings.ToLower folded it into ASCII first (the Kelvin sign's
|
||
// kubernetes.io was taken as kubernetes.io), as the proxy refuses such a host before it folds it.
|
||
// Every host CheckHost takes, it took, as the same host.
|
||
func FuzzCheckHostSite(f *testing.F) {
|
||
for _, s := range []string{
|
||
"api.example.com", "API.Example.com.", "api.example.com:443", "api.example.com.:443", "api.example.com..",
|
||
"api.example.com:8443", "Kubernetes.io", "[::1]:443", "*.example.com", "example", "x.local", "",
|
||
} {
|
||
f.Add(s)
|
||
}
|
||
f.Fuzz(func(t *testing.T, given string) {
|
||
got, err := CheckHost(given)
|
||
was, ok := legacyCheckHost(given)
|
||
switch {
|
||
case err == nil && (!ok || got != was):
|
||
t.Fatalf("CheckHost(%q) = %q; was %q, %v", given, got, was, ok)
|
||
case err != nil && ok && !strings.ContainsFunc(given, func(r rune) bool { return r <= ' ' || r > '~' }):
|
||
t.Fatalf("CheckHost(%q) refused it; was %q", given, was)
|
||
}
|
||
})
|
||
}
|