Repository navigation
Content query: parse IDs and integer filters as schema validation does - #1075
Closed
jorgefilipecosta wants to merge 2 commits into
Closed
jorgefilipecosta wants to merge 2 commits into
jorgefilipecosta wants to merge 2 commits into
Conversation
The JSON Schema integer type accepts whole floats and numeric strings such as "12.0" or "+12", so an author or parent filter given that way passes validation and was then rejected as an invalid filter. Parse the value with rest_is_integer(), as validation does, and reject a value beyond the integer range, which a cast would wrap around onto an unrelated ID.
A whole float beyond the integer range passes the schema's integer validation, and absint() wrapped it around, so an ID of 2^64 + N read post N. Parse the ID like the filters, which rejects such a value, and skip the lookup when the ID is invalid so get_post() never falls back to the global post.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1075 +/- ##
==========================================
Coverage 81.53% 81.54%
- Complexity 3071 3072 +1
==========================================
Files 129 129
Lines 12253 12255 +2
==========================================
+ Hits 9991 9993 +2
Misses 2262 2262
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Makes
core/content-queryread itsidinput and itsauthorandparentfilters the way the input schema validates integers.Why?
The input schema declares these as integers, and the JSON Schema
integertype accepts whole floats and numeric strings such as"12.0"or"+12". The execute side read them differently:authorandparentfilters accepted only native integers and digit strings, so{"author": "12.0"}passed validation and then failed withcontent_invalid_filter.idwent throughabsint(). A whole float beyond the integer range passes validation, and the cast wraps it around, so an ID of 2^64 + 4194304 read post 4194304. The permission check resolved the same post, so read permissions still applied, but the ability returned a post the caller did not ask for. In a direct call to the execute callback, a non-numeric ID became 0, andget_post( 0 )falls back to the global post.This came up in the review of #1025, whose write abilities parse their IDs with the same helper. That PR leaves the read ability as it is, so the change lands here.
How?
parse_filter_int()accepts a value whenrest_is_integer()does, as schema validation does, and rejects a float at or beyondPHP_INT_MAXbefore casting it.check_permission()andexecute_content_query()parse theidwith it, and skip the lookup when the ID is invalid.Testing Instructions
Run the content ability tests:
Both new tests fail on
develop:test_author_filter_accepts_every_integer_formfails with "An author filter given as a whole float should be honored."test_get_by_id_beyond_the_integer_range_is_deniedfails with "An ID beyond the integer range should not resolve a post.", because the lookup returns post 4194304.Changelog Entry