mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
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:
parent
fed7f4a0b8
commit
fef50e59f2
1 changed files with 7 additions and 6 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue