Skip to content

Commit

Permalink
make sure trusted types array includes defaults from every new window
Browse files Browse the repository at this point in the history
  • Loading branch information
weizman committed Jun 20, 2023
1 parent 443eb1f commit dd9d85b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions snow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1196,21 +1196,22 @@ const {
Function
} = __webpack_require__(14);
function getHook(win, native) {
trustedHTMLs.push(win.trustedTypes.emptyHTML);
return function (a, b) {
const ret = Function.prototype.call.call(native, this, a, b);
trustedHTMLs.push(ret);
return ret;
};
}
function hookTrustedHTMLs(win) {
if (typeof TrustedTypePolicy === 'undefined') {
if (typeof win.TrustedTypePolicy === 'undefined') {
return;
}
const desc = Object.getOwnPropertyDescriptor(TrustedTypePolicy.prototype, 'createHTML');
const desc = Object.getOwnPropertyDescriptor(win.TrustedTypePolicy.prototype, 'createHTML');
desc.configurable = desc.writable = true;
const val = desc.value;
desc.value = getHook(win, val);
Object.defineProperty(TrustedTypePolicy.prototype, 'createHTML', desc);
Object.defineProperty(win.TrustedTypePolicy.prototype, 'createHTML', desc);
}
module.exports = hookTrustedHTMLs;

Expand Down

0 comments on commit dd9d85b

Please sign in to comment.