diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index 5a512f288..f584794da 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -138,6 +138,11 @@ const immutableResources = new Map([ alias: 'nano-stb.js', redirect: false } ], + [ 'noeval.js', { + } ], + [ 'noeval-if.js', { + redirect: false + } ], [ 'noeval-silent.js', { alias: 'silent-noeval.js', } ], diff --git a/src/web_accessible_resources/noeval-if.js b/src/web_accessible_resources/noeval-if.js new file mode 100644 index 000000000..994772f4a --- /dev/null +++ b/src/web_accessible_resources/noeval-if.js @@ -0,0 +1,41 @@ +/******************************************************************************* + + uBlock Origin - a browser extension to block requests. + Copyright (C) 2019-present Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +(function() { + 'use strict'; + let needle = '{{1}}'; + if ( needle === '' || needle === '{{1}}' ) { + needle = '.?'; + } else if ( needle.slice(0,1) === '/' && needle.slice(-1) === '/' ) { + needle = needle.slice(1,-1); + } else { + needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + } + needle = new RegExp(needle); + window.eval = new Proxy(window.eval, { // jshint ignore: line + apply: function(target, thisArg, args) { + const a = args[0]; + if ( needle.test(a.toString()) === false ) { + return target.apply(thisArg, args); + } + } + }); +})(); diff --git a/src/web_accessible_resources/noeval-silent.js b/src/web_accessible_resources/noeval-silent.js index 1aa08cd3a..cfe6e3b03 100644 --- a/src/web_accessible_resources/noeval-silent.js +++ b/src/web_accessible_resources/noeval-silent.js @@ -21,6 +21,8 @@ (function() { 'use strict'; - window.eval = function() { - }.bind(window); + window.eval = new Proxy(window.eval, { // jshint ignore: line + apply: function() { + } + }); })(); diff --git a/src/web_accessible_resources/noeval.js b/src/web_accessible_resources/noeval.js new file mode 100644 index 000000000..e1f2a7486 --- /dev/null +++ b/src/web_accessible_resources/noeval.js @@ -0,0 +1,30 @@ +/******************************************************************************* + + uBlock Origin - a browser extension to block requests. + Copyright (C) 2019-present Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +(function() { + 'use strict'; + const log = console.log.bind(console); + window.eval = new Proxy(window.eval, { // jshint ignore: line + apply: function(target, thisArg, args) { + log(`Document tried to eval... ${args[0]}\n`); + } + }); +})(); diff --git a/src/web_accessible_resources/set-constant.js b/src/web_accessible_resources/set-constant.js index f7d4114fa..1c3ec876e 100644 --- a/src/web_accessible_resources/set-constant.js +++ b/src/web_accessible_resources/set-constant.js @@ -76,7 +76,7 @@ } const prop = chain.slice(0, pos); let v = owner[prop]; - chain = chain.slice(pos + 1); + chain = chain.slice(pos + 1); if ( v !== undefined ) { makeProxy(v, chain); return;