chm*_*ike 7 sql security python-2.7
我在Python中有一些代码在sqlite DB中设置char(80)值.
该字符串是通过文本输入字段直接从用户获取的,并使用JSON结构中的POST方法发送回服务器.
在服务器端,我当前将字符串传递给调用SQL UPDATE操作的方法.
它有效,但我知道它根本不安全.
我希望客户端无论如何都是不安全的,因此任何保护都应放在服务器端.我可以做些什么来再次保护UPDATE操作SQL注入?
我正在寻找的是一个"引用"文本以便它不会混淆SQL解析器的函数.我希望这样的功能存在,但找不到它.
编辑: 这是我当前设置char字段名称标签的代码:
def setLabel( self, userId, refId, label ):
self._db.cursor().execute( """
UPDATE items SET label = ? WHERE userId IS ? AND refId IS ?""", ( label, userId, refId) )
self._db.commit()
Run Code Online (Sandbox Code Playgroud)
从文档:
con.execute("insert into person(firstname) values (?)", ("Joe",))
Run Code Online (Sandbox Code Playgroud)
这逃脱了"Joe",所以你想要的是
con.execute("insert into person(firstname) values (?)", (firstname_from_client,))
Run Code Online (Sandbox Code Playgroud)