Skip to content

The headless browser for AI agents and web scraping

fix(ssrf): refuse Teredo addresses that embed a forbidden IPv4

Andrey Mnatsakanov733a85ecce6a
diff --git a/crates/obscura-net/src/client.rs b/crates/obscura-net/src/client.rs
index c9fc15f5..52788d6a 100644
--- a/crates/obscura-net/src/client.rs
+++ b/crates/obscura-net/src/client.rs
@@ -1875,6 +1875,21 @@ mod ssrf_tests {
}
}
+ #[test]
+ fn teredo_cannot_hide_a_forbidden_ipv4() {
+ // RFC 4380: 2001:0::/32 embeds the Teredo server's IPv4 in bits
+ // 32..64 and the client's public IPv4, bit-inverted, in the last 32
+ // bits. Both are IPv4-in-IPv6 forms like NAT64 and 6to4.
+ // Client 127.1.1.1 (inverted 80fe:fefe) behind server 65.54.227.120.
+ assert!(is_forbidden_ip(ip("2001:0:4136:e378:8000:63bf:80fe:fefe")));
+ // Client 10.0.0.1 (inverted f5ff:fffe).
+ assert!(is_forbidden_ip(ip("2001:0:4136:e378:8000:63bf:f5ff:fffe")));
+ // Server 10.0.0.1 with a public client.
+ assert!(is_forbidden_ip(ip("2001:0:a00:1:8000:63bf:f7f7:f7f7")));
+ // Public server and public client 8.8.8.8 (inverted f7f7:f7f7).
+ assert!(!is_forbidden_ip(ip("2001:0:4136:e378:8000:63bf:f7f7:f7f7")));
+ }
+
#[test]
fn native_non_global_ipv6_ranges_are_forbidden() {
for s in [
diff --git a/crates/obscura-ssrf/src/lib.rs b/crates/obscura-ssrf/src/lib.rs
index 9da528d1..61033628 100644
--- a/crates/obscura-ssrf/src/lib.rs
+++ b/crates/obscura-ssrf/src/lib.rs
@@ -109,6 +109,25 @@ pub fn is_forbidden_ip(ip: IpAddr) -> bool {
s[2] as u8,
)));
}
+ // Teredo (RFC 4380, 2001:0::/32) carries the server's IPv4 in
+ // bits 32..64 and the client's public IPv4, bit-inverted, in the
+ // last 32 bits. Either one embedding a forbidden address is
+ // refused, like the other IPv4-in-IPv6 forms above.
+ if s[0] == 0x2001 && s[1] == 0 {
+ let server = Ipv4Addr::new(
+ (s[2] >> 8) as u8,
+ s[2] as u8,
+ (s[3] >> 8) as u8,
+ s[3] as u8,
+ );
+ let client = Ipv4Addr::new(
+ !(s[6] >> 8) as u8,
+ !s[6] as u8,
+ !(s[7] >> 8) as u8,
+ !s[7] as u8,
+ );
+ return is_forbidden_ip(IpAddr::V4(server)) || is_forbidden_ip(IpAddr::V4(client));
+ }
// Discard-only, local-use NAT64, and documentation prefixes.
(s[0] == 0x100 && s[1] == 0 && s[2] == 0 && s[3] == 0)