-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathnoeval.js
46 lines (42 loc) · 1.09 KB
/
noeval.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* eslint-disable no-eval, no-extra-bind */
import { hit, logMessage } from '../helpers';
/**
* @scriptlet noeval
*
* @description
* Prevents page to use eval.
* Notifies about attempts in the console
*
* Related UBO scriptlet:
* https://github.com/gorhill/uBlock/wiki/Resources-Library#noevaljs-
*
* It also can be used as `$redirect` rules sometimes.
* See [redirect description](../wiki/about-redirects.md#noeval).
*
* ### Syntax
*
* ```adblock
* example.org#%#//scriptlet('noeval')
* ```
*
* @added v1.0.4.
*/
export function noeval(source) {
window.eval = function evalWrapper(s) {
hit(source);
logMessage(source, `AdGuard has prevented eval:\n${s}`, true);
}.bind();
}
export const noevalNames = [
'noeval',
// aliases are needed for matching the related scriptlet converted into our syntax
'noeval.js',
'silent-noeval.js',
'ubo-noeval.js',
'ubo-silent-noeval.js',
'ubo-noeval',
'ubo-silent-noeval',
];
// eslint-disable-next-line prefer-destructuring
noeval.primaryName = noevalNames[0];
noeval.injections = [hit, logMessage];