CRLF Injection in legacy url API (url.parse().hostname)
The legacy url.parse() API in Node.js returns a hostname that stops at an embedded carriage-return/line-feed sequence, while the newer URL API keeps the whole string. An attacker could use this difference to slip a crafted URL past a hostname whitelist check and reach a medium or high severity issue.
Originally disclosed on HackerOne
- Triaged in 5 hours
- Disclosed after 6 hours
Summary:
There is CRLF Injection in legacy url.hostname() API.
Description:
During the recent penetration test, I have found a whitelist bypass using CRLF Injection. We did a code review and determined the issue is in a legacy url.hostname() API. Not sure if it's a known issue or not, I wasn't able to find any report related to url.hostname().
Steps To Reproduce:
poc_url = "http://test1.com\n\rtest2.com"
const url = require('url');
console.log("Vulnerable: ", url.parse(poc_url).hostname)
console.log("\n")
const myURL = new URL(poc_url);
console.log("Not Vulnerable: ", myURL.hostname)
Not exactly sure where is the problem, but probably in here:
https://github.com/nodejs/node/blob/master/lib/url.js#L298-L340
Impact:
Even if it's legacy code, there still might be a lot of projects and codebases relying on it. As mentioned in the description, I was able to bypass a whitelist function during the recent penetration test and exploit a medium/high vulnerability thanks to it.
Supporting Material/References:
Poc:
poc_url = "http://test1.com\n\rtest2.com"
const url = require('url');
console.log("Vulnerable: ", url.parse(poc_url).hostname)
console.log("\n")
const myURL = new URL(poc_url);
console.log("Not Vulnerable: ", myURL.hostname)
Output:
Vulnerable: test1.com
Not Vulnerable: test1.comtest2.com
Impact
Whitelist function can use url.parse("https://example.com").hostname to check for allowed hostnames. It can be easily bypassed using CRLF injection and it can lead to whitelist bypass and compromise of the website.
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 the legacy url.parse() hostname parser does not reject or strip carriage-return and line-feed characters, so it truncates the hostname at the newline instead of treating the whole string as one host.
Impact
A whitelist check built on the legacy hostname value could be bypassed, which the reporter says led to a medium or high severity issue during a penetration test.
What the attacker needed
Code uses legacy url.parse().hostname; attacker controls the URL string
How it was found
- Build a URL string containing a newline and carriage return between two hostnames.
- Pass it to the legacy url.parse() function and read the hostname property.
- Pass the same string to the newer URL constructor and read its hostname property.
- Compare the two outputs to see the legacy API truncates while the new one does not.
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 whitelist is a list of allowed hostnames that code checks before trusting a link. The old url.parse() function in Node.js cuts the hostname short when it sees hidden newline characters, so a check can see an allowed name while the rest of the string is ignored. The newer URL class does not do this, so the two functions disagree about the same input.
What is Smuggling / CRLF?
A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.