Prevent ASP. NET from being attacked by SQL Injection

Source: Internet
Author: User

It is not difficult to prevent ASP. NET from being attacked by SQL injection. you only need to filter all input content before using the content entered in the form to construct an SQL command. You can filter the input content in multiple ways.

First, the following technologies can be used to dynamically construct SQL queries.

Replace the single quotation marks (single quotation marks), that is, change all single quotation marks to two single quotation marks to prevent attackers from modifying the meaning of SQL commands. delete all the hyphens in user input content. For database accounts used to perform queries, restrict its permissions.

Second, use the stored procedure to execute all the queries.

The SQL parameter transmission method prevents attacks by using single quotes and hyphens. In addition, it allows database permissions to be restricted to only allowing specific stored procedures to be executed. All user input must comply with the security context of the called stored procedure, in this way, it is difficult to launch injection attacks again.

Third, restrict the length of form or query string input.

If a user's login name can contain a maximum of 10 characters, do not recognize the 10 or more characters entered in the form. This will greatly increase the number of characters inserted by attackers in SQL commands.
HarmfulCode.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.