This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for following filter options
- abort-on-property-read - abort-on-property-write - abort-current-inline-script
- Loading branch information
1 parent
b54950c
commit 34c3c7b
Showing
8 changed files
with
367 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}"); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){}}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.