Your SSRF filter and your HTTP client parse different URLs
One backslash makes Python’s urlsplit approve one host while requests connects to another. A deep dive into the URL parser differentials, legacy IPv4 spellings and is_private gaps that still get SSRF payloads past filters, the netmask, ipaddress and node-ip CVEs they produced, and a validator built so it cannot disagree with its own HTTP client.
By The Xalgorix Team
Here is one URL, handed to two pieces of Python that ship in almost every web backend:
>>> from urllib.parse import urlsplit >>> import requests >>> u = "http://127.0.0.1:9001\@127.0.0.1:9002/" >>> urlsplit(u).port 9002 >>> requests.get(u).url 'http://127.0.0.1:9001/%5C@127.0.0.1:9002/'
The standard library says the destination is port 9002. Requests, which parses URLs with urllib3, opened a connection to port 9001 and put everything after the backslash into the path. We ran this on 2026-11-18 with Python 3.13, requests 2.34.2 and urllib3 2.8.0, against two local listeners. Swap the ports for hostnames and the shape is familiar: a filter that validates with urlsplit approves allowed.example, and the HTTP client fetches from whatever host sits before the backslash.
That gap between the parser that checks and the parser that connects is one of the oldest and most reliable ways past an SSRF filter, and it has not gone away. This article walks through the three families of disagreement that still turn up (the authority section, IP address spellings, and the questions a blocklist asks) with commands you can reproduce, the CVEs that came out of each, and a validator built so it cannot disagree with its own client.
Two parsers, one string
Orange Tsai made this a named technique at Black Hat USA 2017 in “A New Era of SSRF: Exploiting URL Parser in Trending Programming Languages”. The talk's core observation was that the component which parses a URL and the component which requests it often interpret the same string differently, and fuzzing that gap produced more than 20 bugs across the standard libraries of Python, PHP, Perl, Ruby, Java and JavaScript as well as wget and cURL.
The reason it keeps happening is that there are two specifications in wide use. RFC 3986 describes a generic URI syntax. The WHATWG URL Standard describes what browsers actually do, including error recovery: for special schemes such as http it treats a backslash like a forward slash, and its host parser accepts legacy IPv4 forms in hex, octal and fewer than four parts. Libraries pick one model, partly implement the other, or invent their own, and an application can easily load three of them at once.
Authority confusion: @, # and the backslash
The authority is the part between // and the path: userinfo@host:port. Three characters decide where it ends, and parsers do not agree on them. We fed the same strings to Python's urllib.parse.urlsplit, urllib3's parse_url (what requests uses) and Node 22's WHATWG new URL():
input urlsplit urllib3 WHATWG URL http://evil.example\@allowed.example/ allowed.example evil.example evil.example http://allowed.example#@evil.example/ allowed.example allowed.example allowed.example http://allowed.example@evil.example/ evil.example evil.example evil.example
- The backslash is the live one. RFC-style parsers treat
\as an ordinary character inside userinfo, so everything before@is credentials and the host isallowed.example. WHATWG and urllib3 end the authority at the backslash. A Python service that validates withurlsplitand then fetches with requests, or hands the URL to a headless Chromium for a screenshot or PDF, is exposed. curl 8.5.0 sided withurlsplitin our test, which is why “it works with curl” tells you nothing about the production client. - The fragment (
#) ended the authority for all three here. It still matters for hand-written checks: a regex orstartswithtest that looks forallowed.exampleanywhere in the string is satisfied byhttps://evil.example/#allowed.example. - Userinfo (
@) is parsed consistently by real parsers. It defeats string matching, not parsing:allowed.example@evil.examplebegins with the allowed name and points at the attacker.
Leading whitespace was a fourth entry until recently. CVE-2023-24329 covered Python's urlparse mis-reading the scheme and host when the whole URL started with blank characters, which let input slip past blocklists of schemes and hosts. It was fixed in 3.11.4, 3.10.12 and the matching security releases; on 3.13 urlsplit now strips the leading space. It is a useful reminder that a differential can live in your language runtime, not your code, and that runtime updates are part of the SSRF defense.
One address, many spellings
The second family needs no parser bug at all. The C library function inet_aton, and the resolvers built on it, accept IPv4 addresses written in forms nobody types on purpose. On the Linux box we tested, socket.gethostbyname returned 127.0.0.1 for every one of these:
0x7f.1 hex first part, two-part form 2130706433 one 32-bit decimal number 127.1 three parts collapsed into two 0177.0.0.1 leading zero means octal: 0177 = 127
Now look at what a typical validator does with them. Python's ipaddress.ip_address() raises ValueError on all four, because it only accepts dotted-decimal. A filter written as “if it parses as an IP, check the range, otherwise treat it as a hostname” waves them through as hostnames, and then the resolver turns them into loopback. WHATWG new URL() goes the other way and normalizes all four to 127.0.0.1, which is safer only if your check runs on the normalized hostname.
Leading zeros are the nastiest case, because two correct-looking libraries can reach different answers. 0127.0.0.1 resolves to 87.0.0.1 (octal 127 is 87), and 0177.0.0.1 resolves to loopback. Libraries that strip the zero and read decimal get both wrong. That exact mistake produced a run of CVEs:
- CVE-2021-28918, npm
netmask1.0.6 and below: octal strings read as decimal, so dependents using it to filter IPs could be steered to LAN hosts. As The Register reported,0177.0.0.1looked public to netmask while browsers read it as loopback. Upgrade to 2.0.0 or later. - CVE-2021-29921, Python
ipaddress: Python 3.8 started accepting leading zeros. Fixed in 3.8.12, 3.9.5 and 3.10.0, which now reject them. - CVE-2023-42282, npm
ip:isPublic()called0x7f.1public. The fix in 1.1.9 and 2.0.1 was incomplete, and CVE-2024-29415 lists127.1,01200034567,012.1.2.3,000:0:0000::01and::fFFf:127.0.0.1as still misclassified in versions through 2.0.1. If a package like this sits in your SSRF path, check whether a fixed release exists for your version before trusting it, and prefer judging the resolved address instead.
IPv6 adds its own spellings. [::ffff:127.0.0.1] and [::ffff:7f00:1] are the same IPv4-mapped loopback address. Node normalizes the host to [::ffff:7f00:1]; a filter that compares strings against 127.0.0.1 or checks only IPv4 ranges misses both. PortSwigger's URL validation bypass cheat sheet (Zakhar Fedotkin, September 2024) collects these encodings, including overflowed DWORD and mixed forms, alongside domain-allowlist confusions, and generates them for your own target and allowed domains.
Blocklists that ask the wrong question
Even with a perfect address in hand, the range check is easy to get subtly wrong. Python 3.13 gives these answers:
address is_private is_global 169.254.169.254 True False cloud metadata (link-local) 0.0.0.0 True False reaches local listeners on Linux 100.64.0.1 False False shared address space (CGNAT) ::ffff:127.0.0.1 True False IPv4-mapped loopback
The third row is the trap. 100.64.0.0/10 is carrier-grade NAT space, and in cloud and Kubernetes networks it often carries internal traffic, yet is_private is False for it. The ipaddress documentation calls this out as a deliberate exception. The question an SSRF filter wants answered is “is this publicly routable?”, so test not ip.is_global, and unwrap ipv4_mapped first so the IPv4 rules apply to mapped addresses on every Python version you run, not only the ones whose behaviour you checked.
fc00::/7) and link-local (fe80::/10), 0.0.0.0/8, or the IPv6 form of the metadata endpoint some clouds expose. Use the library's registry-backed property and add only what your network needs on top.Testing a URL-fetching feature for parser gaps
If you are on the attacking side of an engagement, the goal is to learn which parser validates and which one connects, without hammering internal services. A workflow that stays quiet:
The out-of-band step is what makes this efficient. Put your own callback domain on one side of the backslash and the allowed domain on the other; whichever name receives the DNS lookup or HTTP request tells you how the client parsed it, before any internal address is involved. Our guide to out-of-band callbacks covers reading those signals. When a filter turns out to be range-based, cycle the address spellings above; when it is allowlist-based, the authority tricks are the ones that matter. Keep internal requests to targets the program puts in scope, and treat cloud metadata as out of bounds unless it is explicitly allowed.
A validator that cannot disagree with its client
Every bypass above relies on two components disagreeing or a check reading the wrong form of the address. The fix is to leave no room for either: parse once with the client's own parser, refuse ambiguous input outright, and judge the resolved address rather than the text. For a Python service that fetches with requests:
import ipaddress
import socket
from urllib3.util import parse_url # the parser requests uses
class BlockedURL(ValueError):
pass
def resolve_public(url: str):
# 1. Refuse what parsers disagree about, before parsing at all.
if any(c in url for c in "\\\t\r\n ") or not url.isprintable():
raise BlockedURL("backslash, whitespace or control character")
# 2. Parse with the same library the HTTP client will use.
u = parse_url(url)
if u.scheme not in ("http", "https") or not u.host:
raise BlockedURL("scheme or host missing")
if u.auth is not None:
raise BlockedURL("userinfo is not allowed")
# 3. Resolve, then judge every address the resolver returns.
port = u.port or (443 if u.scheme == "https" else 80)
infos = socket.getaddrinfo(u.host.strip("[]"), port,
proto=socket.IPPROTO_TCP)
addrs = []
for *_, sockaddr in infos:
ip = ipaddress.ip_address(sockaddr[0])
if getattr(ip, "ipv4_mapped", None):
ip = ip.ipv4_mapped
if not ip.is_global:
raise BlockedURL(f"{u.host} resolves to non-global {ip}")
addrs.append(ip)
# 4. Connect to one of these addresses and do not resolve again.
return u, addrsWe ran it against the payloads above. The backslash and leading-space URLs fail step 1, userinfo fails step 2, file:// fails the scheme check, and the encoded loopbacks (0x7f.1, 2130706433, 0177.0.0.1, [::ffff:127.0.0.1]),0.0.0.0, 100.64.0.1 and 169.254.169.254 all fail step 3 because the resolver has already turned each spelling into a real address. A public IP passes. Notice that step 3 never inspects the hostname text: encodings stop mattering once you check what the resolver produced.
What this function does not do
- It does not pin the connection. If you return the URL to requests, it resolves the name a second time and a rebinding DNS server can answer differently. Step 4 has to be a real connection to the validated address with the original hostname kept for Host, SNI and certificate checks; our article on the SSRF filter that resolves DNS twice shows how. Pinning also neutralizes any parser differential you missed for the blocklist case, because the socket goes to the address you checked.
- It does not handle redirects. Disable them, or run every
Locationthrough the same function. - It is not an allowlist. If the feature only ever needs a few destinations, compare
u.host, lowercased and IDNA-normalized, for exact equality with a fixed set. Never use substring, prefix or suffix matching:allowed.example.evil.examplestarts with the allowed name and belongs to the attacker. - It only covers one client. If the URL is also handed to a headless browser, a PDF renderer or an image library, each of those has its own parser. Validate against the strictest common subset, or better, give that component no network path to internal ranges at all.
What to take away
Payload lists find the bugs, but they also explain why automated scanners miss some of them: a scanner that sprays encoded loopbacks learns that the filter blocks them, not that a one-character authority trick lands on a different host. Tools that test for this well, Xalgorix included, work by sending a candidate and watching where the request actually arrives, which only works when the tool controls a listener the target can reach. When you build the defense, aim for the property that makes the whole class disappear: one parser, one resolution, one checked address, and a socket that goes exactly there.
Ready to see it prove a bug?
Start scanning on Cloud →