Checkmark scanned our codes and showed these code have risks for second order injection the code like this
@SuppressWarnings("unchecked")
public List<Map<String, Object>> findBySQL(String sql, List<ScalarType> types, List<Object> values, Info info) throws ApplicationException {
try {
SQLQuery query = currentSession().createSQLQuery(sql);
if (types != null) {
for (ScalarType scalar : types) {
query.addScalar(scalar.getColumn(), scalar.getType());
}
}
if (values != null) {
for (int i = 0; i < values.size(); i++) {
query.setParameter(i, values.get(i));
}
}
query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
return query.list();
} catch (Exception e) {
throw new ApplicationException(e, info);
}
}
Our code use the preparedStatement to execute sql. But why these code still have the risks, and how can I fix it?