spring-data-rest icon indicating copy to clipboard operation
spring-data-rest copied to clipboard

`filterByJacksonVisibility` breaks filtering on relations

Open aronbeurskens opened this issue 5 months ago • 3 comments

The following commit breaks filtering on relationship. https://github.com/spring-projects/spring-data-rest/commit/3dc76b887be2714d53afbe3024f758ecd50c29ed

I have an entity Dossier with a @ManyToMany on customers:

The DossierRepository extends the QuerydslBinderCustomizer to bind on the customer property.

@RepositoryRestResource(excerptProjection = DossierExcerpt.class)
public interface DossierRepository extends JpaRepository<Dossier, Integer>, QuerydslPredicateExecutor<Dossier>, QuerydslBinderCustomizer<QDossier> {
    @RestResource
    Page<Dossier> findAll(@QuerydslPredicate Predicate predicate, Pageable pageable);

    @Override
    default void customize(QuerydslBindings bindings, QDossier dossier) {
        // Like statements on firstName and lastName
        bindings.bind(dossier.customers.any().firstName).first(StringExpression::containsIgnoreCase);
        bindings.bind(dossier.customers.any().lastName).first(StringExpression::containsIgnoreCase);
    }

Formerly I could use: /api/dossiers?customers.firstName=John However due to the strict checking in filterByJacksonVisibility this bind doesn't work anymore

aronbeurskens avatar Jul 01 '26 12:07 aronbeurskens

Jammer dat ik geen Nederlands versta 🙃.

Thanks @aronbeurskens. The initial description is just about right as it stands. We would rather keep AI generated content out of the ticket, since it tends to add overhead on our side and distracts from the actual problem.

To your initial report: The intent of filterByJacksonVisibility is to avoid exposing any surface that could be used to probe for property names. It is a hardening measure: applications should not be susceptible to someone trying various property names outside the exported model to observe how the application reacts when a model field happens to be hit.

Let us explore how we can pass-thru intended usage of filtered properties when there is Querydsl involved defining bindings. Given we have the registered property path bindings, we should be able to leverage these.

mp911de avatar Jul 01 '26 15:07 mp911de

We also ran into this updating an app to Spring Boot 4.0.7. We'd be interested if there is a way to work around this change, for the time being we're holding back on updating Spring Data in that app.

Banesword avatar Jul 14 '26 21:07 Banesword

I checked PR #2581 and noticed it already addresses this regression with nested-path handling and regression tests. Thanks for working on this! Is there any additional testing or edge case that would be helpful to investigate?

yashdotdev13 avatar Nov 12 '26 09:11 yashdotdev13