Require a nonce to change Story Budget filters#985
Merged
Conversation
Fixes VIPPLUG-19.
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
The Story Budget's filter controls change state over GET. The Reset link and the filter form both write the current user's saved filter preferences to user meta, and
update_user_filters()persisted whatever was in$_GETon every render — none of it nonce-protected. A crafted link could therefore permanently change a victim's saved Story Budget filters: a self-targeted, cosmetic CSRF, but a state change without intent all the same.The Reset link now carries a nonce that
handle_filter_reset()verifies before writing, mirroring the existing date-range form. The filter form carries a nonce too, andupdate_user_filters()only persists to user meta when the form was actually submitted with a valid nonce. A crafted URL can still filter that single page view, but it can no longer alter what the user has saved.Removing the persist-on-every-render behaviour surfaced a latent assumption:
update_user_filters_from_form_date_range_change()read the stored filters and wrote date keys onto them, butget_user_meta()returns an empty string when nothing is stored, which throws on PHP 8 when indexed. It now treats absent filters as an empty array.Fixes VIPPLUG-19.
Test plan
composer test:integration -- --filter test_filters_persist_only_with_valid_nonce— confirms filters are not persisted without a valid nonce and are persisted with one.php -lclean.