Skip to content

Commit 4aff4b9

Browse files
committed
trusted types - loader should use trusted script url when using script tags, #103699
1 parent de9e9c4 commit 4aff4b9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bootstrap-window.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@
9999
preferScriptTags: useCustomProtocol
100100
};
101101

102+
// use a trusted types policy when loading via script tags
103+
if (loaderConfig.preferScriptTags) {
104+
loaderConfig.trustedTypesPolicy = window.trustedTypes?.createPolicy('amdLoader', {
105+
createScriptURL(value) {
106+
if (value.startsWith(window.location.origin)) {
107+
return value;
108+
}
109+
throw new Error(`Invalid script url: ${value}`);
110+
}
111+
});
112+
}
113+
102114
// Enable loading of node modules:
103115
// - sandbox: we list paths of webpacked modules to help the loader
104116
// - non-sandbox: we signal that any module that does not begin with

0 commit comments

Comments
 (0)