From 68d0e12bdb574838473ecdce00102eabc4270119 Mon Sep 17 00:00:00 2001 From: pshu Date: Thu, 12 Jan 2023 17:31:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20delete=20defineProperty=20to=20r?= =?UTF-8?q?ecover=20doc.currentScript=20(#2372)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sandbox/patchers/dynamicAppend/common.ts | 10 ++++++++++ src/sandbox/proxySandbox.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sandbox/patchers/dynamicAppend/common.ts b/src/sandbox/patchers/dynamicAppend/common.ts index cfc309646..b99cb95bf 100644 --- a/src/sandbox/patchers/dynamicAppend/common.ts +++ b/src/sandbox/patchers/dynamicAppend/common.ts @@ -283,6 +283,7 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { const scopedGlobalVariables = speedySandbox ? trustedGlobals : []; if (src) { + let isRedfinedCurrentScript = false; execScripts(null, [src], proxy, { fetch, strictGlobal, @@ -299,14 +300,23 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { }, configurable: true, }); + isRedfinedCurrentScript = true; } }, success: () => { manualInvokeElementOnLoad(element); + if (isRedfinedCurrentScript) { + // @ts-ignore + delete document.currentScript; + } element = null; }, error: () => { manualInvokeElementOnError(element); + if (isRedfinedCurrentScript) { + // @ts-ignore + delete document.currentScript; + } element = null; }, }); diff --git a/src/sandbox/proxySandbox.ts b/src/sandbox/proxySandbox.ts index 23f263e26..1c312c76e 100644 --- a/src/sandbox/proxySandbox.ts +++ b/src/sandbox/proxySandbox.ts @@ -161,7 +161,8 @@ export default class ProxySandbox implements SandBox { } // the descriptor of global variables in whitelist before it been modified - globalWhitelistPrevDescriptor: { [p in typeof globalVariableWhiteList[number]]: PropertyDescriptor | undefined } = {}; + globalWhitelistPrevDescriptor: { [p in (typeof globalVariableWhiteList)[number]]: PropertyDescriptor | undefined } = + {}; globalContext: typeof window; constructor(name: string, globalContext = window) {