mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-04 01:59:38 +02:00
Add ability to match against script content of data: URI
Related commit:
- ebc42ae21e
This commit is contained in:
parent
9c8691709d
commit
4fe8126c66
@ -77,16 +77,35 @@
|
|||||||
}
|
}
|
||||||
const magic = String.fromCharCode(Date.now() % 26 + 97) +
|
const magic = String.fromCharCode(Date.now() % 26 + 97) +
|
||||||
Math.floor(Math.random() * 982451653 + 982451653).toString(36);
|
Math.floor(Math.random() * 982451653 + 982451653).toString(36);
|
||||||
const validate = function() {
|
const scriptTexts = new WeakMap();
|
||||||
const e = document.currentScript;
|
const getScriptText = elem => {
|
||||||
if (
|
let text = elem.textContent;
|
||||||
e instanceof HTMLScriptElement &&
|
if ( text.trim() !== '' ) { return text; }
|
||||||
reContext.test(e.src) &&
|
if ( scriptTexts.has(elem) ) { return scriptTexts.get(elem); }
|
||||||
e !== thisScript &&
|
const [ , mime, content ] =
|
||||||
reNeedle.test(e.textContent)
|
/^data:([^,]*),(.+)$/.exec(elem.src.trim()) ||
|
||||||
) {
|
[ '', '', '' ];
|
||||||
throw new ReferenceError(magic);
|
try {
|
||||||
|
switch ( true ) {
|
||||||
|
case mime.endsWith(';base64'):
|
||||||
|
text = self.atob(content);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
text = self.decodeURIComponent(content);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
} catch(ex) {
|
||||||
|
}
|
||||||
|
scriptTexts.set(elem, text);
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
const validate = ( ) => {
|
||||||
|
const e = document.currentScript;
|
||||||
|
if ( e instanceof HTMLScriptElement === false ) { return; }
|
||||||
|
if ( reContext.test(e.src) === false ) { return; }
|
||||||
|
if ( e === thisScript ) { return; }
|
||||||
|
if ( reNeedle.test(getScriptText(e)) === false ) { return; }
|
||||||
|
throw new ReferenceError(magic);
|
||||||
};
|
};
|
||||||
Object.defineProperty(owner, prop, {
|
Object.defineProperty(owner, prop, {
|
||||||
get: function() {
|
get: function() {
|
||||||
@ -106,7 +125,7 @@
|
|||||||
});
|
});
|
||||||
const oe = window.onerror;
|
const oe = window.onerror;
|
||||||
window.onerror = function(msg) {
|
window.onerror = function(msg) {
|
||||||
if ( typeof msg === 'string' && msg.indexOf(magic) !== -1 ) {
|
if ( typeof msg === 'string' && msg.includes(magic) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ( oe instanceof Function ) {
|
if ( oe instanceof Function ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user