Skip to content
Snippets Groups Projects
Commit 9e995a13 authored by brinn's avatar brinn
Browse files

Improve protection against SQL injection for custom queries.

SVN: 27600
parent f8029d14
No related branches found
No related tags found
No related merge requests found
...@@ -197,8 +197,10 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO ...@@ -197,8 +197,10 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
return (TableModel) template.execute(resolvedQuery, callback); return (TableModel) template.execute(resolvedQuery, callback);
} }
// WORKAROUND this solution is not safe // FIXME this solution is not safe.
// prepared statement parameters would be better but then we need to know the type of parameters // We should use a prepared statement and set the parameters according to the information
// that PreparedStatement.getParameterMetaData() provides or check whether setObject() does the
// trick for us here.
private static String createSQLQueryWithBindingsResolved(String sqlQuery, private static String createSQLQueryWithBindingsResolved(String sqlQuery,
QueryParameterBindings bindingsOrNull) QueryParameterBindings bindingsOrNull)
{ {
...@@ -207,10 +209,19 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO ...@@ -207,10 +209,19 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
{ {
for (Entry<String, String> entry : bindingsOrNull.getBindings().entrySet()) for (Entry<String, String> entry : bindingsOrNull.getBindings().entrySet())
{ {
validateParameterValue(entry.getValue());
template.bind(entry.getKey(), entry.getValue()); template.bind(entry.getKey(), entry.getValue());
} }
} }
return template.createText(); return template.createText();
} }
private static void validateParameterValue(String value) throws UserFailureException
{
if (value.contains("'"))
{
throw new UserFailureException("Parameter value \"" + value
+ "\" contains invalid character.");
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment