-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: protect
ERR_UNSUPPORTED_DIR_IMPORT
against prototype pollution
PR-URL: #49060 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
- Loading branch information
Showing
3 changed files
with
24 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
import '../common/index.mjs'; | ||
import { mustNotCall } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import assert from 'assert'; | ||
|
||
async function main() { | ||
let mod; | ||
try { | ||
mod = await import('../fixtures/es-modules/pjson-main'); | ||
} catch (e) { | ||
assert.strictEqual(e.code, 'ERR_UNSUPPORTED_DIR_IMPORT'); | ||
} | ||
Object.defineProperty(Error.prototype, 'url', { | ||
get: mustNotCall('get %Error.prototype%.url'), | ||
set: mustNotCall('set %Error.prototype%.url'), | ||
}); | ||
Object.defineProperty(Object.prototype, 'url', { | ||
get: mustNotCall('get %Object.prototype%.url'), | ||
set: mustNotCall('set %Object.prototype%.url'), | ||
}); | ||
|
||
assert.strictEqual(mod, undefined); | ||
await assert.rejects(import('../fixtures/es-modules/pjson-main'), { | ||
code: 'ERR_UNSUPPORTED_DIR_IMPORT', | ||
url: fixtures.fileURL('es-modules/pjson-main').href, | ||
}); | ||
|
||
try { | ||
mod = await import('../fixtures/es-modules/pjson-main/main.mjs'); | ||
} catch (e) { | ||
console.log(e); | ||
assert.fail(); | ||
} | ||
|
||
assert.strictEqual(mod.main, 'main'); | ||
} | ||
|
||
main(); | ||
assert.deepStrictEqual( | ||
{ ...await import('../fixtures/es-modules/pjson-main/main.mjs') }, | ||
{ main: 'main' }, | ||
); |