Skip to content

Use correct wp_kses arguments in inline-save error paths#943

Merged
GaryJones merged 1 commit intodevelopfrom
GaryJones/fix-wp-kses-inline-save-errors
Apr 23, 2026
Merged

Use correct wp_kses arguments in inline-save error paths#943
GaryJones merged 1 commit intodevelopfrom
GaryJones/fix-wp-kses-inline-save-errors

Conversation

@GaryJones
Copy link
Copy Markdown
Contributor

Summary

Three inline-save AJAX handlers — for custom statuses, editorial metadata terms and user groups — built their "could not update" error message with sprintf and then ran it through wp_kses() with the wrong second argument. Two of them passed the string 'strong', which wp_kses_allowed_html() does not recognise as a context and so silently collapses to the small default inline-tag allowlist. The third passed nothing at all, which produces a TypeError on PHP 8 because $allowed_html is a required parameter; reaching the error branch on a modern install thus turns a benign "term could not be updated" path into a fatal.

Each site now passes an explicit array( 'strong' => array() ) so only the intended bold wrapper survives kses, and the user-supplied term name interpolated into the message is first run through esc_html(). The belt-and-braces shape matches the other wp_die() error paths in the same handlers — even if a translation file is ever tampered with, the inserted name cannot break out of the wrapper.

No behaviour change on a happy path: the message still renders the same for the administrator who hits it. The PHP 8 fatal is the only user-visible difference, and that was already latent in editorial-metadata.php before this PR.

Test plan

  • composer test:integration — existing tests continue to pass
  • On PHP 8, force the error branch in handle_ajax_inline_save_term (e.g. by temporarily making update_editorial_metadata_term return a WP_Error); confirm the response is a formatted error rather than a TypeError

Three inline-save AJAX handlers (custom-status, editorial-metadata and
user-groups) built their "could not update" error message with sprintf
and then passed it through wp_kses() with the wrong second argument.
Two sites passed the string 'strong', which wp_kses treats as a
context name via wp_kses_allowed_html(); the third passed nothing at
all, which produces a TypeError on PHP 8 because $allowed_html is a
required parameter. The latter turns a benign error path into a
fatal.

Each call now passes an explicit array( 'strong' => array() ), so only
the intended bold wrapper survives. The user-supplied term name that
is interpolated into the message is run through esc_html() first, so
a name containing HTML cannot break out of the wrapper even if the
translated string is ever tampered with. This is the same belt-and-
braces shape used for the adjacent wp_die error paths in the same
handlers.
@GaryJones GaryJones requested a review from a team as a code owner April 23, 2026 23:29
@GaryJones GaryJones self-assigned this Apr 23, 2026
@GaryJones GaryJones added this to the Next milestone Apr 23, 2026
@GaryJones GaryJones merged commit f6cb3ed into develop Apr 23, 2026
10 checks passed
@GaryJones GaryJones deleted the GaryJones/fix-wp-kses-inline-save-errors branch April 23, 2026 23:42
@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