SSRF via maliciously crafted URL due to host confusion
Curl parses the host part of a URL differently from the WHATWG URL standard and other parsers, so a crafted URL with a backslash before the @ sign makes curl connect to a different host than the one a validator sees. An attacker could use this to slip a request past a host allowlist or blocklist and reach internal services (SSRF) or cause an open redirect.
Originally disclosed on HackerOne
- Disclosed after 15 months
Summary:
Curl is vulnerable to SSRF due to improperly parsing the host component of the URL compared to other URL parsers and the URL living standard.
POC
curl -sD - -o /dev/null "http://google.com:80\\@yahoo.com/"
Curl makes a request to yahoo.com instead of google.com.
Supporting Material/References:
- Exact question to URL standards body
- CVE-2018-3774 similar vulnerability in an NPM lib
- See also: https://hackerone.com/reports/384029
To quote the standards body issue:
Specifically the authority state deals with parsing the @ properly. However as you'll notice if it encounters the
\beforehand, it'll go into the host state and reset the pointer at which point it won't considergoogle.com:80\\auth data foryahoo.comanymore.
Other Libraries
const whatwg_url = require('whatwg-url'); // Created by the RFC maintainers
const theUrl = new whatwg_url.URL("https://google.com:80\\\\@yahoo.com/");
const theUrl2 = new whatwg_url.URL("https://google.com:80\\@yahoo.com/");
const nodeUrl = new URL("https://google.com:80\\\\@yahoo.com/");
const nodeUrl2 = new URL("https://google.com:80\\@yahoo.com/");
console.log(theUrl.hostname); // Prints google.com
console.log(theUrl2.hostname); // Prints google.com
console.log(nodeUrl.hostname); // Prints google.com
console.log(nodeUrl2.hostname); // Prints google.com
Impact
If another library implementing the URL standard is used to white/blacklist a request by host but the actual request is made via curl or the curl library, an attacker can smuggle the request past the URL validator thus allowing an attacker to perform SSRF or an open redirect attack.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely curl's URL parser treats a backslash before the @ as ending the authority section and resets to host parsing, so the text before the @ is not treated as credentials the way the URL standard requires.
Impact
If a validator using a standards-compliant URL library checks the host but the request is made with curl, an attacker could bypass the allowlist or blocklist and perform SSRF or an open redirect.
What the attacker needed
Application validates URL with another library; request is then made with curl
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A URL can contain a username and password before the @ sign, and different programs disagree about where the real host name starts. If a website checks a URL with one library but fetches it with curl, the check may approve one host while curl actually contacts another. That lets an attacker make the server talk to places it should not reach, such as internal systems.
What is SSRF?
The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.