From fef50e59f231557ddf96f3f6f51367544145019c Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 20 Jul 2025 10:26:31 -0400 Subject: [PATCH] Improve `abort-current-script` scriptlet Prevent webpages from tampering with `textContent`. Borrow solution from: https://github.com/AdguardTeam/Scriptlets/blob/c2d7378e4de8ed79fcd7cc17c0e883e48dcd2f2a/src/scriptlets/abort-current-inline-script.js#L98-L99 --- src/js/resources/scriptlets.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/js/resources/scriptlets.js b/src/js/resources/scriptlets.js index 071b6052b..74881a230 100755 --- a/src/js/resources/scriptlets.js +++ b/src/js/resources/scriptlets.js @@ -77,8 +77,8 @@ function shouldDebug(details) { /******************************************************************************/ builtinScriptlets.push({ - name: 'abort-current-script-core.fn', - fn: abortCurrentScriptCore, + name: 'abort-current-script.fn', + fn: abortCurrentScriptFn, dependencies: [ 'get-exception-token.fn', 'safe-self.fn', @@ -87,7 +87,7 @@ builtinScriptlets.push({ }); // Issues to mind before changing anything: // https://github.com/uBlockOrigin/uBlock-issues/issues/2154 -function abortCurrentScriptCore( +function abortCurrentScriptFn( target = '', needle = '', context = '' @@ -122,8 +122,9 @@ function abortCurrentScriptCore( const debug = shouldDebug(extraArgs); const exceptionToken = getExceptionTokenFn(); const scriptTexts = new WeakMap(); + const textContentGetter = Object.getOwnPropertyDescriptor(Node.prototype, 'textContent').get; const getScriptText = elem => { - let text = elem.textContent; + let text = textContentGetter.call(elem); if ( text.trim() !== '' ) { return text; } if ( scriptTexts.has(elem) ) { return scriptTexts.get(elem); } const [ , mime, content ] = @@ -596,7 +597,7 @@ builtinScriptlets.push({ ], fn: abortCurrentScript, dependencies: [ - 'abort-current-script-core.fn', + 'abort-current-script.fn', 'run-at-html-element.fn', ], }); @@ -604,7 +605,7 @@ builtinScriptlets.push({ // https://github.com/uBlockOrigin/uBlock-issues/issues/2154 function abortCurrentScript(...args) { runAtHtmlElementFn(( ) => { - abortCurrentScriptCore(...args); + abortCurrentScriptFn(...args); }); }