I was reading this SO question: psycopg2: insert multiple rows with one query and I found there was an excellent answer included that used cursor.mogrify
to speed up a series of sql insertions. It got me wondering, does cursor.mogrify
successfully escape all sql injection vulnerabilities?
The code for the answer posted by Alex Riley was as follows:
args_str = ','.join(cur.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in tup)
cur.execute("INSERT INTO table VALUES " + args_str)
Does anyone know of any vulnerabilities to this method of using psychopg2's cursor.mogrify
method and then following it up with a string interpolation in the cursor.execute
function like this?