You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
url.parse does not strip leading C0 control characters, returning protocol: null for '\x00javascript:...' #79
In url 0.11.4 (and master at 455a3e2, as well as the bundled copy in node-stdlib-browser 1.3.1), url.parse() uses String.prototype.trim() before matching the scheme, which does not strip C0 control characters (U+0000–U+001F other than \t\n\v\f\r). When a URL starts with a C0 control character, url.parse() fails to recognize the scheme or host (returning protocol: null and host: null), whereas both Node.js node:url and browsers (WHATWG URL) strip leading C0 controls and parse the scheme/host normally—allowing javascript: URI or host-check sanitizers built on url.parse() in browser bundles to be bypassed.
Expected:url.parse('\x00javascript:alert(1)').protocol returns 'javascript:' and url.parse('\x00\x00http://evil.com/').host returns 'evil.com', matching Node.js url.parse and browser URL parsing.
Actual:url.parse('\x00javascript:alert(1)').protocol returns null, url.parse('\x1fjavascript:alert(1)').protocol returns null, and url.parse('\x00\x00http://evil.com/').host returns null.
Reference:defunctzombie/node-url README states the module is meant to have feature parity with Node.js core url, which strips leading and trailing C0 controls and spaces per nodejs/node#42196 and the WHATWG URL Standard (URL parsing).
In url.js (Url.prototype.parse), rest = rest.trim() only strips ECMAScript whitespace, leaving leading C0 controls in rest so protocolPattern (/^([a-z0-9.+-]+:)/i) fails to match; stripping leading and trailing code points <= 0x20 (as in nodejs/node#42196) resolves the mismatch.
Activity