Skip to content

Require manage_options to add a custom status#940

Merged
GaryJones merged 1 commit into
developfrom
GaryJones/add-cap-check-handle-add-custom-status
Apr 23, 2026
Merged

Require manage_options to add a custom status#940
GaryJones merged 1 commit into
developfrom
GaryJones/add-cap-check-handle-add-custom-status

Conversation

@GaryJones
Copy link
Copy Markdown
Contributor

Summary

EF_Custom_Status::handle_add_custom_status() verified the form's nonce but did not re-check the user's capability, leaving the action relying on the surrounding admin page's render-time cap check. That is fragile as defence in depth: a user who obtains a valid custom-status-add-nonce (for example through an XSS chain, a shared clipboard, or a leaked form) could submit the handler directly and have a status created on their behalf, even if they lack manage_options.

This change adds an explicit current_user_can( 'manage_options' ) check immediately after the nonce is verified, mirroring the pattern already used by the migrate, edit, and delete handlers in the same class. New integration tests cover both directions: a subscriber with a valid nonce hits wp_die, and an administrator can still complete the flow end-to-end.

Test plan

  • composer test — the two new tests in CustomStatusAddHandlerTest pass
  • Manually submit the Add Status form as an administrator; the status is created
  • Manually submit the same form as a subscriber (with a forged cap but valid nonce); the request is rejected with the "invalid permissions" message

The handle_add_custom_status admin handler verified the nonce but did
not re-check the user's capability, leaving the action relying solely
on the admin page's render-time cap check. A user with a valid nonce
(e.g. a lower-privileged contributor who obtains one via XSS or a
shared form) could therefore create custom statuses. Layering an
explicit manage_options check restores defence in depth and matches
the pattern used elsewhere in the module.
@GaryJones GaryJones requested a review from a team as a code owner April 23, 2026 23:20
@GaryJones GaryJones added this to the Next milestone Apr 23, 2026
@GaryJones GaryJones self-assigned this Apr 23, 2026
@GaryJones GaryJones merged commit b80eef6 into develop Apr 23, 2026
10 checks passed
@GaryJones GaryJones deleted the GaryJones/add-cap-check-handle-add-custom-status branch April 23, 2026 23:26
@GaryJones GaryJones mentioned this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant