fix(#4): decide 'local registry' by name, not by its DNS answer

A registry name resolving to loopback (e.g. *.127.0.0.1.nip.io) got the
unfiltered agent for the whole pull. Only localhost or a non-public IP literal
is local now; DNS-named registries always use the filtered resolver.
This commit is contained in:
2026-10-22 19:52:32 +02:00
parent 2f053b8a5b
commit 37c58cb5b2
2 changed files with 22 additions and 6 deletions
+2 -1
View File
@@ -70,7 +70,8 @@ The VM is the boundary. The guest (including a prompt-injected agent or a malici
- **Registry**: references are validated before any request, digest pins are enforced, and every blob/manifest is sha256-verified. - **Registry**: references are validated before any request, digest pins are enforced, and every blob/manifest is sha256-verified.
The tag cache is keyed by the exact reference (`a_b:t` and `a/b:t` never share an entry). The tag cache is keyed by the exact reference (`a_b:t` and `a/b:t` never share an entry).
Auth realms must be https. For public registries, connections to loopback/private/link-local addresses are refused Auth realms must be https. For public registries, connections to loopback/private/link-local addresses are refused
(token realms and redirects included). (token realms and redirects included, IPv6 forms like NAT64/6to4 too). A registry counts as local only by name:
`localhost` or a private IP literal (`192.168.1.5:5000`). LAN registries addressed by a DNS name are refused; use the IP.
- **pi config**: allowlisted items only. Symlinks are followed only into `~/.pi/agent` or `~/.agents/skills`, with no cycles - **pi config**: allowlisted items only. Symlinks are followed only into `~/.pi/agent` or `~/.agents/skills`, with no cycles
and no special files, capped at 256 MB. and no special files, capped at 256 MB.
- **exec**: sessions run as root before dropping to the user, so the guest helper accepts them only from the host's vsock CID, - **exec**: sessions run as root before dropping to the user, so the guest helper accepts them only from the host's vsock CID,
+20 -5
View File
@@ -73,13 +73,18 @@ pub fn is_public(ip: IpAddr) -> bool {
} }
} }
/// Registry the user named as local: `localhost` or a non-public IP literal. Decided by name only --
/// a DNS name pointing at loopback (e.g. *.127.0.0.1.nip.io) is controlled by whoever owns the zone.
fn explicit_local(registry: &str) -> bool {
let host = registry.split_once(':').map_or(registry, |(h, _)| h);
host == "localhost" || host.parse().is_ok_and(|ip| !is_public(ip))
}
/// HTTP agent for a registry. Public registries get an agent that refuses to connect to non-public /// HTTP agent for a registry. Public registries get an agent that refuses to connect to non-public
/// addresses (covers token realms and blob redirects too); a registry that is itself local /// addresses (covers token realms and blob redirects too); an explicitly local registry
/// (e.g. localhost:5000) was chosen explicitly by the user and keeps the default agent. /// (e.g. localhost:5000, 192.168.1.5:5000) was chosen by the user and keeps the default agent.
fn agent_for(registry: &str) -> ureq::Agent { fn agent_for(registry: &str) -> ureq::Agent {
let addr = if registry.contains(':') { registry.to_string() } else { format!("{registry}:443") }; if explicit_local(registry) {
let local = addr.to_socket_addrs().map(|mut a| a.any(|a| !is_public(a.ip()))).unwrap_or(false);
if local {
return ureq::agent(); return ureq::agent();
} }
ureq::AgentBuilder::new() ureq::AgentBuilder::new()
@@ -486,6 +491,16 @@ mod tests {
} }
} }
#[test]
fn local_registries() {
for l in ["localhost:5000", "localhost", "127.0.0.1:5000", "192.168.1.5:5000"] {
assert!(explicit_local(l), "{l}");
}
for r in ["evil.127.0.0.1.nip.io:8443", "localhost.evil.com", "ghcr.io", "8.8.8.8:443", "registry-1.docker.io"] {
assert!(!explicit_local(r), "{r}");
}
}
#[test] #[test]
fn bad_refs() { fn bad_refs() {
for bad in ["alpine@sha256:../../x", "../x", "a/../b", "alpine:../x", "Alpine", "a//b"] { for bad in ["alpine@sha256:../../x", "../x", "a/../b", "alpine:../x", "Alpine", "a//b"] {