/
psycopg-sqli.yaml
51 lines (51 loc) · 1.48 KB
/
psycopg-sqli.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
49
50
51
rules:
- id: psycopg-sqli
languages:
- python
message: >-
Detected SQL statement that is tainted by `event` object. This could lead to SQL injection if the
variable is user-controlled
and not properly sanitized. In order to prevent SQL injection,
use parameterized queries or prepared statements instead.
You can use parameterized statements like so:
`cursor.execute('SELECT * FROM projects WHERE status = %s', 'active')`
mode: taint
metadata:
references:
- https://www.psycopg.org/docs/cursor.html#cursor.execute
- https://www.psycopg.org/docs/cursor.html#cursor.executemany
- https://www.psycopg.org/docs/cursor.html#cursor.mogrify
category: security
owasp:
- A01:2017 - Injection
- A03:2021 - Injection
cwe:
- "CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')"
technology:
- aws-lambda
- psycopg
- psycopg2
cwe2022-top25: true
cwe2021-top25: true
subcategory:
- vuln
likelihood: HIGH
impact: MEDIUM
confidence: MEDIUM
pattern-sinks:
- patterns:
- focus-metavariable: $QUERY
- pattern-either:
- pattern: $CURSOR.execute($QUERY,...)
- pattern: $CURSOR.executemany($QUERY,...)
- pattern: $CURSOR.mogrify($QUERY,...)
- pattern-inside: |
import psycopg2
...
pattern-sources:
- patterns:
- pattern: event
- pattern-inside: |
def $HANDLER(event, context):
...
severity: WARNING