From cc3750f8e5a524c5bd87a346adc52e946947e387 Mon Sep 17 00:00:00 2001 From: Huzaifa Al Mesbah Date: Wed, 18 Nov 2026 15:39:56 +0600 Subject: [PATCH 1/2] Plugins: Show the output of a plugin that fails to activate. When a plugin triggers a fatal error or exits during activation, the error notice appends an `error_scrape` iframe that shows the plugin's output. Since r56573 that notice is printed with `wp_admin_notice()`, which passes the message through `wp_kses_post()`. `'; + + /* + * wp_admin_notice() passes the message through wp_kses_post(), which strips iframes. + * Allow the iframe for this notice only, so the error output can be displayed. + */ + $allow_error_iframe = static function ( $tags, $context ) { + if ( 'post' === $context ) { + $tags['iframe'] = array( + 'src' => true, + 'style' => true, + 'width' => true, + 'height' => true, + ); + } + + return $tags; + }; + + add_filter( 'wp_kses_allowed_html', $allow_error_iframe, 10, 2 ); } wp_admin_notice( @@ -713,6 +732,9 @@ ) ); + if ( isset( $allow_error_iframe ) ) { + remove_filter( 'wp_kses_allowed_html', $allow_error_iframe ); + } } elseif ( isset( $_GET['deleted'] ) ) { $delete_result = get_option( 'plugins_delete_result_' . $user_ID ); // Delete it once we're done. From 112aaadbd7457d7b1e0b409df3e9113bc0787dae Mon Sep 17 00:00:00 2001 From: Huzaifa Al Mesbah Date: Wed, 18 Nov 2026 15:52:42 +0600 Subject: [PATCH 2/2] Plugins: Allow the iframe for the activation error notice only. Instead of temporarily filtering `wp_kses_allowed_html` while `wp_admin_notice()` runs, which also allowed iframes in any `wp_kses_post()` call made by a `wp_admin_notice` callback or notice filter, fire the `wp_admin_notice` action and sanitize this notice's markup with a local allowlist that adds the iframe. See #60373. --- src/wp-admin/plugins.php | 45 +++++++++++++++------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index 4784de54d42f8..700f5b2688ebd 100644 --- a/src/wp-admin/plugins.php +++ b/src/wp-admin/plugins.php @@ -690,6 +690,12 @@ $errmsg = __( 'Plugin could not be activated because it triggered a fatal error.' ); } + $error_notice_args = array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + ); + $allowed_html = wp_kses_allowed_html( 'post' ); + if ( ! isset( $_GET['main'] ) && ! isset( $_GET['charsout'] ) && isset( $_GET['_error_nonce'] ) && wp_verify_nonce( $_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) { @@ -704,37 +710,20 @@ $errmsg .= ''; - /* - * wp_admin_notice() passes the message through wp_kses_post(), which strips iframes. - * Allow the iframe for this notice only, so the error output can be displayed. - */ - $allow_error_iframe = static function ( $tags, $context ) { - if ( 'post' === $context ) { - $tags['iframe'] = array( - 'src' => true, - 'style' => true, - 'width' => true, - 'height' => true, - ); - } - - return $tags; - }; - - add_filter( 'wp_kses_allowed_html', $allow_error_iframe, 10, 2 ); + // wp_kses_post() strips iframes, so allow this one when sanitizing this notice only. + $allowed_html['iframe'] = array( + 'src' => true, + 'style' => true, + 'width' => true, + 'height' => true, + ); } - wp_admin_notice( - $errmsg, - array( - 'id' => 'message', - 'additional_classes' => array( 'error' ), - ) - ); + /** This action is documented in wp-includes/functions.php */ + do_action( 'wp_admin_notice', $errmsg, $error_notice_args ); - if ( isset( $allow_error_iframe ) ) { - remove_filter( 'wp_kses_allowed_html', $allow_error_iframe ); - } + // Same as wp_admin_notice(), but sanitized with the allowed HTML above instead of wp_kses_post(). + echo wp_kses( wp_get_admin_notice( $errmsg, $error_notice_args ), $allowed_html ); } elseif ( isset( $_GET['deleted'] ) ) { $delete_result = get_option( 'plugins_delete_result_' . $user_ID ); // Delete it once we're done.