【问题标题】:SQL injection prevent with python [duplicate]用python防止SQL注入[重复]
【发布时间】:2022-01-18 01:38:20
【问题描述】:

嘿,我阅读了所有关于 python 的指南,但我找不到下一个查询的解决方案:

select * from known_table_name where id in (list)

list 是一个持有 = "1,2,3,56,7,8" 的变量

有人知道如何保护它吗?

【问题讨论】:

标签: python mysql sql-injection


【解决方案1】:

有多种方式,包括:

# SAFE EXAMPLES. DO THIS!
cursor.execute("SELECT admin FROM users WHERE username = %s'", (username, ));
cursor.execute("SELECT admin FROM users WHERE username = %(username)s", {'username': username});

来源:https://realpython.com/prevent-python-sql-injection/#exploiting-query-parameters-with-python-sql-injection

【讨论】:

  • 我不认为这是在回答用户的问题,具体是如何在查询中安全地使用列表作为变量。
猜你喜欢
  • 2012-08-04
  • 2016-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-12
  • 1970-01-01
相关资源
最近更新 更多