Abusing URI Parsers for fun and profit
A URI parser treated a hostname with a trailing dot as different from the same hostname without it, even though RFC 1034 says they are equivalent. An attacker could bypass host-based access checks that rely on this parser, for example to read a file that should be forbidden.
Published on huntingreads.com
This is a write-up about a security issue I found on one of the famous URI parsers.
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.
Context
This is a write-up about a security issue I found in one of the well-known URI parsers. Because it was my first discovery in a framework, and because I believe the same issue can be found in many different URI parsers and in many websites that use any sort of URL parser (such issues often lead to high severity bugs), I am disclosing the finding in this paper. To respect the terms and policies of the company, I have redacted their name and the parser's name.
The target was a company whose scope was limited to observing code on GitHub. The scope item looked like this:
https://github.com/someName-Of-uri-parser
So the product under test is a URI parsing library, and the feature at issue is its URL comparison function, which decides whether two URLs are equal.
Setup
It had been a long time since I had opened my PC for hunting security vulnerabilities. I requested invites to Bugcrowd Support, which resulted in an invitation from the company above. I had no experience in testing for issues that way, but while checking out the scope I thought I would try something new.
Some days before the invitation I had already done some testing on the parser, analysing how it works and how it handles URLs, so I started from there. The proof of concept I later wrote runs with NodeJS.
Finding it
According to the RFC, the following two URLs are exactly the same:
https://huntingreads.com
https://huntingreads.com.
Notice the dot at the end. This is detailed in rfc1034.
With this in mind I passed different URLs in comparisons to the framework:
redacted.isequal("https://abc.com", "https://abc.com.")
false
redacted.isequal("https://abc.com", "https://ABC.COM.")
false
redacted.isequal("https://abc.com:80", "https://ABC.COM:.")
false
redacted.isequal("https://abc.com:80", "https://ABC.COM.")
false
redacted.isequal("https://abc.com:443", "https://ABC.COM.")
false
Every comparison returned false, even though the RFC treats the trailing-dot form as the same host. Noticing this behaviour, I sent a report explaining how this can go wrong if websites implement their parsers for deciding any critical or sensitive logic. The triage reply was:
The main focus for any security researcher or bug bounty hunter is to demonstrate an impact by proving it, so I wrote some code as my PoC to do that, running with NodeJS.
Exploitation
Step 1: build a server that relies on the parser for access control
The demonstration code creates an HTTP server that reconstructs the full URL from the Host header and the request path, and uses the parser's equality check to block access to one sensitive file:
var http = require('http');
var fs = require('fs');
const URI = require("redacted-parser");
// create a http server
http.createServer(function (req, res) {
host = req.headers.host
var fullURL = "http://" + host + req.url;
if (redacted.isequal(fullURL, "http://[redacted]/some-sensitive-file.txt") === true) {
console.log("This page is forbidden!")
console.log(fullURL)
return res.end();
} else {
// for other URLs, try responding with the page
console.log(req.url)
console.log(fullURL)
// read requested file
fs.readFile(req.url.substring(1),
function(err, data) {
if (err) throw err;
res.writeHead(200);
res.write(data.toString('utf8'));
return res.end();
});
}
}).listen(80);
What this code does is check whether a user requests the http://[redacted]/some-sensitive-file.txt endpoint. If they do, it restricts them from reading its contents; otherwise it loads the contents of the requested endpoint normally. There are many different ways this can go wrong, but I chose this example to demonstrate the impact.
Step 2: confirm the restriction works for the normal form
From the code above we can conclude that a request such as curl http://127.0.0.1./readableFile.txt will return the contents of readableFile.txt, but attempting to read some-sensitive-file.txt will print the forbidden message.
Example showing the path is restricted.
Step 3: bypass the check with a trailing dot on the host
Because of the parser issue, we can still read the restricted file's contents if we append a dot to the host value. A simple curl request with any flags will not work, by the way, because curl will generally strip off the dot. So to read the restricted file we send the request with an explicit Host header carrying the trailing dot:
curl -v http://127.0.0.1./some-sensitive-file.txt -H "Host: 127.0.0.1."
The Host header is set to 127.0.0.1.. The server builds fullURL from that header, the parser's equality check against http://[redacted]/some-sensitive-file.txt returns false, the forbidden branch is skipped, and the file is read and returned.
PoC screenshot.
I also found some other issues in their parsers, which they declined to accept, saying that the framework's focus is to parse URIs and not URLs. I am sure those will be good to know when testing other websites that rely on these parsers, so I may write about them in the near future.
Root cause
The parser's equality function treats a host with a trailing dot as different from the same host without it. RFC 1034 treats a host with a trailing dot as the same host, but the parser does not, so https://abc.com and https://abc.com. compare as different. Any application that uses this comparison to make a security decision, such as deciding whether a request targets a forbidden endpoint, can be steered around the decision by presenting the same resource in the trailing-dot form.
Impact
Where a site uses such a parser to decide critical or sensitive logic, an attacker can reach resources the logic is meant to protect. In the demonstration, the protected file some-sensitive-file.txt on [redacted] is readable by sending the request with a trailing dot in the host. The impact depends entirely on what the application gates with the comparison; the report frames this as a class of issue that can affect many URI parsers and many websites using URL parsers, and notes that such bugs often lead to high severity issues.
Fix
The report does not describe a fix applied by the vendor.
Variants to test
- Trailing dot on the host: compare
https://abc.comwithhttps://abc.com.. A positive result is the parser reporting them as different, as in the report. - Case differences combined with the trailing dot: compare
https://abc.comwithhttps://ABC.COM.. A positive result isfalsefrom the equality check. - Explicit port with a trailing dot: compare
https://abc.com:80withhttps://ABC.COM., andhttps://abc.com:443withhttps://ABC.COM.. A positive result isfalsein each case. - Malformed port with a trailing dot: compare
https://abc.com:80withhttps://ABC.COM:.. A positive result isfalse. - Live bypass: against a server that gates a path using the parser, send the request with a trailing dot in the
Hostheader, as in the curl command above, and check whether the protected content is returned instead of the forbidden response.
Timeline
| Event | Time |
|---|---|
| Time to triage | 2 days |
| Bounty rewarded | After about a month |
| Reward | $500 |
What happened, in plain words
A security researcher found a small flaw in a piece of software that many websites use behind the scenes: a URI parser. A URI parser is a helper program that takes a web address (like https://example.com/page) and breaks it into its parts so the rest of the website can reason about it: which site is it, which page, which port, and so on. Think of it like a postal sorting machine that reads the address on an envelope and decides which pigeonhole it belongs in. If the sorting machine misreads one address as a different address, the letter ends up in the wrong place.
The specific feature that was broken was the parser's equality check: a function that answers the question "are these two web addresses the same?". The researcher noticed that the parser said "no" for two addresses that, according to the internet's official rulebook (the RFC documents), are actually the same address. The difference was a single dot at the end of the site name.
Why does that matter? Because websites often use such a check to make security decisions, for example "block anyone trying to read this private file". If the check can be fooled into thinking a forbidden address is a different, allowed address, the block can be walked around. The researcher proved this with a small demonstration server, and the company paid a $500 bounty.
The company and the parser are not named in the write-up, to respect the company's rules.
Background: what a URI parser is and why anyone cares
Every time you type an address into your browser, a lot of software has to understand that address. The browser needs to know which server to contact, which page to ask for, whether to use a secure connection, and so on. Websites also do this on their own side: when a request arrives, the site's code often rebuilds the address from the pieces of the request and then makes decisions based on it.
A URI parser is the component that does this splitting and rebuilding. It is usually a small library, a reusable block of code that many projects include rather than writing themselves. Because so many projects use the same libraries, a single mistake in a popular parser can affect a very large number of websites at once. That is why the researcher calls this a class of issue worth writing about.
The feature at issue here is the parser's URL comparison function, which decides whether two URLs are equal. The researcher refers to it as redacted.isequal, where redacted stands for the parser's real name, which has been removed.
The setup: how the researcher got to the target
The researcher had not been hunting security vulnerabilities for a while. They requested invitations through Bugcrowd Support, a platform where companies publish programs that pay for security findings. That led to an invitation from a company whose scope, the list of things a researcher is allowed to test, was limited to observing code on GitHub. The scope item looked like this:
https://github.com/someName-Of-uri-parser
In other words, the thing under test was not a live website but a code repository: a URI parsing library published on GitHub. The researcher had no experience testing that way, but decided to try something new. Some days before the invitation they had already spent time on the parser, analysing how it works and how it handles URLs, so they started from that knowledge.
The proof of concept they later wrote runs with NodeJS, a program that lets you run JavaScript code outside a browser, typically on a server.
Finding it: the trailing dot
Here is the key fact. According to the internet's rules, written down in documents called RFCs (Request for Comments, the standards documents of the internet), these two addresses are exactly the same:
https://huntingreads.com
https://huntingreads.com.
Notice the dot at the end of the second one. This is detailed in rfc1034.
Why would a dot at the end mean nothing? Because of how the Domain Name System (DNS) works. DNS is the internet's phone book: it translates a human-friendly name like huntingreads.com into the numeric address of a server. The DNS rules treat a name as a sequence of labels separated by dots, and a name that ends with a dot is called a fully qualified domain name: it says explicitly "this is the complete name, nothing more to add". A name without the final dot may be completed with a search domain. So huntingreads.com and huntingreads.com. point at the same server. A useful comparison: writing "Main Street" or "Main Street." on an envelope does not change which street you mean.
With this in mind, the researcher passed different pairs of URLs to the parser's comparison function:
redacted.isequal("https://abc.com", "https://abc.com.")
false
redacted.isequal("https://abc.com", "https://ABC.COM.")
false
redacted.isequal("https://abc.com:80", "https://ABC.COM:.")
false
redacted.isequal("https://abc.com:80", "https://ABC.COM.")
false
redacted.isequal("https://abc.com:443", "https://ABC.COM.")
false
Line by line:
redacted.isequal("https://abc.com", "https://abc.com.")asks the parser whether the plain address and the same address with a trailing dot are equal. The answer printed isfalse, meaning the parser says they are different. According to the RFC they are the same, so this is the bug.redacted.isequal("https://abc.com", "https://ABC.COM.")adds a second difference: upper case letters. Site names are not case sensitive, soABC.COMandabc.comare the same site. The parser again answersfalse.redacted.isequal("https://abc.com:80", "https://ABC.COM:.")introduces a port. A port is a numbered door on a server; port 80 is the default door for ordinary unencrypted web traffic. Here the second address has a colon followed by a dot where the port number should be, which is malformed. The parser answersfalse.redacted.isequal("https://abc.com:80", "https://ABC.COM.")compares an address with an explicit port 80 against the upper-case form with a trailing dot and no port. The parser answersfalse.redacted.isequal("https://abc.com:443", "https://ABC.COM.")does the same with port 443, the default door for encrypted (HTTPS) traffic. Againfalse.
Every comparison returned false, even though the RFC treats the trailing-dot form as the same host. The researcher noticed this behaviour and sent a report explaining how this can go wrong if websites use such a parser to decide any critical or sensitive logic. In other words: if a website asks the parser "is this the forbidden address?" and the parser says "no" for a form that actually reaches the forbidden address, the website's protection is useless.
The company's first reply was:
This is a common stage in bug bounty work. Triage is the first review of a report, where the company decides whether it is valid and worth investigating. Here the reviewer accepted that the behaviour was real but asked for a PoC, a proof of concept: a concrete demonstration that the flaw can actually cause harm, not just a theoretical argument. The main focus for any security researcher or bug bounty hunter is to demonstrate an impact by proving it, so the researcher wrote code to do exactly that, running with NodeJS.
Exploitation
Step 1: build a server that relies on the parser for access control
The demonstration code creates a small web server that rebuilds the full URL from the request and uses the parser's equality check to block access to one sensitive file:
var http = require('http');
var fs = require('fs');
const URI = require("redacted-parser");
// create a http server
http.createServer(function (req, res) {
host = req.headers.host
var fullURL = "http://" + host + req.url;
if (redacted.isequal(fullURL, "http://[redacted]/some-sensitive-file.txt") === true) {
console.log("This page is forbidden!")
console.log(fullURL)
return res.end();
} else {
// for other URLs, try responding with the page
console.log(req.url)
console.log(fullURL)
// read requested file
fs.readFile(req.url.substring(1),
function(err, data) {
if (err) throw err;
res.writeHead(200);
res.write(data.toString('utf8'));
return res.end();
});
}
}).listen(80);
Line by line, in plain words:
var http = require('http');loads NodeJS's built-in module for running a web server. A module is a ready-made bundle of code you can pull into your own program.var fs = require('fs');loads the module that reads files from disk.fsstands for file system.const URI = require("redacted-parser");loads the parser library under test. The real name is replaced byredacted-parser.http.createServer(function (req, res) {starts defining a server. The function inside runs every time a request arrives.reqholds the incoming request,resis the reply being built.host = req.headers.hostreads theHostheader from the request. A header is a labelled line of extra information that travels with every web request. TheHostheader tells the server which site name the browser was trying to reach. It is supplied by the client, so it can be set to anything.var fullURL = "http://" + host + req.url;glues together a full address: the schemehttp://, then the host from the header, then the path the client asked for (req.url). This is the address the server will make its security decision about.if (redacted.isequal(fullURL, "http://[redacted]/some-sensitive-file.txt") === true) {asks the parser whether the rebuilt address is exactly the protected one.[redacted]is the loopback address, the address a computer uses to refer to itself. So the protected resource is a file on the server itself.console.log("This page is forbidden!")andconsole.log(fullURL)print a message and the address to the server's log, so the researcher can see what happened.return res.end();ends the response without sending the file. This is the block.} else {is the branch for every address that is not the protected one.console.log(req.url)andconsole.log(fullURL)log the request path and the rebuilt address.fs.readFile(req.url.substring(1),reads a file from disk.req.url.substring(1)drops the leading slash from the requested path, turning/readableFile.txtintoreadableFile.txt, a relative file name.- The function passed to
fs.readFileruns when the file has been read.if (err) throw err;stops with an error if the file could not be read. res.writeHead(200);sends the HTTP status code 200, which means "OK".res.write(data.toString('utf8'));sends the file contents as text.return res.end();finishes the response.}).listen(80);makes the server listen on port 80, the standard web port.
So what this code does is check whether a user requests the http://[redacted]/some-sensitive-file.txt endpoint. An endpoint is simply a specific address on a server that does a specific thing. If the user does request it, the server restricts them from reading its contents; otherwise it loads the contents of the requested endpoint normally. There are many different ways this can go wrong, but the researcher chose this example to demonstrate the impact.
Step 2: confirm the restriction works for the normal form
From the code above we can conclude that a request such as curl http://127.0.0.1./readableFile.txt will return the contents of readableFile.txt, but attempting to read some-sensitive-file.txt will print the forbidden message. curl is a command-line tool for sending web requests; think of it as a browser without a window.
Example showing the path is restricted.
Step 3: bypass the check with a trailing dot on the host
Because of the parser issue, the restricted file's contents can still be read if a dot is appended to the host value. A simple curl request with any flags will not work, by the way, because curl will generally strip off the dot. So to read the restricted file, the request is sent with an explicit Host header carrying the trailing dot:
curl -v http://127.0.0.1./some-sensitive-file.txt -H "Host: 127.0.0.1."
What each part does:
curlis the tool sending the request.-vmeans verbose: curl prints the details of the conversation, which helps when demonstrating a result.http://127.0.0.1./some-sensitive-file.txtis the address being requested, with a dot after the loopback address.-H "Host: 127.0.0.1."sets theHostheader explicitly to127.0.0.1., with the trailing dot. This matters because curl would otherwise normalise the address and remove the dot, and the trick would be lost.
The server builds fullURL from that header, so fullURL becomes http://127.0.0.1./some-sensitive-file.txt. The parser's equality check against http://[redacted]/some-sensitive-file.txt returns false, because the two strings differ by the dot. The forbidden branch is skipped, the file is read and returned. The protection is bypassed without ever touching the protected address in the form the check expects.
PoC screenshot.
The researcher also found some other issues in the parser, which the company declined to accept, saying that the framework's focus is to parse URIs and not URLs. A URI is a broader term than URL: a URL is a locator (it says where something is), while a URI is any identifier (it may just name something). The distinction is subtle, and the researcher is sure the other findings will be good to know when testing other websites that rely on these parsers, so they may write about them in the near future.
Root cause
The parser's equality function treats a host with a trailing dot as different from the same host without it. Normalising means rewriting an address into one standard form before doing anything with it, the way you might rewrite "Main St." and "Main Street" into the same canonical text before comparing. RFC 1034 treats a host with a trailing dot as the same host, but the parser does not, so https://abc.com and https://abc.com. compare as different. Any application that uses this comparison to make a security decision, such as deciding whether a request targets a forbidden endpoint, can be steered around the decision by presenting the same resource in the trailing-dot form.
Impact
Where a site uses such a parser to decide critical or sensitive logic, an attacker can reach resources the logic is meant to protect. In the demonstration, the protected file some-sensitive-file.txt on [redacted] is readable by sending the request with a trailing dot in the host. The impact depends entirely on what the application gates with the comparison; the report frames this as a class of issue that can affect many URI parsers and many websites using URL parsers, and notes that such bugs often lead to high severity issues.
Fix
The report does not describe a fix applied by the vendor.
Variants to test
- Trailing dot on the host: compare
https://abc.comwithhttps://abc.com.. A positive result is the parser reporting them as different, as in the report. - Case differences combined with the trailing dot: compare
https://abc.comwithhttps://ABC.COM.. A positive result isfalsefrom the equality check. - Explicit port with a trailing dot: compare
https://abc.com:80withhttps://ABC.COM., andhttps://abc.com:443withhttps://ABC.COM.. A positive result isfalsein each case. - Malformed port with a trailing dot: compare
https://abc.com:80withhttps://ABC.COM:.. A positive result isfalse. - Live bypass: against a server that gates a path using the parser, send the request with a trailing dot in the
Hostheader, as in the curl command above, and check whether the protected content is returned instead of the forbidden response.
Timeline
| Event | Time |
|---|---|
| Time to triage | 2 days |
| Bounty rewarded | After about a month |
| Reward | $500 |
Glossary
- API: a defined way for one piece of software to talk to another; here, the functions a parser library offers to the code that uses it.
- Bounty: money a company pays a researcher for reporting a valid security issue.
- Bug bounty: a programme where companies invite researchers to look for security problems and reward valid reports.
- curl: a command-line tool for sending web requests.
- DNS (Domain Name System): the internet's phone book, translating names like
example.cominto numeric server addresses. - Endpoint: a specific address on a server that performs a specific action.
- Equality check: a function that answers whether two values are the same.
- Fully qualified domain name: a site name written with a trailing dot to mark it as complete.
- Header: a labelled line of extra information sent with a web request or response, such as
Host. - Host header: the header in a web request that says which site name the client was trying to reach; it is supplied by the client.
- HTTP: the protocol browsers and servers use to exchange web pages and data.
- HTTPS: HTTP carried over an encrypted connection.
- Library: a reusable bundle of code that projects include instead of writing the same thing themselves.
- Loopback address: the address
[redacted], which a computer uses to refer to itself. - Module: a ready-made bundle of code that a program can load.
- NodeJS: a program that runs JavaScript code outside a browser, typically on a server.
- Normalisation: rewriting a value into one standard form before comparing or using it.
- Parser: software that takes a structured text, such as a web address, and breaks it into its parts.
- PoC (proof of concept): a concrete demonstration that a flaw can actually cause harm.
- Port: a numbered door on a server; 80 is the default for HTTP, 443 for HTTPS.
- RFC (Request for Comments): the standards documents that define how the internet works.
- Scope: the list of systems a researcher is allowed to test in a bounty programme.
- Triage: the first review of a report, where the company decides whether it is valid.
- URI: a broad identifier for a resource; a URL is one kind of URI.
- URI parser: a library that splits and rebuilds URIs.
- URL: a locator that says where a resource is on the web.
- URL comparison function: the parser feature that decides whether two URLs are equal.
- Vulnerability: a weakness in software that can be used to make it behave in ways its author did not intend.