Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are SQL injection attacks possible in JPA?

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?

like image 749
Akshay Avatar asked Aug 09 '10 14:08

Akshay


People also ask

Is SQL injection possible in hibernate?

Hibernate does not grant immunity to SQL Injection, one can misuse the api as they please. There is nothing special about HQL (Hibernates subset of SQL) that makes it any more or less susceptible.

Does Spring data JPA prevent SQL injection?

Note that using JPA or other ORMs without prepared statements with bound parameters won't protect you from an SQL injection.

Do SQL injection attacks still work?

Even though this vulnerability is known for over 20 years, injections still rank number 3 in the OWASP's Top 10 for web vulnerabilities. In 2021, 718 vulnerabilities with the type “SQL injections” have been accepted as a CVE. So the answer is: Yes, SQL injections are still a thing.

What is SQL injection attack in Java?

SQL Injection is one of the top 10 web application vulnerabilities. In simple words, SQL Injection means injecting/inserting SQL code in a query via user-inputted data. It can occur in any applications using relational databases like Oracle, MySQL, PostgreSQL and SQL Server.


1 Answers

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.

like image 67
BalusC Avatar answered Sep 30 '22 08:09

BalusC