JPA 中可能存在 SQL 注入攻击吗?

发布于 2024-09-13 17:10:06 字数 157 浏览 3 评论 0原文

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

挽梦忆笙歌 2024-09-20 17:10:06

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

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

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

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.

与他有关 2024-09-20 17:10:06

是的,这是可能的。这取决于您的实施方式。
查看防止 JPA 查询语言中的注入

Yes, it is possible. It depends on the way you implement.
Have a look at Preventing injection in JPA query language.

莫言歌 2024-09-20 17:10:06

如果您的 JPA 提供程序处理所有输入参数来处理注入攻击,那么您应该受到保护。我们在 EclipseLink 中进行精简。

正如前面的发帖人提到的,将您自己的 JPQL 或 SQL(用于本机查询)拼凑在一起可能会让您暴露。

我建议使用带参数的命名查询而不是连接字符串来构建 JPQL/SQL。

道格

If your JPA provider processes all input arguments to handle injection attacks then you should be covered. We do thin in EclipseLink.

As the previous poster mentioned piecing together your own JPQL or SQL (for native queries) could expose you.

I would recommend using named queries with parameters over concatenating strings to build JPQL/SQL.

Doug

吻泪 2024-09-20 17:10:06

如果您从进攻/实用的角度提出问题,如果 JPQL 语句是根据用户输入构建的,请考虑以下用户输入:

blah') AND FUNCTION('user like chr(65)||chr(37) ) 和 42-', 1) > 40 AND ('42'='42

如果受害者使用的是 JPA 实现 >= 2.1,并且后端数据库是 Oracle,类似上面的内容可能会充当布尔 SQL 注入来告诉您数据库是否用户以“A”开头。

In case you're asking from an offensive/practical perspective, if a JPQL statement is constructed from user input, consider the following user input:

blah') AND FUNCTION('user like chr(65)||chr(37) AND 42 - ', 1) > 40 AND ('42'='42

If the victim is using a JPA implementation >= 2.1, and the backend database is Oracle, something like the above may act as a boolean SQL injection to tell you if the database user starts with 'A'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文