-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Malicious SQL injection
PostPosted: Wed Apr 14, 2004 3:47 am 
Beginner
Beginner

Joined: Wed Dec 03, 2003 10:59 am
Posts: 47
Hello,

Is it possible to inject malicious SQL into objects, and have Hibernate execute this when updating/inserting/selecting from DB?

Example:
If I have an object Foo and allow the user to edit Foo properties (think web app with HTML form for editing), could a user set one of the properties to, for example, "DROP TABLE xxx;", and cause Hibernate to execute that and drop table 'xxx'?

This is a trivial example, but please consider all kinds of escape sequences that a smart and evil user could come up with, to let that SQL get to the point where it would get executed.

Does Hibernate do anything to prevent this?
Does it try to analyze the input to make sure it is not SQL?
Does it do something (what?) to make sure that even if SQL is entered and is smartly escaped, it does not get executed?

Thank you.
P.S.
Hibernate 2.1.1 on PostgreSQL, but that is irrelevant for my questions.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 5:13 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Hibernate uses properties as prepared statements parameters and postgresql driver escapes string parameters.
There is no problems if you do not use dynamic queries and string manipulation yourself (It is possible to execute multiple statements separated by semicolon on some postgresql versions).


Top
 Profile  
 
 Post subject: More on what baliukas said,
PostPosted: Wed Apr 14, 2004 8:45 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 9:37 am
Posts: 22
Location: Willow Grove, PA
Use bind variables.

Instead of session.find("from blah where blah.name='" + namevar "');

do something more on the lines of --> session.find("from blah where blah.name=?);
i.e. or
Code:
session.createQuery("from blah where blah.name=?").setParameter(1, namevar)
// or
session.createQuery("from blah where blah.name=:nameHere").setParameter("nameHere,namevar);



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.