清理 psycopg2 的 SQL fstring 查询
我迭代地构建了我的SQL查询以这样执行:
sql = "SELECT * FROM txs "
param_values = []
if params:
sql += f"WHERE name=%s"
param_values.append(params.name)
...
with _psql_connection() as c:
c.execute(sql, (*param_values)
return c.fetchall()
似乎我使用FString附加名称是可注射的,我不确定这里的解决方案是什么。 c.execute不应该(sql,(*param_values)
已经对输入进行了消毒?
I'm iteratively building up my SQL query to execute as such:
sql = "SELECT * FROM txs "
param_values = []
if params:
sql += f"WHERE name=%s"
param_values.append(params.name)
...
with _psql_connection() as c:
c.execute(sql, (*param_values)
return c.fetchall()
It seems as though me using the fstring to append the name is injectable, and I'm not sure what the right solution here is. Shouldn't c.execute(sql, (*param_values)
sanitize the input already ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)