Aller au contenu

SQL injection (ARCH2100)

Ce contenu n’est pas encore disponible dans votre langue.

Key python.security.sql-injection · Severity error · Category security · CWE CWE-89

Embedding user input into a SQL query via concatenation or formatting lets an attacker alter the query structure and exfiltrate data. Use parameterized queries.

def get_user(cur, username):
cur.execute("SELECT * FROM users WHERE name = '%s'" % username)
return cur.fetchone()
def get_user(cur, username):
cur.execute("SELECT * FROM users WHERE name = %s", (username,))
return cur.fetchone()

Use parameterized queries (placeholders) or your ORM’s safe query API instead of interpolating input into the SQL string.