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

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

问题描述

我需要避免在我的 ASP.NET 应用程序中受到 SQL 注入的影响.我如何才能做到这一点?

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:

  • 使用参数化查询(SqlCommandSqlParameter)并将用户输入放入参数中.
  • 不要根据未经检查的用户输入构建 SQL 字符串.
  • 不要假设您可以构建一个可以检查用户输入的各种格式错误的清理例程.边缘情况很容易被遗忘.检查数字输入可能很简单,可以让您安全起见,但对于字符串输入,只需使用参数即可.
  • 检查二级漏洞 - 如果这些值包含用户输入,则不要从 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天全站免登陆