Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cross Site request Forgery

 
lakshmi gullapudi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
lakshmi gullapudi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic