![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
Simon Brooke wrote: So I'm considering building up a query in a string buffer, with clauses like the following: String author = context.getValueAsString( Book.AUTHORFN ); if ( author != null ) { /* do something to sanitise the input */ query.append( " and author like '%" ).append( author ).append( "%'" ); } query.append(" and author like ?") parameters.add(new MyParameterInfo(MyParameterInfo.TYPE_STRING, "%" + author + "%"); You still have injection issues here, the user can enter % and _ for himself but that only affects the results not the statement itself. |
|
But do all SQL injection attacks depend simply on this trick, or are there other tricks I need to defend against? In the particular instance, the database is Postgres 8, but I'd like to have a general understanding and a general solution. |
#12
| |||
| |||
|
|
Le 06/10/2010 10:50, Lothar Kimmeringer a écrit : Simon Brooke wrote: So I'm considering building up a query in a string buffer, with clauses like the following: String author = context.getValueAsString( Book.AUTHORFN ); if ( author != null ) { /* do something to sanitise the input */ query.append( " and author like '%" ).append( author ).append( "%'" ); } query.append(" and author like ?") parameters.add(new MyParameterInfo(MyParameterInfo.TYPE_STRING, "%" + author + "%"); You still have injection issues here, the user can enter % and _ for himself but that only affects the results not the statement itself. I see another possibility of injection with a string containing "\';INSERT... --" So if you simply replace ' by '' in your example you will have : and author like '%\'';INSERT...--' So the INSERT (or what you want) will be executed |
#13
| |||
| |||
|
|
Le 06/10/2010 10:50, Lothar Kimmeringer a écrit : query.append(" and author like ?") parameters.add(new MyParameterInfo(MyParameterInfo.TYPE_STRING, "%" + author + "%"); You still have injection issues here, the user can enter % and _ for himself but that only affects the results not the statement itself. I see another possibility of injection with a string containing "\';INSERT... --" So if you simply replace ' by '' in your example you will have : and author like '%\'';INSERT...--' So the INSERT (or what you want) will be executed |
#14
| |||
| |||
|
|
No, because the escaping of all relevant characters will take place in (or is at least the responsibility of) the JDBC-driver when setting the parameter using setString(...) |
#15
| |||
| |||
|
|
Yes, I'm OK with that. But you have to check configuration and JDBC used and at least test to ensure that is safe. |
#16
| |||
| |||
|
|
Le 07/10/2010 13:54, Lothar Kimmeringer a écrit : No, because the escaping of all relevant characters will take place in (or is at least the responsibility of) the JDBC-driver when setting the parameter using setString(...) Yes, I'm OK with that. But you have to check configuration and JDBC used and at least test to ensure that is safe. |
#17
| |||
| |||
|
|
Yes, I'm OK with that. But you have to check configuration and JDBC used and at least test to ensure that is safe. It is required functionality for the driver to be JDBC compliant. |
![]() |
| Thread Tools | |
| Display Modes | |
| |