【问题标题】:How to stop SQL Injection in Google Cloud SQL?如何停止 Google Cloud SQL 中的 SQL 注入?
【发布时间】:2013-01-10 04:31:36
【问题描述】:

我正在使用 Python 与 Google 的新 Cloud SQL (mySQL) 数据库通信。我有一个工作示例,但我想知道示例代码是否可以阻止 SQL 注入攻击?

mdata = self.request.get('mdata')
conn = rdbms.connect(instance=_INSTANCE_NAME, database='metarsql')
cursor = conn.cursor()
# Note that the only format string supported is %s
cursor.execute('INSERT INTO metar (metar_data) VALUES (%s)', (MySQLdb.escape_string(mdata)))
conn.commit()
conn.close()

是否有要添加的函数或命令来停止 SQL 注入?也许是一个停止多个 SQL 命令的函数?

Google 搜索中没有太多关于 Cloud SQL 和注入的内容。

最好的问候

安德烈·F·布鲁顿

【问题讨论】:

    标签: python mysql google-cloud-sql


    【解决方案1】:

    一个很好的指南:Prevent sql injection in python using cursor.execute correctly

    不管是 Google 的服务器还是其他任何人。

    【讨论】:

    • 如何从上面的示例中添加超过 1 %s 的变量?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 2015-08-12
    • 2015-09-07
    • 1970-01-01
    • 2018-11-21
    • 2011-09-10
    相关资源
    最近更新 更多