How can I avoid SQL injection attacks?

后端 未结 6 2415
轻奢々
轻奢々 2020-11-27 07:33

Yesterday I was speaking with a developer, and he mentioned something about restricting the insertions on database field, like, strings such as -- (minus minus)

6条回答
  •  庸人自扰
    2020-11-27 07:53

    The proper way to avoid SQL Injection attacks is NOT to simply disallow certain problematic characters, but rather to use parameterized SQL. In short, parameterized SQL prevents the database from executing raw user input as part of the SQL command this prevents user input like "drop table" from being executed. Just escaping characters does not stop all forms of SQL injection attacks and excluding certain words such as "Drop" does not work in all cases; there can be certain fields where "Drop" is a perfectly valid part of the data entry.

    You can find some good articles on the subject of paramaterized SQL here:

    https://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/

    http://www.codeproject.com/KB/database/ParameterizingAdHocSQL.aspx

    Now that you mentioned that you are working with ASP.net I can give you some links that deal specifically with SQL Injection in ASP.

    https://dzone.com/articles/aspnet-preventing-sql-injectio https://www.c-sharpcorner.com/UploadFile/75a48f/how-sql-injection-can-be-possible-in-asp-net-websites/

    Here is a more general article on making your ASP more secure: http://www.codeproject.com/KB/web-security/Securing_ASP_NET_Apps.aspx

    And, of course the MSDN article on SQL injection: http://msdn.microsoft.com/en-us/library/ms998271.aspx

提交回复
热议问题