H: canonicalise addresses in the deny check Match IPv4-mapped IPv6 addresses against the IPv4 deny list at connect time, with tests for ::ffff:169.254.169.254

This commit is contained in:
ari committed 2026-10-20 16:12:07 -04:00
1 parent 39c1c91695
commit 6e74d3d99b
2 files changed
+28

No files matched your search

+22
View File
@@ -1075,6 +1075,28 @@ mod tests {
let _ = std::fs::remove_file(&token);
}
/// An IPv4-mapped literal resolves to a socket address in the IPv6 family.
/// Without canonicalising it the IPv4 deny list would miss it and the
/// metadata endpoint would be contacted.
#[tokio::test]
async fn an_ipv4_mapped_address_is_matched_against_the_v4_deny_list() {
let token = write_token("t", 0o600);
let mut p = peer(80, &token, None);
p.url = url("http://[::ffff:169.254.169.254]/");
p.allow_plain_http = true;
let deny = deny_networks(&PeersConfig::default().deny_cidrs).unwrap();
assert!(matches!(
resolve_target(&p, &deny).await,
Err(PeerError::Unreachable)
));
let transport = ReqwestTransport::new(&PeersConfig::default()).unwrap();
assert!(matches!(
transport.tcp_check(&p, Duration::from_secs(1)).await,
Err(PeerError::Unreachable)
));
let _ = std::fs::remove_file(&token);
}
#[test]
fn invalid_deny_cidr_and_plain_http_opt_in() {
let mut cfg = limits(2, 2, 1024);
+6
View File
@@ -409,6 +409,12 @@ mod tests {
let err = message(validate(&cfg).unwrap_err());
assert!(err.contains("deny_cidrs"), "{err}");
// The address form the connector sees is matched the same way.
let deny = deny_networks(&cfg.deny_cidrs).unwrap();
assert!(denied("::ffff:169.254.169.254".parse().unwrap(), &deny));
assert!(denied("169.254.169.254".parse().unwrap(), &deny));
assert!(!denied("::ffff:10.0.0.1".parse().unwrap(), &deny));
// Same for loopback: a mapped literal is loopback, so plain http is
// allowed without the flag.
let cfg = disabled_section(vec![peer("beta", "http://[::ffff:127.0.0.1]:1984")]);