Summary
Authorization bypass through user-controlled key in url-parse. It improperly handles username and password, and unable to detect the hostname.
Product
NPM url-parse prior to 1.5.6.
Impact
This issue may lead to the bypass of the hostname check.
Steps to reproduce
url-parse was not able to verify basic authentication credentials and it also wrongly verifies the hostname. This allows to bypass the hostname validation.
Let username be set as admin, password as password123@ and hostname as 127.0.0.1.
The url will be http://admin:password123@@127.0.0.1.
There is a blacklist check for domain 127.0.0.1 and every request to 127.0.0.1 will be blocked.
var cc=parse("http://admin:password123@@127.0.0.1")
Expected result:
protocol: 'http:',
hash: '',
query: '',
pathname: '/',
auth: 'admin:password123',
host: '@127.0.0.1',
port: '',
hostname: '@127.0.0.1',
password: 'password123',
username: 'admin',
origin: 'http://@127.0.0.1',
href: 'http://admin:password123@@127.0.0.1/' }
Incorrret detection of auth, origin, password and hostname.
Here hostname check cc.hostname is @127.0.0.1 and also cc.origin is http://@127.0.0.1 which will clearly bypass above 127.0.0.1 blacklist check.
Now if you use cc.href to fetch url it will fetch 127.0.0.1.
Remediation
Update url-parse to version 1.5.6.
Credit
This issue was reported by @ranjit-git through huntr.dev.