wood burning stoves*
The moose likes JDBC and the fly likes Cross Site request Forgery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Cross Site request Forgery" Watch "Cross Site request Forgery" New topic
Author

Cross Site request Forgery

lakshmi gullapudi
Greenhorn

Joined: Mar 18, 2013
Posts: 16
Found security vulnerability when application is scanned .
While scanning the application, they are passing diff values for TRANS_CD, due to these invalid values , system thorwing exception , how can we restrict this ?

16 Apr 2013 16:58:58,105 [SocketListener0-7] ERROR com.xelus.solos.trans.TransRunner - Object Not In Db Exception
com.xelus.solos.persistent.ObjectNotInDbException: TransactionMap could not be found in the database with key of TRANS_CD = [DISPLAY_1C_SELECTION' OR]
at com.xelus.solos.persistent.TransactionMap.loadByTransCd(Unknown Source)


16 Apr 2013 16:59:09,970 [SocketListener0-7] ERROR com.xelus.solos.trans.TransRunner - Object Not In Db Exception
com.xelus.solos.persistent.ObjectNotInDbException: TransactionMap could not be found in the database with key of TRANS_CD = [DISPLAY_1C_SELECTION' AND 5=5 OR 's'='0]
at com.xelus.solos.persistent.TransactionMap.loadByTransCd(Unknown Source)
at com.xelus.solos.trans.TransRunner.execute(Unknown Source)


Code:

PreparedStatement pstmt = con.prepareStatement(
"SELECT " + Consts.FIELD_TRANS_CD + ", "
+ Consts.FIELD_TRANS_GOTO_CD + ", "
+ Consts.FIELD_TRANS_CLASS_NM + ", "
+ Consts.FIELD_TRANS_METHOD_NM + ", "
+ Consts.FIELD_UPDATE_STAMP + " "
+ "FROM " + Consts.TABLE_TRANS + " "
+ "WHERE " + Consts.FIELD_TRANS_CD + "= ? ");

pstmt.setString(1, transCd);


ResultSet rs = pstmt.executeQuery();

if (rs.next()) {
_isPersistent = true;
_transCd = rs.getString(1);
_transGotoCd = rs.getString(2);
_transClassNm = rs.getString(3);
_transMethodNm = rs.getString(4);
_updateStamp = rs.getString(5);
}
else {
clear();
rs.close();
pstmt.close();
connectionManager.freeConnection(con);

throw new ObjectNotInDbException("TransactionMap",
"TRANS_CD = [" + transCd + "]");
}


Please help me how to resolve this issue.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

That's not cross site request forgery. It looks like they were trying to do SQL Injection. And failed since that code protects against SQL Injection. If you don't want to throw ane xception on error, you can catch the exception. It is a good idea to not be showing the user a stack trace. But it's not cross site request forgery.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
lakshmi gullapudi
Greenhorn

Joined: Mar 18, 2013
Posts: 16
yes, it looks like SQL injection.

In many sites , its mentioned use prepared statements to avoid SQL injections.

in my code we are using prepared statement , but still this vulnerability occuring in scan .

How can i restrict this or how can i prevent this SQL injection?

Please help me.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Actually it is an attempted SQL injection attack. You obviously cannot prevent such attempts, you can only make sure they fail - which they did. "Preventing SQL injection" usually means exactly that - making sure the attacker won't gain unauthorized access using SQL injection. If you weren't using prepared statements (nor had escaped the inputs properly, but it is a lot of unnecessary work), the attacker might perhaps execute some unauthorized statements in the database.

The SQL injection attacks is based on entering invalid inputs to the application. Obviously that causes errors in the application. You can handle these errors one way or another - you might, for example, check that the user input corresponds to an expected format, but sometimes that could be hard. I don't think relying on an exception being thrown is a bad solution, assuming you don't show the exception details to the end user.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

lakshmi gullapudi wrote:in my code we are using prepared statement , but still this vulnerability occuring in scan .

What exactly is it saying about the vulnerability in the scan? Because I think it is wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cross Site request Forgery
 
Similar Threads
org.hibernate.PropertyAccessException: exception setting property value with CGLIB
error on TreeMap
Exception starting filter in Struts2
Data type mismatch in criteria expression while using Datetime column
Problem in generating report from birt