Validate metadata term in calendar AJAX update handler#946
Merged
Conversation
The handle_ajax_update_metadata handler accepted an unvalidated metadata_term from the request and used it either as part of a post meta key or as the taxonomy argument to wp_set_post_terms. A user with edit_post capability could therefore write arbitrary post meta keys on a post, or assign terms from any registered taxonomy — including taxonomies not intended to be edited via this interface. Constrain the term before use: for editorial metadata updates it must match the slug of an existing editorial metadata term, and for taxonomy updates it must be a taxonomy registered on the post's post type. Both inputs are also now sanitised up front so the phpcs suppressions can be tightened to the single value that still passes through wp_set_post_terms.
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.
Summary
EF_Calendar::handle_ajax_update_metadataaccepted ametadata_termvalue from the request and used it in two ways without checking what
it referred to. For editorial metadata updates it was concatenated
into a post meta key of the form
_ef_editorial_meta_{type}_{term};for taxonomy updates it was passed straight to
wp_set_post_termsas the taxonomy argument. A user with
edit_postcapability couldtherefore write arbitrary post meta keys on a post, or assign terms
from any registered taxonomy — including taxonomies not intended to
be edited from the calendar.
This PR constrains
metadata_termbefore it is used. For theeditorial metadata branch the term must match the slug of an
existing editorial metadata term (via
get_editorial_metadata_term_by).For the taxonomy branch it must be a taxonomy registered on the post's
post type (via
get_object_taxonomies). Both inputs are also sanitisedup front so the
phpcs:disableblock narrows to the one value that isstill passed through to
wp_set_post_termsunchanged (arrays of termIDs/names continue to be accepted there).
A new integration test exercises the three rejection paths: unknown
editorial metadata slug, unknown taxonomy, and empty term.
Test plan
composer test:integration -- tests/Integration/CalendarMetadataAjaxTest.phppasses in CI