Fork me on GitHub
#sql
<
2019-01-18
>
noisesmith19:01:06

I had a question from the security team at work - does clojure.java.jdbc create / use parameterized queries?

seancorfield20:01:55

@noisesmith If you use ? in query strings, yes.

seancorfield20:01:23

(and if you use HoneySQL, it lifts values out of the DSL into query parameters too)

seancorfield20:01:21

(jdbc/query db-spec ["select * from foobar where v > ? and q = ?" v q]) is a parameterized query.

noisesmith20:01:54

cool - I suspected that but didn't know enough jdbc / sql to verify - the security person was suspicious that it was just string concatenation

seancorfield20:01:04

Behind the scenes, clojure.java.jdbc creates a PreparedStatement and sets the supplied values as parameter values on it.

seancorfield20:01:04

Well, if you do (jdbc/query db-spec [(str "select * from foobar where v > " v " and q = " q)]) then, yeah, that is just string concatenation -- and the values are embedded in the SQL and not parameters.

seancorfield20:01:37

But that also won't work in the general case anyway (since str of anything but numbers isn't a valid piece of SQL).

noisesmith20:01:41

yeah, doing string ops inside a query should be a red flag for sure

mattly21:01:55

security people are always suspicious it's just string concatenation tho

noisesmith21:01:36

I guess I could make a small proof of concept that would work with string concat and breaks with jdbc/query and positional args

noisesmith21:01:52

(if argument from authority isn't sufficient)