[url-parse] Improper Validation and Sanitization
In the browser build of url-parse, a URL string that fails the protocol validation expression falls back to the page's own protocol instead of returning an empty protocol. An attacker could supply a crafted URL value that slips past validation and sanitisation that relies on the parsed protocol.
- Triaged in 15 days
- Fixed in 11 months
- Disclosed after 11 months
NOTE! Thanks for submitting a report! Please replace all the [square] sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report!
I would like to report Improper Validation and Sanitization in url-parse.
It allows attacker-controlled URL values to bypass validation and sanitization.
Module
module name: url-parse
version: 1.4.4
npm page: https://www.npmjs.com/package/url-parse
Module Description
The url-parse method exposes two different API interfaces. The url interface that you know from Node.js and the new URL interface that is available in the latest browsers.
Module Stats
Replace stats below with numbers from npm’s module page:
5,544,078 downloads in the last week
Vulnerability
Vulnerability Description
When using url-parse in the browser the protocol of the URL returned by the parser is not validated correctly. In the Node.js environment strings like, javascript: return and empty string on the resulting URL object, but in the browser the current document.location.protocol is used when the provided URL doesn't match the validation expression /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i.
Steps To Reproduce:
Add the following test to test/test.js and run npm run test-browser.
assume(parse.extractProtocol(' javscript:')).eql({ slashes: false, protocol: '', rest: '' })
Wrap up
Line 199 in index.js is setting the protocol to location.protocol, this is probably not the right move.
url protocol = extracted.protocol || location.protocol || '';
Select Y or N for the following statements:
- I contacted the maintainer to let them know: [Y]
- I opened an issue in the related repository: [N]
Impact
Bypass input sanitization and validation.
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 browser code path falls back to the current page's protocol when the supplied URL does not match the validation pattern, rather than returning an empty protocol as the Node.js path does.
Impact
Applications that rely on the parsed protocol for validation or sanitisation could be bypassed in the browser, though the report gives no concrete exploit beyond that.
What the attacker needed
Library used in a browser; attacker controls the URL string
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 splits a web address into parts such as the protocol (the 'http' or 'javascript' bit at the front). This library checks the protocol with a pattern, but in a browser, when the pattern does not match, it quietly uses the protocol of the current page instead of reporting nothing. That means code trusting the parser can be fooled about what kind of link it is handling.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.