URL API: triple-slash parses path segment as hostname
libcurl's URL parser treats the first path segment after a triple slash as the hostname, even though RFC 3986 says the authority is empty in that case. An application that builds URLs from user input and checks the parsed hostname could therefore be tricked into sending requests to an attacker-chosen host, such as a cloud metadata address.
- Disclosed after 12 hours
Summary
libcurl's URL API misparses http:///host/path. Per RFC 3986, the authority between // and / is empty, so /host/path is the path. But parseurl() in lib/urlapi.c treats the first segment as the hostname. On line ~1087, the slash counter i reaches 3, which is within the valid 1-3 range, and hostp is set to whatever follows the third slash. The file:// scheme has special handling that correctly handles empty authority — this fix should be generalized to other schemes.
Affected version
libcurl 8.5.0 (Ubuntu 24.04) and 8.21.0 (latest). Confirmed on both. curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13
Steps To Reproduce
- Compile and run the attached poc_tripleslash.c
- Observe: http:///169.254.169.254/latest/meta-data/ → host="169.254.169.254", path="/latest/meta-data/" Expected: host="" (empty authority), path="/169.254.169.254/latest/meta-data/"
- Also confirmed via curl CLI:
curl -w "%{url_effective}" http:///pathOutputs: http://path/ (path became hostname)
Impact
An application that constructs URLs from user input and validates the parsed hostname via curl_url_get(CURLUPART_HOST) can be tricked into making requests to attacker-chosen hosts. For example, if user input "/169.254.169.254/latest/meta-data/" is appended to "http://", curl parses host="169.254.169.254", enabling SSRF to cloud metadata endpoints.
Context
curl is a command-line tool and library for transferring data with URLs, and libcurl is the library underneath it. Among its public interfaces is the URL API, which lets an application parse a URL into its component parts (scheme, host, path and so on) and read them back individually. The function that does the parsing is parseurl() in lib/urlapi.c.
The report concerns how that parser handles a URL with an empty authority, specifically http:///host/path. Under RFC 3986 the authority is the part between // and the next /. When nothing sits between them, the authority is empty and everything after the third slash belongs to the path. The parser instead promoted the first path segment to the hostname.
Setup
The issue was confirmed on two libcurl versions:
- libcurl 8.5.0, as shipped on Ubuntu 24.04
- libcurl 8.21.0, described in the report as the latest at the time
The CLI banner reported for the first environment was:
curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13
The researcher used an attached program, poc_tripleslash.c, together with the curl command-line tool. No account, role or special configuration is described.
Finding it
The starting point is the RFC 3986 rule for the authority component: for http:///host/path, the authority between // and / is empty, so /host/path is the path. The parser in lib/urlapi.c did not follow that. Around line 1087, the slash counter i reaches 3, which is still inside the valid 1 to 3 range the code accepts, and hostp is set to whatever follows the third slash. The result is that the first path segment is treated as the hostname.
The report notes that the file:// scheme already has special handling that deals correctly with an empty authority, and argues that this handling should be generalised to the other schemes.
Exploitation
Step 1: build and run the proof of concept
Compile and run the attached poc_tripleslash.c
The report gives no further detail about the program beyond compiling and running it.
Step 2: observe the parsed components
The input and the observed result:
http:///[redacted]/latest/meta-data/
→ host="[redacted]", path="/latest/meta-data/"
The expected result, per the RFC, is an empty host and the full remainder as the path:
Expected: host="" (empty authority), path="/[redacted]/latest/meta-data/"
Instead of an empty authority, the first segment [redacted] was returned as the host, and the path lost that segment.
Step 3: confirm through the CLI
The same behaviour was reproduced with the curl command line, printing the effective URL:
curl -w "%{url_effective}" http:///path
The output was:
http://path/
The path segment path had become the hostname, and the effective URL was rewritten accordingly.
Root cause
The bug is in parseurl() in lib/urlapi.c. The slash counter i reaches 3, which the code accepts as within the valid 1 to 3 range, and hostp is then set to whatever follows the third slash. The parser accepts three slashes as within its valid 1 to 3 range and sets hostp to whatever follows the third slash. The file:// scheme has separate handling that copes with an empty authority correctly, but that handling was not applied to the other schemes.
Impact
An application that builds URLs from user input and then validates the parsed hostname via curl_url_get(CURLUPART_HOST) can be tricked into making requests to attacker-chosen hosts. The report gives a concrete pattern: if user input /[redacted]/latest/meta-data/ is appended to http://, curl parses the host as [redacted], which enables SSRF to cloud metadata endpoints.
An application that validates the parsed hostname via curl_url_get(CURLUPART_HOST) can be tricked this way. Where that is the case, a hostname check that looks correct can be bypassed because the parser and the application disagree with the RFC about which part of the string is the host.
Fix
The report does not describe a patch. Its recommendation is to generalise the existing file:// handling of an empty authority to the other schemes, so that http:///host/path parses with an empty host and /host/path as the path.
Variants to test
- Other schemes with an empty authority, such as
https:///host/path, to see whether the same promotion of the first path segment to host occurs. - More than three slashes, to check how the slash counter behaves outside the accepted 1 to 3 range.
- The
file://scheme itself, as a control: the report says it handles an empty authority correctly, so it should return an empty host. - Applications that append user input to a scheme prefix and then validate with
curl_url_get(CURLUPART_HOST), checking whether a leading/in the input changes the parsed host.
A positive result is a parsed host that is non-empty when the authority in the input is empty, with the first path segment appearing as the host.
Hunting notes
This kind of bug hides in URL parsers and in the gap between what a parser returns and what the surrounding application assumes. The signal is a URL form with an empty authority, scheme:///..., which most people never type and most test suites never cover. Comparing the parser's output against the RFC for such inputs, and against the behaviour of other schemes in the same library, is a quick way to spot inconsistencies.
To show impact, the researcher demonstrated the misparse both through the library API and through the curl CLI, and tied it to a realistic SSRF path against a cloud metadata address.
What happened, in plain words
curl is a very common program, and a library called libcurl sits underneath it. Both are used to fetch things from the internet using URLs, the addresses you type into a browser, like http://example.com/page. libcurl also offers a feature called the URL API: a way for another program to hand it a URL and ask it to break that URL into pieces, such as the scheme (http), the host (the machine name) and the path (the page on that machine).
The report is about a mistake in that breaking-up step. When a URL has nothing between its // and the next /, the rules for URLs (a document called RFC 3986) say the host is empty and everything after the third slash is the path. libcurl instead took the first piece of the path and called it the host. So a URL that should point at no particular machine was quietly turned into a URL pointing at a machine named in the path.
That matters because many programs build a URL from something a user typed, then ask libcurl for the host and check it against a list of allowed hosts. If libcurl reports a different host than the one the rules say, the check can be fooled, and the program can be made to send requests to a machine the attacker chose. The report shows this with a cloud metadata address, a special internal address that cloud servers use to hand out information about themselves.
Context
curl is a command-line tool and a library for transferring data with URLs. You can think of it as the engine behind the scenes in many programs that need to download or upload something. libcurl is the library underneath the tool: the reusable code that other software includes so it does not have to write its own URL handling.
Among libcurl's public interfaces is the URL API. An API (application programming interface) is simply a set of functions a program can call to ask another piece of software to do something. Here the URL API lets an application hand over a URL and get back its parts one by one: the scheme, the host, the path and so on. A useful comparison is a postal address: you can ask for just the street, just the city, or just the postcode, instead of getting the whole line back.
The function that does the parsing is parseurl() in lib/urlapi.c. Parsing means reading a piece of text and working out its structure, the way you might read [redacted] and recognise a name, an at sign and a domain.
The report concerns how that parser handles a URL with an empty authority. The authority is the part of a URL that names the machine, and in http://example.com/page it is example.com. Under RFC 3986, the authority is whatever sits between // and the next /. When nothing sits between them, the authority is empty and everything after the third slash belongs to the path. The parser instead promoted the first path segment to the hostname.
Setup
The issue was confirmed on two libcurl versions:
- libcurl 8.5.0, as shipped on Ubuntu 24.04
- libcurl 8.21.0, described in the report as the latest at the time
Ubuntu is a popular Linux operating system, and 24.04 is one of its releases. A version number like 8.5.0 identifies exactly which build of the software is in use, which matters because bugs come and go between releases.
The CLI banner reported for the first environment was:
curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13
This is the line curl prints when you ask it for its version. Read it piece by piece:
curl 8.5.0is the version of the command-line tool.(x86_64-pc-linux-gnu)describes the kind of computer and operating system it was built for: a 64-bit Linux machine.libcurl/8.5.0is the version of the library doing the real work.OpenSSL/3.0.13is the separate library curl uses for encrypted connections, such as HTTPS.
The researcher used an attached program, poc_tripleslash.c, together with the curl command-line tool. C is a programming language often used for system software. A proof of concept (PoC) is a small, deliberately simple program that demonstrates a bug exists, without needing the full application around it. No account, role or special configuration is described.
Finding it
The starting point is the RFC 3986 rule for the authority component: for http:///host/path, the authority between // and / is empty, so /host/path is the path. RFC 3986 is the document that defines how URLs are written and read; think of it as the grammar book for web addresses.
The parser in lib/urlapi.c did not follow that. Around line 1087, the slash counter i reaches 3, which is still inside the valid 1 to 3 range the code accepts, and hostp is set to whatever follows the third slash. In plain terms, the code counts slashes to decide where the host begins, and it treats three slashes as if the host started after the third one. The result is that the first path segment is treated as the hostname.
The report notes that the file:// scheme already has special handling that deals correctly with an empty authority, and argues that this handling should be generalised to the other schemes. A scheme is the first word of a URL, the part before ://, which tells the software what kind of address it is: http for web pages, file for files on the local disk. The file scheme already copes with an empty authority, so the suggestion is to reuse that logic everywhere.
Exploitation
Exploitation means actually using the bug to produce a wrong or harmful result, rather than just suspecting it exists. Here the steps are simple and do not involve any attack on a live service.
Step 1: build and run the proof of concept
Compile and run the attached poc_tripleslash.c
Compiling is the step that turns human-readable C source code into a program the computer can run. The report gives no further detail about the program beyond compiling and running it. The reason for this step is to test the library directly, without any other software in between, so that whatever comes back is clearly the library's own answer.
Step 2: observe the parsed components
The input and the observed result:
http:///[redacted]/latest/meta-data/
→ host="[redacted]", path="/latest/meta-data/"
This block shows what was fed in and what came back. The input is a URL with three slashes after http:. The arrow separates input from output. The library reported the host as [redacted] and the path as /latest/meta-data/. The address [redacted] is used by cloud metadata endpoints, an internal service on cloud servers. The reason for choosing it is that it makes the consequence obvious: a URL that should have no host at all ends up pointing at a sensitive internal address.
The expected result, per the RFC, is an empty host and the full remainder as the path:
Expected: host="" (empty authority), path="/[redacted]/latest/meta-data/"
Here the host is the empty string, shown as "", and the whole remainder including the address is part of the path. The reason for writing the expected result next to the observed one is to make the disagreement visible: the same input produces two different readings, and the library's reading is the wrong one.
Instead of an empty authority, the first segment [redacted] was returned as the host, and the path lost that segment.
Step 3: confirm through the CLI
The same behaviour was reproduced with the curl command line, printing the effective URL:
curl -w "%{url_effective}" http:///path
This is a single shell command. Read it in parts:
curlruns the tool.-w "%{url_effective}"tells curl to print a piece of information after the request, here the effective URL, meaning the URL curl actually ended up using after any rewriting. The%{...}syntax is curl's way of naming a value to print.http:///pathis the URL being tested, with three slashes and a single path segment.
The report also confirms the same behaviour through the curl command line.
The output was:
http://path/
The path segment path had become the hostname, and the effective URL was rewritten accordingly. In other words, curl took the word path, decided it was the machine name, and rebuilt the address around it.
Root cause
A root cause is the underlying reason a bug happens, as opposed to where it shows up. The bug is in parseurl() in lib/urlapi.c. The slash counter i reaches 3, which the code accepts as within the valid 1 to 3 range, and hostp is then set to whatever follows the third slash. The parser therefore does not distinguish between //host/path (a real authority) and ///path (an empty authority followed by a path). The file:// scheme has separate handling that copes with an empty authority correctly, but that handling was not applied to the other schemes.
A weakness class is a label for the kind of mistake, used to group similar bugs together. This one means the software worked out a name (here, the host) incorrectly and then acted on that wrong name.
Impact
Impact is what an attacker could actually achieve. An application that builds URLs from user input and then validates the parsed hostname via curl_url_get(CURLUPART_HOST) can be tricked into making requests to attacker-chosen hosts. curl_url_get is the URL API function that reads one part back out of a parsed URL, and CURLUPART_HOST says which part: the host.
The report gives a concrete pattern: if user input /[redacted]/latest/meta-data/ is appended to http://, curl parses the host as [redacted], which enables SSRF to cloud metadata endpoints. SSRF, server-side request forgery, is when an attacker can make a server send a request to an address of the attacker's choosing, often an internal one the attacker could not reach directly. A comparison: a receptionist who will dial any number you give them, including internal extensions you were never meant to call.
An application that validates the parsed hostname via curl_url_get(CURLUPART_HOST) can be tricked this way. Where that is the case, a hostname check that looks correct can be bypassed because the parser and the application disagree with the RFC about which part of the string is the host.
Fix
The report does not describe a patch. Its recommendation is to generalise the existing file:// handling of an empty authority to the other schemes, so that http:///host/path parses with an empty host and /host/path as the path.
Variants to test
A variant is a slightly different input that might trigger the same underlying mistake. Testing variants shows how wide the problem is.
- Other schemes with an empty authority, such as
https:///host/path, to see whether the same promotion of the first path segment to host occurs. - More than three slashes, to check how the slash counter behaves outside the accepted 1 to 3 range.
- The
file://scheme itself, as a control: the report says it handles an empty authority correctly, so it should return an empty host. A control is a case you already know the right answer for, used to check your test setup is sound. - Applications that append user input to a scheme prefix and then validate with
curl_url_get(CURLUPART_HOST), checking whether a leading/in the input changes the parsed host.
A positive result is a parsed host that is non-empty when the authority in the input is empty, with the first path segment appearing as the host.
Hunting notes
Hunting notes are tips for finding similar bugs yourself. This kind of bug hides in URL parsers and in the gap between what a parser returns and what the surrounding application assumes. The signal is a URL form with an empty authority, scheme:///..., which most people never type and most test suites never cover. Comparing the parser's output against the RFC for such inputs, and against the behaviour of other schemes in the same library, is a quick way to spot inconsistencies.
To show impact, the researcher demonstrated the misparse both through the library API and through the curl CLI, and tied it to a realistic SSRF path against a cloud metadata address.
Glossary
- API: a set of functions one program offers so another program can ask it to do something.
- Authority: the part of a URL that names the machine, sitting between
//and the next/. - CLI: command-line interface, a way of running a program by typing commands rather than clicking.
- Compile: turn source code written by a person into a program the computer can run.
- Control: a test case whose correct result you already know, used to check your setup.
- curl: a command-line tool and library for transferring data with URLs.
- Effective URL: the URL a tool actually used after any rewriting.
- Host: the machine name inside a URL, such as
example.com. - Impact: what an attacker could actually achieve by using a bug.
- libcurl: the library underneath curl, used by other software to handle URLs and transfers.
- Link-local address: an address used only on the local network segment, such as
[redacted]. - Metadata service: an internal endpoint on cloud servers that describes the running server.
- Parse: read text and work out its structure.
- Path: the part of a URL after the host, naming the resource on that machine.
- PoC (proof of concept): a small program that demonstrates a bug exists.
- RFC 3986: the document that defines how URLs are written and read.
- Root cause: the underlying reason a bug happens.
- Scheme: the first word of a URL, such as
httporfile, saying what kind of address it is. - SSRF: server-side request forgery, making a server send a request to an address of the attacker's choosing.
- URL: the address of something on a network, such as a web page.
- URL API: libcurl's interface for breaking a URL into its parts and reading them back.
- Variant: a slightly different input that might trigger the same bug.
- Weakness class: a label grouping similar kinds of mistake.