Skip to content

Commit b6777c8

Browse files
BornToBeRootclaude
andcommitted
Fix: RDAP referral behind a proxy, private address check for NAT64/6to4
- If the referral goes through the system proxy, the host name is not resolved locally (the proxy resolves it), so referrals work in networks where only the proxy resolves public names. IP addresses in the URL are still checked. - The private address check also covers IPv6 addresses that contain an IPv4 address (NAT64 64:ff9b::/96, 6to4 2002::/16), the rest of 64:ff9b::/32 (local-use NAT64), 192.0.0.0/24 and 198.18.0.0/15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9e41b2d commit b6777c8

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎Source/NETworkManager.Models/RDAP/RDAPClient.cs‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ private async Task<RDAPResult> GetAsync(RDAPQuery query, string url, TimeSpan ti
279279
/// <summary>
280280
/// Checks the target of a referral, which is sent by the registry and therefore untrusted. Only HTTPS is allowed
281281
/// (no downgrade to plain text) and the host must not resolve to a local or private address, so a response
282-
/// cannot make the client send requests into the local network.
282+
/// cannot make the client send requests into the local network. If the request goes through a proxy, the proxy
283+
/// resolves the host and connects to it, so the host is not resolved locally (often not possible in networks
284+
/// where only the proxy resolves public names); an IP address in the URL is still checked.
283285
/// </summary>
284286
private static async Task ValidateReferralTargetAsync(Uri url, CancellationToken cancellationToken)
285287
{
@@ -296,6 +298,10 @@ private static async Task ValidateReferralTargetAsync(Uri url, CancellationToken
296298
{
297299
addresses = [ipAddress];
298300
}
301+
else if (IsProxied(url))
302+
{
303+
return;
304+
}
299305
else
300306
{
301307
try
@@ -313,6 +319,16 @@ private static async Task ValidateReferralTargetAsync(Uri url, CancellationToken
313319
throw new RDAPException(RDAPErrorKind.PrivateAddress, url.AbsoluteUri) { RequestUrl = url.AbsoluteUri };
314320
}
315321

322+
/// <summary>
323+
/// Whether a request to the URL goes through the system proxy (the proxy of the referral client).
324+
/// </summary>
325+
private static bool IsProxied(Uri url)
326+
{
327+
var proxy = HttpClient.DefaultProxy;
328+
329+
return !proxy.IsBypassed(url) && proxy.GetProxy(url) != null;
330+
}
331+
316332
/// <summary>
317333
/// Connect callback of the referral client: resolves the host once, checks all addresses and connects to exactly
318334
/// these addresses, so a second DNS answer (DNS rebinding) cannot redirect the connection to a local or private
@@ -352,7 +368,9 @@ private static async ValueTask<Stream> ConnectToPublicAddressAsync(SocketsHttpCo
352368
}
353369

354370
/// <summary>
355-
/// Loopback, private (RFC 1918, RFC 4193), shared (RFC 6598), link-local, unspecified and multicast addresses.
371+
/// Loopback, private (RFC 1918, RFC 4193), shared (RFC 6598), link-local, unspecified, multicast and special
372+
/// purpose (IETF protocol assignments, benchmarking) addresses. IPv6 addresses that contain an IPv4 address
373+
/// (NAT64, 6to4) are checked by that IPv4 address, since they are translated or tunneled to it.
356374
/// </summary>
357375
private static bool IsLocalOrPrivateAddress(IPAddress address)
358376
{
@@ -369,7 +387,19 @@ private static bool IsLocalOrPrivateAddress(IPAddress address)
369387
bytes[0] == 172 && (bytes[1] & 0xF0) == 16 ||
370388
bytes[0] == 192 && bytes[1] == 168 ||
371389
bytes[0] == 169 && bytes[1] == 254 ||
372-
bytes[0] == 100 && (bytes[1] & 0xC0) == 64;
390+
bytes[0] == 100 && (bytes[1] & 0xC0) == 64 ||
391+
bytes[0] == 192 && bytes[1] == 0 && bytes[2] == 0 ||
392+
bytes[0] == 198 && (bytes[1] & 0xFE) == 18;
393+
394+
// NAT64 (RFC 6052): the well-known prefix 64:ff9b::/96 contains the IPv4 address in the last 4 bytes. Other
395+
// addresses in 64:ff9b::/32, e.g. the local-use prefix 64:ff9b:1::/48 (RFC 8215), are translated by the local
396+
// network operator and are therefore treated as local.
397+
if (bytes[0] == 0x00 && bytes[1] == 0x64 && bytes[2] == 0xFF && bytes[3] == 0x9B)
398+
return bytes[4..12].Any(x => x != 0) || IsLocalOrPrivateAddress(new IPAddress(bytes[12..]));
399+
400+
// 6to4 (RFC 3056): 2002::/16 contains the IPv4 address in bytes 2-5.
401+
if (bytes[0] == 0x20 && bytes[1] == 0x02)
402+
return IsLocalOrPrivateAddress(new IPAddress(bytes[2..6]));
373403

374404
return address.Equals(IPAddress.IPv6Any) || address.IsIPv6LinkLocal || address.IsIPv6SiteLocal ||
375405
address.IsIPv6Multicast || (bytes[0] & 0xFE) == 0xFC;

‎Website/docs/application/rdap.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ For many domains (e.g. `.com` and `.net`), the registry only returns basic data
123123

124124
:::note
125125

126-
For security reasons, a referral is only followed if it uses HTTPS and does not point to a local or private address (e.g. `192.168.0.0/16`). Otherwise, a message is shown and only the result of the registry is displayed.
126+
For security reasons, a referral is only followed if it uses HTTPS and does not point to a local or private address (e.g. `192.168.0.0/16`). Otherwise, a message is shown and only the result of the registry is displayed. If a proxy is configured in Windows, the proxy resolves the host name of the referral, so it is only checked if it is an IP address.
127127

128128
:::
129129

0 commit comments

Comments
 (0)