diff options
author | Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> | 2022-01-19 08:28:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 08:28:32 +0300 |
commit | dbc6e39ca7306b0998beb683193483bf9c898100 (patch) | |
tree | ad5fe3859954b2542d12d6d74c94a531e1cb8eda /lib | |
parent | b9258e5e81408c02a7efe14207960ba7ea12f5ff (diff) |
esm: improve validation of resolved URLs
PR-URL: https://github.com/nodejs/node/pull/41446
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/modules/esm/loader.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 91f570297be..1707db8b185 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -29,7 +29,7 @@ const { ERR_INVALID_RETURN_VALUE, ERR_UNKNOWN_MODULE_FORMAT } = require('internal/errors').codes; -const { pathToFileURL, isURLInstance } = require('internal/url'); +const { pathToFileURL, isURLInstance, URL } = require('internal/url'); const { isAnyArrayBuffer, isArrayBufferView, @@ -558,7 +558,8 @@ class ESMLoader { format, ); } - if (typeof url !== 'string') { + + if (typeof url !== 'string') { // non-strings can be coerced to a url string throw new ERR_INVALID_RETURN_PROPERTY_VALUE( 'string', 'loader resolve', @@ -567,6 +568,8 @@ class ESMLoader { ); } + new URL(url); // Intentionally trigger error if `url` is invalid + return { format, url, |