Skip to content
XSS Disclosed report Intermediate CVE-2022-0691

url-parse incorrectly parses hostname / protocol due to unstripped leading control characters.

The url-parse library fails to strip leading control characters from URLs, so it may treat a URL as relative when the WHATWG parser would treat it as absolute. If url-parse is used for security checks on hostname or protocol, an attacker could bypass those checks, potentially leading to XSS when checking for the javascript: protocol.

github/advisory-database

Originally disclosed on huntr

Leading control characters in a URL are not stripped when passed into url-parse. This can cause input URLs to be mistakenly be interpreted as a relative URL without a hostname and protocol, while the WHATWG URL parser will trim control characters and treat it as an absolute URL.

If url-parse is used in security decisions involving the hostname / protocol, and the input URL is used in a client which uses the WHATWG URL parser, the decision may be incorrect.

This can also lead to a cross-site scripting (XSS) vulnerability if url-parse is used to check for the javascript: protocol in URLs. See following example:

JavaScript
const parse = require('url-parse')
const express = require('express')
const app = express()
const port = 3000

url = parse(\"\\bjavascript:alert(1)\")

console.log(url)

app.get('/', (req, res) => {
 if (url.protocol !== \"javascript:\") {res.send(\"<a href=\\'\" + url.href + \"\\'>CLICK ME!</a>\")}
 })

app.listen(port, () => {
 console.log(`Example app listening on port ${port}`)
 })

From the GitHub Advisory Database (GHSA-jf5r-8hm2-f872, CC BY 4.0).

The original report as published on the GitHub Advisory Database. Images and videos are our own copies; raw HTML is shown as text. View it on GitHub Advisory Database.

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 library does not strip leading control characters before parsing, unlike the WHATWG URL standard.

Impact

If url-parse is used in security decisions involving hostname or protocol, the decision may be incorrect, potentially leading to XSS when checking for the javascript: protocol.

What the attacker needed

Url-parse used for security checks; client uses WHATWG URL parser

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 parser is a tool that breaks a web address into parts like the protocol (e.g., 'https:') and the hostname (e.g., 'example.com'). This library, url-parse, does not remove invisible control characters at the start of a URL, so it may think the URL is relative (like a file path) while browsers remove those characters and treat it as a full address. If a website uses url-parse to decide whether a link is safe, an attacker could craft a link that looks harmless to url-parse but is actually dangerous in a browser, such as one starting with 'javascript:'.

What is XSS?

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

More from github/advisory-database

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.