Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Added support for following filter options
Browse files Browse the repository at this point in the history
  - abort-on-property-read
  - abort-on-property-write
  - abort-current-inline-script
  • Loading branch information
uBlockAdmin committed Jul 30, 2019
1 parent b54950c commit 34c3c7b
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 57 deletions.
63 changes: 63 additions & 0 deletions assets/scriptlets/abort-current-inline-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
The idea implemented from
https://issues.adblockplus.org/ticket/7141
*/

(function() {
function strToRegex(s) {
if (s.charAt(0) === '/' && s.slice(-1) === '/' && s.length > 2) {
return new RegExp(s.slice(1, -1));
}
let reStr = s.replace(/[.+?${}()|[\]\\]/g, '\\$&');
return new RegExp(reStr);
}

var randomNo = Math.floor(Math.random() * 2116316160 + 60466176).toString(36);

function abortCurrentInlineScript(api, search = null) {
let names = api.split(".");
let base = window;
let property;
let lastproperty = names.pop();
while( (property = names.shift()) !== undefined ) {
base = base[property];
if (!base || !(base instanceof Object)) {
return;
}
}
var descriptor = Object.getOwnPropertyDescriptor(base, lastproperty);
if ( descriptor && descriptor.get !== undefined ) { return; }

let re = search ? strToRegex(search) : null;
let rid = randomNo;
let us = document.currentScript;
var value = base[lastproperty];

function validate() {
let element = document.currentScript;
if (element instanceof HTMLScriptElement && element.src == "" &&
element != us && (!re || re.test(element.textContent)))
{
throw new ReferenceError(rid);
}
}

Object.defineProperty(base, lastproperty, {
get() { validate(); return value; },
set(newValue) {
validate();
value = newValue;
},
configurable: true
});
var onerror = window.onerror;
window.onerror = function(message, source, lineno, colno, error) {
if ( typeof message === 'string' && message.indexOf(randomNo) !== -1 ) {
return true;
}
if (typeof onerror == "function")
return onerror(message, source, lineno, colno, error);
};
}
abortCurrentInlineScript("{{1}}","{{2}}");
})();
52 changes: 52 additions & 0 deletions assets/scriptlets/abort-on-property-read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
The idea implemented from
https://issues.adblockplus.org/ticket/6969
*/

(function() {
let createProxy = function(object, property, descriptor) {
let pos = property.indexOf(".");
if(pos === -1) {
let objDescriptor = Object.getOwnPropertyDescriptor(object, property);
if (objDescriptor && !objDescriptor.configurable)
return;

Object.defineProperty(object, property, Object.assign({}, descriptor, {configurable: true}));
return true;
} else {
let property1 = property.slice(0, pos);
let propertyRemaining = property.slice(pos + 1);
let value = object[property1];
if (value && (value instanceof Object)) {
createProxy(value, propertyRemaining, descriptor);
return;
}

let objDescriptor = Object.getOwnPropertyDescriptor(object, property1);
if (objDescriptor && !objDescriptor.configurable)
return;

Object.defineProperty(object, property1, {
get() { return value; },
set(newValue) { value = newValue; if ( newValue instanceof Object ) {
createProxy(newValue, propertyRemaining, descriptor);
}},
configurable: true
});
}
}

let randomNo = Math.floor(Math.random() * 2116316160 + 60466176).toString(36);
let abort = function() {
throw new ReferenceError(randomNo);
}
var onerror = window.onerror;
window.onerror = function(message, source, lineno, colno, error) {
if( typeof message === 'string' && message.indexOf(randomNo) !== -1 ) {
return true;
}
if(typeof onerror == "function")
return onerror(message, source, lineno, colno, error);
};
createProxy(window, '{{1}}', {get: abort, set: function(){}});
})();
51 changes: 51 additions & 0 deletions assets/scriptlets/abort-on-property-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
The idea implemented from
https://issues.adblockplus.org/ticket/7207
*/

(function() {
var createProxy = function(object, property, descriptor) {
let pos = property.indexOf(".");
if(pos === -1) {
let objDescriptor = Object.getOwnPropertyDescriptor(object, property);
if (objDescriptor && !objDescriptor.configurable)
return;

Object.defineProperty(object, property, Object.assign({}, descriptor, {configurable: true}));
return true;
} else {
let property1 = property.slice(0, pos);
let propertyRemaining = property.slice(pos + 1);
let value = object[property1];
if (value && (value instanceof Object)) {
createProxy(value, propertyRemaining, descriptor);
return;
}
let objDescriptor = Object.getOwnPropertyDescriptor(object, property1);
if (objDescriptor && !objDescriptor.configurable)
return;

Object.defineProperty(object, property1, {
get() { return value; },
set(newValue) { value = newValue; if ( newValue instanceof Object ) {
createProxy(newValue, propertyRemaining, descriptor);
}},
configurable: true
});
}
}

var randomNo = Math.floor(Math.random() * 2116316160 + 60466176).toString(36);
var abort = function() {
throw new ReferenceError(randomNo);
}
var onerror = window.onerror;
window.onerror = function(message, source, lineno, colno, error) {
if ( typeof message === 'string' && message.indexOf(randomNo) !== -1 ) {
return true;
}
if (typeof onerror == "function")
return onerror(message, source, lineno, colno, error);
};
createProxy(window, '{{1}}', {set: abort});
})();
2 changes: 1 addition & 1 deletion platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,

"name": "uBlock",
"version": "0.9.5.18",
"version": "0.9.5.19",

"default_locale": "en",
"description": "__MSG_extShortDesc__",
Expand Down
4 changes: 2 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ return {

// read-only
systemSettings: {
compiledMagic: 'wertpszukpsddd',
selfieMagic: 'werthiasrsddd'
compiledMagic: 'wertpszukpseee',
selfieMagic: 'werthiasrseee'
},
restoreBackupSettings: {
lastRestoreFile: '',
Expand Down
Loading

0 comments on commit 34c3c7b

Please sign in to comment.