-
Notifications
You must be signed in to change notification settings - Fork 32
/
pandas-eval.yaml
48 lines (44 loc) · 1.65 KB
/
pandas-eval.yaml
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
rules:
- id: pandas-eval
message: >-
Pandas eval() and query() may be dangerous if used to evaluate
dynamic content. If this content can be input from outside the program, this
may be a code injection vulnerability. Ensure evaluated content is not definable
by external sources.
languages: [python]
severity: ERROR
metadata:
category: security
cwe: "CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')"
subcategory:
- audit
confidence: LOW
likelihood: LOW
impact: HIGH
technology: [pandas]
description: "Potential arbitrary code execution from `pandas` functions that evaluate user-provided expressions"
references:
- https://blog.trailofbits.com/2021/03/15/never-a-dill-moment-exploiting-machine-learning-pickle-files/
patterns:
- pattern-inside: |
import pandas
...
- pattern-either:
- patterns:
- pattern: pandas.DataFrame.$FN(...)
- pattern-not: pandas.DataFrame.$FN("...", ...)
- pattern-not: pandas.DataFrame.$FN(f"", ...)
- patterns:
- pattern: pandas.$FN(...)
- pattern-not: pandas.$FN("...", ...)
- pattern-not: pandas.$FN(f"", ...)
- patterns:
- pattern-inside: |
$DF = pandas.DataFrame(...)
...
- pattern: $DF.$FN(...)
- pattern-not: $DF.$FN("...", ...)
- pattern-not: $DF.$FN(f"", ...)
- metavariable-regex:
metavariable: $FN
regex: (eval|query)