From c51d925c84918dbfbfa1bfe98d1948079265ae48 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Mon, 20 Mar 2017 11:40:54 -0700 Subject: [PATCH] url: restrict setting protocol to "file" Since file URLs can not have `username/password/port`, the specification was updated to restrict setting protocol to "file". Refs: https://github.com/whatwg/url/pull/269 Fixes: https://github.com/nodejs/node/issues/11785 PR-URL: https://github.com/nodejs/node/pull/11887 Reviewed-By: James M Snell Reviewed-By: Timothy Gu Reviewed-By: Joyee Cheung --- lib/internal/url.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/internal/url.js b/lib/internal/url.js index 3dc317a8bbb7c3..ad3f0d6f0bbab0 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -122,6 +122,13 @@ function onParseProtocolComplete(flags, protocol, username, password, if ((s && !newIsSpecial) || (!s && newIsSpecial)) { return; } + if (protocol === 'file:' && + (ctx.username || ctx.password || ctx.port !== undefined)) { + return; + } + if (ctx.scheme === 'file:' && !ctx.host) { + return; + } if (newIsSpecial) { ctx.flags |= binding.URL_FLAGS_SPECIAL; } else {