Resolving SQL Injection Vulnerability methods

Source: Internet
Author: User

This article only pointer coding layer of SQL Injection Vulnerability resolution method, the example code is Java-based.

1, Parameterized precompiled query statements

Unsafe examples

String query = "Select Account_balance from user_data WHERE user_name ="   + request.getparameter ("CustomerName");   Try {     = connection.createstatement (...);      = statement.executequery (query);}

To prevent unsafe values from being passed through parameters, you must use parameterized precompiled query statements

// perform input validation to detect attacks String query = "Select Account_balance FRO   M user_data WHERE user_name =? ";   =1, custname);   = Pstmt.executequery ();
2. White list of input parameters

It is not recommended to pass key portions of SQL statements as parameters, such as table names, field names, or sort characters (ASC, DESC), and so on. The proposed design is judged by the logo, as in the following example

  String tableName;  switch   (PARAM):  case                   "Value1": TableName = "footable" ;    break  ;                   case  "Value2": TableName = "bartable" ;      break  ; ...    default : throw  new  inputvalidationexception (" Unexpected value provided for table name "); 
 Public String SomeMethod (boolean  sortOrder) {  = "Some SQL ... order by Salary" + (SortOrder? ") ASC ":" DESC "); ...

Resolving SQL Injection Vulnerability methods

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.