Advisory

GHSA-jf5r-8hm2-f872

Also known as: CVE-2022-0691

Summary

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

Details

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:

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}`)
 })

Severity

Medium Basis: The source's own band: MODERATE

Dates

Published
2022-02-22 00:00 UTC
Modified
2026-02-03 22:19 UTC

Affected packages and fixes

url-parse

npm · All systems

Affected

  • introduced 0.1.0, fixed 1.5.9 (semver)

Fixed versions

1.5.9

Fix

Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.

Check your own computer: guard packages check

View this record on OSV.dev

Source

Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0

Sources & licences