SQL injection attack on web front-end security

Source: Internet
Author: User
Tags sql injection sql injection attack

First, the principle of SQL injection attack
The attacker injects malicious SQL code into the HTTP request and executes it on the server.
For example, user login, enter the user name Camille, password ' or ' 1 ' = ' 1, if you use the method of parameter construction, it will appear

Select *  from User where = ' Camille '  and = "' or ' 1 ' = ' 1 '

Regardless of the user name and password, the list of users queried is not empty, so you can look at the information of other users.


Second, the defense of SQL injection attack
1, the Client

    • Limit the length of string input;
    • Validity test.
// filter URLs for illegal SQL characters, or filter text boxes for illegal characters.  var surl = location.search.toLowerCase (); var squery = surl.substring (surl.indexof ("=") +1); Reg=/select|update|delete|truncate|join|union| Exec|insert|drop|count| ' | ' |;| >|<|%/ i; if (Reg.test (squery)) {    alert ("Do not enter illegal characters")    ; = Surl.replace (Squery, "");}

2. Service side

    • Use Precompiled Preparestatement (Java);
    • Validation to prevent attackers from bypassing client requests;
    • Never use dynamically assembled SQL, you can use parameterized SQL or directly use stored procedures for data query access;
    • Filter the special characters in the parameters that SQL requires, such as single quotes, double quotes.

Web front-end security for SQL injection attacks

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.