SQL Injection & Optimizations Path
Join the DZone community and get the full member experience.
Join For FreeIt is silly, but I just had a conversation with one of our developers on SQL Injection. In RavenDB we support replicating to a relational database, which obviously require using SQL. We are doing things properly, with parameters and everything.
No chance for SQL Injection from there. Great, and end of a very short blog post if it was everything.
As it turned out, there is a significant performance difference between:
@p1 = 'users/1' @p2 = 'users/2' DELETE FROM Users WHERE Id IN (@p1,@p1)
And:
DELETE FROM Users WHERE Id IN ('users/1', 'users/2')
Enough that we added that as an option. The reason why related to the vagaries of the database query optimizer, and not really relevant.
This is off by default, obviously. And we use parameters by choice & preference. But we still added a minimal “protection” by adding:
sqlValue.Replace("'", "''")
Considering that this isn’t meant for user’s input (it is for document ids), that is something that is annoying.
Any suggestions on how to improve this?
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Send Email Using Spring Boot (SMTP Integration)
-
How To Manage Vulnerabilities in Modern Cloud-Native Applications
-
Using OpenAI Embeddings Search With SingleStoreDB
-
Database Integration Tests With Spring Boot and Testcontainers
Comments