-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval_test.ts
50 lines (40 loc) · 1.13 KB
/
eval_test.ts
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
47
48
49
50
// Let's say there's a custom, dangerous function
// we want to flag or ban. Because it's unique to *our*
// repo, it's not going to be covered by any tool
// out of the box. But no problem, this is easy with Semgrep!
function my_eval(str) {
eval(str);
}
// Match a variable as an argument
// ruleid:juice-shop-eval
my_eval(some_var);
// Match a hard-coded string
// ruleid:juice-shop-eval
my_eval("ls");
// Can be part of a conditional statement
// ruleid:juice-shop-eval
if (my_eval() && true) {
// Called inside a conditional or function call
// ruleid:juice-shop-eval
my_eval(a, b, c, d);
}
// Whitespace doesn't trip up Semgrep
// ruleid:juice-shop-eval
my_eval (foo);
// Or new lines
// ruleid:juice-shop-eval
my_eval (
bar
);
// grep would flag this, but it's not an issue, it's in a comment
// my_eval(foo)
// grep would also flag this, but it's a string, not a function call
console.log("my_eval(bar)")
// In some cases, Semgrep can even reason about when a variable
// is definitely a hard-coded string
const x = "semgrep";
// ruleid:juice-shop-eval
my_eval(x);
var y = "r2c";
// ruleid:juice-shop-eval
my_eval(y);