How does a PreparedStatement avoid or prevent SQL injection?

前端 未结 10 1934
再見小時候
再見小時候 2020-11-22 05:21

I know that PreparedStatements avoid/prevent SQL Injection. How does it do that? Will the final form query that is constructed using PreparedStatements will be a string or o

10条回答
  •  天命终不由人
    2020-11-22 05:42

    As explained in this post, the PreparedStatement alone does not help you if you are still concatenating Strings.

    For instance, one rogue attacker can still do the following:

    • call a sleep function so that all your database connections will be busy, therefore making your application unavailable
    • extracting sensitive data from the DB
    • bypassing the user authentication

    Not only SQL, but even JPQL or HQL can be compromised if you are not using bind parameters.

    Bottom line, you should never use string concatenation when building SQL statements. Use a dedicated API for that purpose:

    • JPA Criteria API
    • jOOQ

提交回复
热议问题