JPA 中是否可能进行 SQL 注入攻击? [英] Are SQL injection attacks possible in JPA?

查看:82
本文介绍了JPA 中是否可能进行 SQL 注入攻击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Java EE 6 和 JSF-2.0 构建一个 Java Web 应用程序,对所有数据库操作使用持久性 API.

I'm building a Java Web Application using Java EE 6 and JSF-2.0, using the persistence API for all database operations.

后端是 MySQL,但我使用 EJB-QL 中的 EntityManager 函数和命名查询进行所有操作.这种情况下是否有可能进行 SQL 注入攻击?

The back-end is MySQL, but I have used the EntityManager functions and Named Queries in EJB-QL for all operations. Are SQL injection attacks possible in this case?

推荐答案

只有在像这样在 SQL/JPQL 字符串中内联用户控制的变量时才有可能:

It's only possible if you're inlining user-controlled variables in a SQL/JPQL string like so:

String sql = "SELECT u FROM User u WHERE id=" + id;

如果您不这样做并且仅使用参数化/命名查询,那么您就安全了.

If you aren't doing that and are using parameterized/named queries only, then you're safe.

这篇关于JPA 中是否可能进行 SQL 注入攻击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆