Opened 8 years ago
Last modified 7 years ago
#39061 reopened enhancement
REST API pagination: Large INT passed to `paged` query arg doesn't fail properly
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | needs-patch needs-unit-tests |
Focuses: | Cc: |
Description
When an absurdly large value is passed to the REST API (e.g. /wp/v2/pages?page=23924321212413345333
), it returns the first page of results instead of an error. The problem is during validation and sanitization of the value, where the passed value is run through absint
, which returns another absurdly large value, which then gets nullified by PHP, which becomes 1
.
wp> print_r( rest_sanitize_value_from_schema( 23452345346346345456567356, array( 'type' => 'integer' ), 'page' ) ); 3481259413623275520 => bool(true) wp> print_r( rest_validate_value_from_schema( 23452345346346345456567356, array( 'type' => 'integer' ), 'page' ) ); 1 => bool(true) wp> absint(23924321212413345333); => int(5477577138703794176)
Edge case, but worth noting since smaller values that are larger than the number of pages return an empty array (like if there are only 2 pages of posts, but 3 are requested).
Related: #19728.
Attachments (4)
Change History (27)
#1
@
8 years ago
- Keywords needs-patch needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
- Type changed from defect (bug) to enhancement
#2
@
8 years ago
@rachelbaker yep, I'll work on "smaller values that are larger than the number of pages return an empty array (like if there are only 2 pages of posts, but 3 are requested)."
#3
@
8 years ago
39061.diff is a first pass at returning an error for an out-of-bounds page request for posts. If this looks right, I'll do the same for the other endpoints.
#6
@
8 years ago
Added a test for OOB posts pagination in 39061.2.diff.
#7
@
8 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
In 39061.3.diff: make sure to check for no posts in a response before returning an error. This prevents unintended failure on empty arrays when none are expected.
#8
@
8 years ago
It seems like the cutoff value here is PHP_INT_MAX
, so could we just check $value > PHP_INT_MAX
?
#9
@
8 years ago
- Owner set to joehoyle
- Resolution set to fixed
- Status changed from new to closed
In 39967:
This ticket was mentioned in Slack in #core by joehoyle. View the logs.
8 years ago
#13
@
8 years ago
- Keywords needs-patch needs-unit-tests added; has-patch dev-feedback has-unit-tests removed
- Resolution fixed deleted
- Status changed from closed to reopened
We should do the same for all endpoints (terms, comments and users) as mentioned in comment:3.
#14
@
8 years ago
Attached a patch for comments endpoint with the same functionality:
- Handle
page
query var that is bigger than PHP_MAX_INT. - Show an out of bounds error if the
page
is larger thanX-TotalPages
Like /wp/v2/posts
we also no longer return pagination headers in the case of the out of bounds error.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#19
@
8 years ago
- Milestone changed from 4.8.1 to 4.9
Punting to 4.9 per today's bug scrub and so @morganestes can split out tickets for all endpoints (terms, comments and users).
Related #28559
@morganestes want to work on a patch?