spring-projects / spring-projects/spring-data-commons

More strict parsing of pageable parameters [DATACMNS-1696]

Open
#2,121 3 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

type: enhancement
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

Paul Vorbach opened DATACMNS-1696 and commented

During a penetration test, we found that you can enter pretty much anything to the query parameters of endpoints that take an argument of type Pageable and the value will get accepted.

For instance, if you have a @RestController listening on /myPageableResource, you can perform requests to /myPageableResource?page=0%20AND%201%3D1%20-- (for readability the URL-decoded value of the page parameter is "0 AND 1=1 --"), the request will be accepted and the default value of 0 for page will be used. The same holds true at least for the ignoreCase parameter of the sort parameters.

I'd argue that it would be better to return a 400 Bad Request instead in this case, where the value for page is obviously invalid. If users happen to enter a bad value by accident, they might not realize why they always get the first page as a result.

 Suggestions for the implementation:

The pageable parameters get parsed by the PageableHandlerMethodArgumentResolver. There also is a PageableHandlerMethodArgumentResolverCustomizer, which can be used to e.g. change parameter names or the maximum page size. Since changing the parsing behavior would be breaking, I'd suggest to allow for customization via the PageableHandlerMethodArgumentResolverCustomizer instead, but a breaking change could probably also be acceptable here.

Do you think this is a valid request? Are there other ways to customize the current behaviour that I have missed (other than re-implementing the HandlerMethodArgumentResolver and changing its behavior)?


Affects: 2.1.16 (Lovelace SR16)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.