sqlite - SQLite - if I block " from strings, can I be SQL injected?
问题描述
I'm using this code (python using sqlite3) to add data to the table:
''' INSERT INTO TABLE (USERNAME) VALUES ("''' + data + '''")'''
If I block ", then (to the best of my knowledge) it should be impossible to exit the string, subsequently making it impossible to SQL inject.
My questions are these: Does this stop users from being able to inject SQL? If no, should I add more to the blacklist or create a whitelist?
All help is greatly appreciated.
解决方案
如果您data
在让它命中插入语句之前进行消毒,确保单引号不会出现在任何地方,那么理论上 SQL 注入是不可能的。无论data
注入什么都应该被视为字符串文字,从而使任何注入的 SQL 命令无效。但是,攻击者可能仍有办法解决此问题。
你最好的办法就是仅仅依靠使用准备好的语句来避免 SQL 注入。攻击者变得越来越聪明,并且可能仍然有一种方法可以通过其他方式注入您当前的插入语句。
推荐阅读
- vue.js - 使用 vuejs 从模型中绑定超链接路径的正确方法是什么
- react-native - 如何在 react native expo 应用程序中禁用 firebase reCAPTCHA?
- discord.js - 嵌入的角色声明消息
- css - 这是什么境界?
- python - 我们可以在 h2o automl 中设置窗口大小来预测时间序列数据集吗?
- ios - 如果弱自我在 RxDataSource 函数中为零,如何正确返回带有重用标识符的 CollectionViewCell?
- snowflake-cloud-data-platform - 在雪花约束中使用强制
- android - “指定的孩子已经有一个父母。您必须首先在孩子的父母上调用 removeView()”我第二次创建 AlertDialog
- jenkins - 在 bitbucket 和 jenkins 中创建和配置 Webhook
- php - PHP 7.4。包含同名方法的类的实例化调用该方法