Dynamic SQL statements are generated without the required data validation and without using parameterized statements or stored procedures. When using LIKE-conditions with values that are coming from a not secure source in the Java Persistence API, the values should be sanitized so they can't contain any wildcards and thereby allow attackers to select more data than they should be able to. For this purpose the escape(String) method is available.
Extract sensitive information from the Database.
Perform queries to the database through sentences or parameterized procedures. Alternatively use escape(String) built-in function.
Authenticated attacker from the Internet.
⌚ 10 minutes.
Default score using CVSS 3.1. It may change depending on the context of the src.
Default score using CVSS 4.0. It may change depending on the context of the src.
The query statements are performed in a parameterized way, validating input data with at least a escape() call
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ParametersJpaRepository extends JpaRepository {
/* Secure */
@Query("select u from User u where u.firstname like %?#{escape([0])}% escape ?#{escapeCharacter()}")
List findContainingEscaped(String namePart);
}
The application performs a query statement without validating input data
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ParametersJpaRepository extends JpaRepository {
// Unsafe LIKE statement injection
@SqlQuery("select u from User u where u.lastname like %:#{[0]}%")
List findByLastnameWithSpelExpression(@Param("lastname") String lastname);
}