I want to dynamically filter a JDBI query.
The a list of parameters is passed from the UI via REST e.g.
http://localhost/things?foo=bar&baz=taz
http://localhost/things?foo=buz
Which is (clumsily) built (Jersey @Context UriInfo::getQueryParameters -> StringBuilder) to something like this:
WHERE foo=bar AND baz=taz
And passed to JDBI which looks like this:
@UseStringTemplate3StatementLocator
public interface ThingDAO {
@SqlQuery("SELECT * FROM things <where>)
List<Thing> findThingsWhere(@Define("where") String where);
}
As far as I understand the current implementation is vulnerable to SQL injection. I can obviously sanitize the column names but not the values. 1
There must be a more elegant and SQL Injection proof way of doing this.
Long
(which shouldn't be able to be used for injection wizardry ;) ) and@BindIn
seems to use PreparedStatements which@Define
(as far as I understood) does not. – Porush