fix: require edit_post access on notification subscription AJAX handlers#931
Merged
Conversation
…ndlers Without this check, any user with the edit_post_subscriptions capability could modify subscriptions (or follow/unfollow) for ANY post, including posts they have no edit access to. - ajax_save_post_subscriptions: add edit_post check alongside the existing edit_post_subscriptions_cap check so only users who can edit the target post may update its subscriber list. - handle_user_post_subscription: add the same edit_post check after the post is fetched, mirroring the gate already applied in filter_post_row_actions(). Tests added for both handlers: an author (who has edit_post_subscriptions but cannot edit another user's post) is now correctly rejected. Agent-Logs-Url: https://github.com/Automattic/edit-flow/sessions/40903bf2-8e98-4206-a6ed-b8d9d3b67208 Co-authored-by: mjangda <86105+mjangda@users.noreply.github.com>
…ption Defensive return ensures execution stops after the error response, even if wp_die() is intercepted (e.g. in test environments). Agent-Logs-Url: https://github.com/Automattic/edit-flow/sessions/40903bf2-8e98-4206-a6ed-b8d9d3b67208 Co-authored-by: mjangda <86105+mjangda@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
mjangda
April 20, 2026 18:52
View session
mjangda
approved these changes
Apr 20, 2026
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.
Both
ajax_save_post_subscriptionsandhandle_user_post_subscriptioncheckededit_post_subscriptionscapability but notcurrent_user_can( 'edit_post', $post_id ), allowing any user with that cap to read/write subscriptions on posts they have no editorial access to.Changes
ajax_save_post_subscriptions— addsedit_postcheck to the existing guard condition alongsideedit_post_subscriptions_cap, so only users who can edit the target post may update its subscriber list.handle_user_post_subscription— adds the sameedit_postcheck after the post is fetched and validated, mirroring the gate already enforced infilter_post_row_actions().Tests
Added two integration tests in
NotificationsAjaxTestusing anauthoruser (hasedit_post_subscriptionsbut can only edit their own posts):test_ajax_save_fails_when_user_cannot_edit_post— expectsWPAjaxDieStopExceptionwhen saving subscriptions on another user's post.test_handle_user_post_subscription_fails_when_user_cannot_edit_post— expects a JSON error response when following another user's post.