-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsql_injection.ron
More file actions
64 lines (63 loc) · 2.54 KB
/
Copy pathsql_injection.ron
File metadata and controls
64 lines (63 loc) · 2.54 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(
rules: [
// Raw-SQL execution helpers and inline string-built queries.
// The "%"/"+"/"=" bearing patterns force full-call-text matching, so the
// whole list is evaluated against the call text (not just the function name).
(
id: Some("python-sql-raw-001"),
name: Some("Raw SQL Execution"),
category: Some("database"),
mode: "search",
patterns: Some([
"execute_raw_query(",
// Match the % operator after a complete query expression, not DB-API placeholders.
"regex:(?s)cursor\\.execute\\(\\s*\\(*\\s*(?:(?:[rRuUbBfF]{0,2})?(?:\"\"\".*?\"\"\"|'''.*?'''|\"(?:\\\\.|[^\"\\\\])*\"|'(?:\\\\.|[^'\\\\])*')|[A-Za-z_][A-Za-z0-9_.]*)\\s*\\)*\\s*%\\s*[^\\s,)]",
"*cursor.execute(*.format(*",
"*cursor.execute(f\"*",
"*cursor.execute(f'*",
"*cursor.execute(*+*",
"*.executescript(*",
]),
finding_type: Some("SQL Injection"),
severity: Some("Critical"),
confidence: Some("Medium"),
cwe_id: Some("cwe-89"),
description: Some("Raw SQL query executed from a dynamically-built string (string formatting/concatenation)"),
file_types: Some((
extensions: Some([".py"])
)),
tags: Some(["sql", "injection", "database"])
),
// Taint: user input flowing into a SQL execute sink (catches variable-built
// queries that aren't visible as a literal at the call site).
(
id: Some("python-sql-taint-001"),
name: Some("SQL Injection Taint Flow"),
category: Some("database"),
mode: "taint",
sources: Some([
"request.",
"input(",
"raw_input(",
"flask.request",
]),
sinks: Some([
"execute(",
"executemany(",
"executescript(",
]),
sanitizers: Some([
"parameterized",
]),
finding_type: Some("SQL Injection"),
severity: Some("Critical"),
confidence: Some("High"),
cwe_id: Some("cwe-89"),
description: Some("User input flows to SQL execution without parameterization"),
file_types: Some((
extensions: Some([".py"])
)),
tags: Some(["sql", "injection", "taint", "database"])
),
]
)