Improve abort-current-script scriptlet

Prevent webpages from tampering with `textContent`.

Borrow solution from:
c2d7378e4d/src/scriptlets/abort-current-inline-script.js (L98-L99)
This commit is contained in:
Raymond Hill 2025-07-20 10:26:31 -04:00
parent fed7f4a0b8
commit fef50e59f2
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -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);
});
}