Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

JDBI How can I dynamically create a WHERE clause while preventing SQL Injection?

$
0
0

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=tazhttp://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:

@UseStringTemplate3StatementLocatorpublic 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.


Viewing all articles
Browse latest Browse all 3630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>