Stage | 2 |
Spec | source, output |
Tests | TODO |
Champion | @mikesamuel |
Reviewers | @bakkot, @erights, @bmeck |
Trusted Types guards sensitive APIs; it double checks that values have been trusted by policy code before performing operations that cannot be undone.
The dynamic import operator, import(...)
, loads code and initializes modules.
Loading code from an untrustworthy source is an operation that cannot be undone.
This adjusts the host callout which enables dynamic loading. With it:
Tests, to be written, will be implemented as web-platform-tests and will focus on the following properties:
Polymorphic objects stringified once. Something like
importScripts("/resources/testharness.js");
test(
() => {
let stringifyCount = 0;
import({
toString() {
let specifier = `data:text/javascript,export default ${ stringifyCount }`;
++stringifyCount;
return specifier;
}
})
.then(
(defaultExport) => {
assert_equals(stringifyCount, 1);
assert_equals(defaultExport, 0);
},
(err) => {
assert_equals(err, null);
})
.finally(done);
},
'DynamicImportStringifiesSpecifierOnce');
See also webappsec-csp #243
on import('data:...')
as CSP bypass.