Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
esm: Ensure custom loader resolved "url" is properly validated#21352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bc83382cf1e32f65944621776edf888d186233cf2ad434368a235f08File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,123 @@ | ||
| // Flags: --experimental-modules | ||
| /* eslint-disable node-core/required-modules */ | ||
| importcommonfrom'./index.js'; | ||
| importassertfrom'assert'; | ||
| const{ | ||
| PORT, | ||
| isMainThread, | ||
| isWindows, | ||
| isWOW64, | ||
| isAIX, | ||
| isLinuxPPCBE, | ||
| isSunOS, | ||
| isFreeBSD, | ||
| isOpenBSD, | ||
| isLinux, | ||
| isOSX, | ||
| isGlibc, | ||
| enoughTestMem, | ||
| enoughTestCpu, | ||
| rootDir, | ||
| buildType, | ||
| localIPv6Hosts, | ||
| opensslCli, | ||
| PIPE, | ||
| hasIPv6, | ||
| childShouldThrowAndAbort, | ||
| ddCommand, | ||
| spawnPwd, | ||
| spawnSyncPwd, | ||
| platformTimeout, | ||
| allowGlobals, | ||
| leakedGlobals, | ||
| mustCall, | ||
| mustCallAtLeast, | ||
| mustCallAsync, | ||
| hasMultiLocalhost, | ||
| fileExists, | ||
| skipIfEslintMissing, | ||
| canCreateSymLink, | ||
| getCallSite, | ||
| mustNotCall, | ||
| printSkipMessage, | ||
| skip, | ||
| ArrayStream, | ||
| nodeProcessAborted, | ||
| busyLoop, | ||
| isAlive, | ||
| noWarnCode, | ||
| expectWarning, | ||
| expectsError, | ||
| skipIfInspectorDisabled, | ||
| skipIf32Bits, | ||
| getArrayBufferViews, | ||
| getBufferSources, | ||
| crashOnUnhandledRejection, | ||
| getTTYfd, | ||
| runWithInvalidFD, | ||
| hijackStdout, | ||
| hijackStderr, | ||
| restoreStdout, | ||
| restoreStderr, | ||
| isCPPSymbolsNotMapped | ||
| }=common; | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be sufficient to just export ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can only do this once we have named exports support for CommonJS modules. | ||
| letknownGlobals=[ | ||
| Buffer, | ||
| clearImmediate, | ||
| clearInterval, | ||
| clearTimeout, | ||
| global, | ||
| process, | ||
| setImmediate, | ||
| setInterval, | ||
| setTimeout | ||
| ]; | ||
| if(process.env.NODE_TEST_KNOWN_GLOBALS){ | ||
| constknownFromEnv=process.env.NODE_TEST_KNOWN_GLOBALS.split(','); | ||
| allowGlobals(...knownFromEnv); | ||
| } | ||
| exportfunctionallowGlobals(...whitelist){ | ||
| knownGlobals=knownGlobals.concat(whitelist); | ||
| } | ||
| exportfunctionleakedGlobals(){ | ||
| // Add possible expected globals | ||
| if(global.gc){ | ||
| knownGlobals.push(global.gc); | ||
| } | ||
| if(global.DTRACE_HTTP_SERVER_RESPONSE){ | ||
| knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE); | ||
| knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST); | ||
| knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE); | ||
| knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST); | ||
| knownGlobals.push(DTRACE_NET_STREAM_END); | ||
| knownGlobals.push(DTRACE_NET_SERVER_CONNECTION); | ||
| } | ||
| if(global.COUNTER_NET_SERVER_CONNECTION){ | ||
| knownGlobals.push(COUNTER_NET_SERVER_CONNECTION); | ||
| knownGlobals.push(COUNTER_NET_SERVER_CONNECTION_CLOSE); | ||
| knownGlobals.push(COUNTER_HTTP_SERVER_REQUEST); | ||
| knownGlobals.push(COUNTER_HTTP_SERVER_RESPONSE); | ||
| knownGlobals.push(COUNTER_HTTP_CLIENT_REQUEST); | ||
| knownGlobals.push(COUNTER_HTTP_CLIENT_RESPONSE); | ||
| } | ||
| constleaked=[]; | ||
| for(constvalinglobal){ | ||
| if(!knownGlobals.includes(global[val])){ | ||
| leaked.push(val); | ||
| } | ||
| } | ||
| if(global.__coverage__){ | ||
| returnleaked.filter((varname)=>!/^(?:cov_|__cov)/.test(varname)); | ||
| }else{ | ||
| returnleaked; | ||
| } | ||
| } | ||
| process.on('exit',function(){ | ||
| constleaked=leakedGlobals(); | ||
| if(leaked.length>0){ | ||
| assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`); | ||
| } | ||
| }); | ||
| export{ | ||
| PORT, | ||
| isMainThread, | ||
| isWindows, | ||
| isWOW64, | ||
| isAIX, | ||
| isLinuxPPCBE, | ||
| isSunOS, | ||
| isFreeBSD, | ||
| isOpenBSD, | ||
| isLinux, | ||
| isOSX, | ||
| isGlibc, | ||
| enoughTestMem, | ||
| enoughTestCpu, | ||
| rootDir, | ||
| buildType, | ||
| localIPv6Hosts, | ||
| opensslCli, | ||
| PIPE, | ||
| hasIPv6, | ||
| childShouldThrowAndAbort, | ||
| ddCommand, | ||
| spawnPwd, | ||
| spawnSyncPwd, | ||
| platformTimeout, | ||
| allowGlobals, | ||
| leakedGlobals, | ||
| mustCall, | ||
| mustCallAtLeast, | ||
| mustCallAsync, | ||
| hasMultiLocalhost, | ||
| fileExists, | ||
| skipIfEslintMissing, | ||
| canCreateSymLink, | ||
| getCallSite, | ||
| mustNotCall, | ||
| printSkipMessage, | ||
| skip, | ||
| ArrayStream, | ||
| nodeProcessAborted, | ||
| busyLoop, | ||
| isAlive, | ||
| noWarnCode, | ||
| expectWarning, | ||
| expectsError, | ||
| skipIfInspectorDisabled, | ||
| skipIf32Bits, | ||
| getArrayBufferViews, | ||
| getBufferSources, | ||
| crashOnUnhandledRejection, | ||
| getTTYfd, | ||
| runWithInvalidFD, | ||
| hijackStdout, | ||
| hijackStderr, | ||
| restoreStdout, | ||
| restoreStderr, | ||
| isCPPSymbolsNotMapped | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-format.mjs | ||
| import{expectsError, mustCall } from '../common' | ||
| import assert from 'assert' | ||
| import('../fixtures/es-modules/test-esm-ok.mjs') | ||
| .then(assert.fail, expectsError({ | ||
| code: 'ERR_INVALID_RETURN_PROPERTY_VALUE', | ||
| message: 'Expected string to be returned for the "format" from the ' + | ||
| '"loader resolve" function but got type undefined.' | ||
| })) | ||
| .then(mustCall()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-url.mjs | ||
| import{expectsError, mustCall } from '../common' | ||
| import assert from 'assert' | ||
| import('../fixtures/es-modules/test-esm-ok.mjs') | ||
| .then(assert.fail, expectsError({ | ||
| code: 'ERR_INVALID_RETURN_PROPERTY', | ||
| message: 'Expected a valid url to be returned for the "url" from the ' + | ||
| '"loader resolve" function but got ' + | ||
| '../fixtures/es-modules/test-esm-ok.mjs.' | ||
| })) | ||
| .then(mustCall()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export async function resolve(specifier, parentModuleURL, defaultResolve){ | ||
| if (parentModuleURL && specifier === '../fixtures/es-modules/test-esm-ok.mjs'){ | ||
| return{ | ||
| url: 'file:///asdf' | ||
| }; | ||
| } | ||
| return defaultResolve(specifier, parentModuleURL); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export async function resolve(specifier, parentModuleURL, defaultResolve){ | ||
| if (parentModuleURL && specifier === '../fixtures/es-modules/test-esm-ok.mjs'){ | ||
| return{ | ||
| url: specifier, | ||
| format: 'esm' | ||
| }; | ||
| } | ||
| return defaultResolve(specifier, parentModuleURL); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name here might be better as:
ERR_INVALID_RETURN_PROPERTY_TYPE?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, the consistent name here would be
ERR_INVALID_RETURN_PROPERTY_VALUEactually :)