Skip to content
XSS Disclosed report Intermediate

url.parse() hostname spoofing via javascript: URIs

bayotop Follow

Originally disclosed on HackerOne

Medium 6.1 View original
  • Triaged in 20 days
  • Fixed in 3 months
  • Disclosed after 17 months

Summary:

Using url.parse() in security sensitive checks is dangerous as an arbitrary hostname can be spoofed via javascript: URIs.

Description:

The original url.parse() API is dangerous as it allows to spoof an arbitrary hostname via a javascript: URI:

Bash
$ node -e 'console.log(require("url").parse("javAscript:alert(1);a=\[email protected]\x27"))'
Url {
  protocol: 'javascript:',
  slashes: null,
  auth: 'alert(1);a=\'',
  host: 'white-listed.com',
  port: null,
  hostname: 'white-listed.com',
  hash: null,
  search: null,
  query: null,
  pathname: '\'',
  path: '\'',
  href: 'javascript:alert(1)%3Ba%3D\'@white-listed.com\'' }

Steps To Reproduce:

  1. node -e 'console.log(require("url").parse("javAscript:alert(1);a=\[email protected]\x27"))'

After a quick look, I believe the issue stems from case-sensitive checks on lines 268 and 275

Additional notes:

I didn't set the severity as I have no idea how widely the "Legacy API" is still used and the actual impact is hugely context-based. For the sake of completeness, I found this issue when testing a real world app.

This also affects this npm package. The WHATWG API handles this particular case well.

In might be a good idea to mention in the documentation that URL parsing shouldn't be relied on in security relevant context. Exact string matching or similarly simple concepts should be always preferred.

Impact

This can be dangerous if used in security relevant access controls as follows:

JavaScript
let parsedUrl = UrlHelper.parse(url); // url = javAscript:alert(1);a='@localhost/'
if (parsedUrl.hostname === 'localhost') { // parsedUrl.hostname = localhost
  return true; // and do something like window.location = url 
}

Although being a bad practice, developers will write this code and will introduce bypassable access controls. Given that the bypass works only with javascript: URIs this will likely lead to XSS in most cases.

The original report as published on HackerOne, by bayotop. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A medium-severity XSS bug in https://github.com/nodejs/node, rated CVSS 6.1. HackerOne made it public on 15 January 2020.

About XSS

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by bayotop

View all

7 more disclosed reports, best first.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.