Skip to content

debug_query and SQL Injection. Why does this not inject? #4225

Answered by weiznich
B4rc1 asked this question in Q&A
Discussion options

You must be logged in to vote

Diesel uses prepared statements for any query. That usually prevents any form of SQL injections as parameters are send separate from the query.

In this psecific case it does not help as you literally pass in a user supplied string as query part via dsl::sql. That function and diesel::sql_query are exceptions in so far that they do not process the strings provided by the user in any way, so if you pass in a string that is constructed via format! your will likely run into SQL injection problems. It does not seem to work for your particular example as you mixed up the quotation marks. SQL uses ' to quote strings and because diesel always will only execute the first query in a particular stat…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@B4rc1
Comment options

@weiznich
Comment options

Answer selected by B4rc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants