Skip to content

Commit

Permalink
Improve noeval-if scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed May 5, 2024
1 parent a351852 commit 4d8ee35
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2015,12 +2015,19 @@ function noEvalIf(
) {
if ( typeof needle !== 'string' ) { return; }
const safe = safeSelf();
const logPrefix = safe.makeLogPrefix('noeval-if', needle);
const reNeedle = safe.patternToRegex(needle);
window.eval = new Proxy(window.eval, { // jshint ignore: line
apply: function(target, thisArg, args) {
const a = args[0];
if ( reNeedle.test(a.toString()) ) { return; }
return target.apply(thisArg, args);
const a = String(args[0]);
if ( needle !== '' && reNeedle.test(a) ) {
safe.uboLog(logPrefix, 'Prevented:\n', a);
return;
}
if ( needle === '' || safe.logLevel > 1 ) {
safe.uboLog(logPrefix, 'Not prevented:\n', a);
}
return Reflect.apply(target, thisArg, args);
}
});
}
Expand Down

0 comments on commit 4d8ee35

Please sign in to comment.