如何避免在我的ASP.NET应用程序中的SQL注入攻击? [英] How can I avoid SQL injection attacks in my ASP.NET application?

查看:320
本文介绍了如何避免在我的ASP.NET应用程序中的SQL注入攻击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要避免被容易受到SQL注入在我的ASP.NET应用程序。我怎么可能做到这一点?

I need to avoid being vulnerable to SQL injection in my ASP.NET application. How might I accomplish this?

推荐答案

虽然你的问题是非常通用的,一些规则始终适用:

Even though your question is very generic, a few rules always apply:

  • 使用参数化查询(的SqlCommand 的SqlParameter ),把用户的输入参数。
  • 请不要建立SQL字符串了未检查用户输入的。
  • 请不要以为你可以建立一个消毒程序,可以检查用户输入的各种malformedness的。边缘的情况下很容易被遗忘。检查数字输入可能会非常简单,让您在安全方面,但对于字符串输入刚才使用的参数。
  • 检查二级vulnerabilites - 不建立SQL查询字符串了SQL表值,如果这些值由用户输入的
  • 使用存储过程来封装数据库操作。
  • Use parameterized queries (SqlCommand with SqlParameter) and put user input into parameters.
  • Don't build SQL strings out of unchecked user input.
  • Don't assume you can build a sanitizing routine that can check user input for every kind of malformedness. Edge cases are easily forgotten. Checking numeric input may be simple enough to get you on the safe side, but for string input just use parameters.
  • Check for second-level vulnerabilites - don't build SQL query strings out of SQL table values if these values consist of user input.
  • Use stored procedures to encapsulate database operations.

这篇关于如何避免在我的ASP.NET应用程序中的SQL注入攻击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆