JAVA-007 / Intermediate
Unvalidated Spring Data Sort input (JPA sorting injection)
Why is this a problem?
Arbitrary properties or expressions in Sort.by(userParam) may expose errors and enable sorting-based SQL manipulation.
How to fix it
java
Set<String> ALLOW = Set.of("createdAt", "title");
String sort = ALLOW.contains(p) ? p : "createdAt";
repo.findAll(PageRequest.of(0, 20, Sort.by(sort)));