Spring SQL Injection中的@Query注释是否安全?

Usm*_*kil 10 java spring sql-injection spring-annotations

对于Spring,传递给@Query注释的字符串的参数是否被视为纯数据,例如,如果您使用的是PreparedStatement类或任何旨在阻止SQL注入的方法?

final String MY_QUERY = "SELECT * FROM some_table WHERE some_column = ?1";

@Query(value=MY_QUERY, nativeQuery = true)
List<SomeEntity> findResults(String potentiallyMaliciousUserInput);
Run Code Online (Sandbox Code Playgroud)

结论:上面的代码是否容易受到SQL注入的影响?

Ale*_*lex 3

看起来 Spring Data@Query只是 JPA 的包装

请参阅这个答案:Are SQL Injection Attacks possible in JPA?

  • 问题中的例子安全还是不安全? (19认同)