1111@before
1212def _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
2423def _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