Skip to content

Commit 57eed8f

Browse files
committed
psycopg: add async support
1 parent 4836a3c commit 57eed8f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

aikido_zen/sinks/psycopg.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
@before
1212
def _copy(func, instance, args, kwargs):
1313
statement = get_argument(args, kwargs, 0, "statement")
14-
15-
op = "psycopg.Cursor.copy"
14+
op = f"psycopg.{instance.__class__.__name__}.copy"
1615
register_call(op, "sql_op")
1716

1817
vulns.run_vulnerability_scan(
@@ -23,7 +22,7 @@ def _copy(func, instance, args, kwargs):
2322
@before
2423
def _execute(func, instance, args, kwargs):
2524
query = get_argument(args, kwargs, 0, "query")
26-
op = f"psycopg.Cursor.{func.__name__}"
25+
op = f"psycopg.{instance.__class__.__name__}.{func.__name__}"
2726
vulns.run_vulnerability_scan(kind="sql_injection", op=op, args=(query, "postgres"))
2827

2928

@@ -38,3 +37,12 @@ def patch(m):
3837
patch_function(m, "Cursor.copy", _copy)
3938
patch_function(m, "Cursor.execute", _execute)
4039
patch_function(m, "Cursor.executemany", _execute)
40+
41+
@on_import("psycopg.cursor_async", "psycopg", version_requirement="3.1.0")
42+
def patch_async(m):
43+
"""
44+
patching module psycopg.cursor_async (similar to normal patch)
45+
"""
46+
patch_function(m, "AsyncCursor.copy", _copy)
47+
patch_function(m, "AsyncCursor.execute", _execute)
48+
patch_function(m, "AsyncCursor.executemany", _execute)

0 commit comments

Comments
 (0)