Automatic prevention of SQL Injection for Ibatis

Source: Internet
Author: User

Assume that the user executes
 
Select * from product where id = 5
 
This statement. 5 of them are user input.
 
The meaning of SQL injection is that some users do not enter 5,
 
 
 
5; delete from orders
 
 
 
Then the original SQL statement will become,
 
 
Select * from product where id = 5; delete from orders
.
 
After the select statement is executed, all records in the orders table will be deleted. (If he only deleted these records, he could have done more terrible things ).
 
 
 
Fortunately, Ibatis uses the PreparedStatement
S ).
 
The preceding statement will be compiled,
 
 
Select * from product where id =?
 
This effectively prevents SQL injection.
 
 
 
But pay attention to it when you use the $ placeholder.
 
For example, dynamic selection of columns and tables
 
 
SELECT * FROM $ TABLE_NAME $ WHERE $ COLUMN_NAME $ = # value #
 
At this time, you must carefully filter those values to avoid SQL injection. Of course, this situation exists not only in Ibatis.
 
 
 
References:
 
[IBATIS in Action] 3.5.2 SQL injection

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.