参数化查询的基础知识
- 我已经多次使用参数化查询,我知道它有助于防止 SQL 注入。
但是,我想知道我是否可以知道参数化查询中的基本逻辑是什么
防止SQL注入可能很简单,但我不知道。我尝试在 google 上搜索它的基本内容,但每次我都找到一个如何在 Asp.net 中使用参数化查询的示例。 - 我知道要创建一个特殊的类来停止 SQL 注入中使用的那些特殊字符,例如 (',-- 等),但是仅停止特殊字符是否可以完全防止 SQL 注入?
- 最后一件事是.net参数化查询可以完全阻止SQL注入吗?
- I have used parameterized query number of times I know it helps in preventing SQL injection.
But, I was wondering if I can know what is basic logic working inside a parameterized query
to prevent SQL injection may be it is very simple but I don't know about it. I tried to search google what are the basic of it but every time I found an example that how to use parameterized query in Asp.net. - I know about making a special class which stops those special characters like (',-- etc) which are used in SQL injection, but does stopping only special characters totally prevent SQL injection?
- And one last thing does .net parameterized query can fully stop SQL injection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为参数化查询不依赖于准备好的查询数据库支持。数据库驱动程序本身以安全的方式传递值,并且如何完成取决于驱动程序本身。
PostgreSQL 手册解释了数据库级别参数化查询的基础知识。
另一方面,参数化查询简化了区域设置敏感数据的传递。
例如,用户输入小数 100,00,但您的服务器需要 100.00 值。
I think parametrized queries are not dependent on prepared queries database support. Database driver itself passing values the safe way, and how is it done depends on driver itself.
The PostgreSQL manual explains basics about parametrized queries on database level.
On the other hand, parametrized queries simplifies you passing locale sensitive data.
For example, user enters 100,00 decimal, but your server expects 100.00 value.
在我知道的每个数据库引擎中,使用“准备好的”(又名“参数化”或“静态”)查询可以防止 SQL 注入。如果将任何字符传递给参数,则无需过滤它们。如果您编写的 SQL 是在代码中连接在一起而不是使用参数准备的,那么您可能面临 SQL 注入的风险。您应该阅读您正在使用的数据库的安全手册,它很可能有关于 SQL 注入的部分,但只需阅读全部内容即可。我打赌这将花费不到一个小时的时间,并且会给您坚实的指导和信心,让您相信您正在遵循适用于您的数据库的最佳实践。
In every database engine I know, using "prepared" (aka "parametrized", or "static") queries prevents SQL injection. You don't need to filter any characters if they're being passed to parameters. If you ever write SQL that is concatenated together in code rather than prepared with parameters, you are probably at risk for SQL injection. You should the security manual for the database you're using, it will very likely have a section on SQL injection, but just read all of it. I bet it will take under an hour and will give you solid instruction and confidence that you're following best the practices that apply to your database.