Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/powerkit/admin/class-admin-powerkit-manager.php
+++ b/powerkit/admin/class-admin-powerkit-manager.php
@@ -363,7 +363,7 @@
return;
}
- $action = sanitize_title( $_REQUEST['action'] ); // Input var ok; sanitization ok.
+ $action = sanitize_title( wp_unslash( $_REQUEST['action'] ) ); // Input var ok; sanitization ok.
// Bulk Actions.
if ( isset( $_REQUEST['checked'] ) && is_array( $_REQUEST['checked'] ) ) { // Input var ok; sanitization ok.
--- a/powerkit/core/core-powerkit-helpers.php
+++ b/powerkit/core/core-powerkit-helpers.php
@@ -20,10 +20,26 @@
*/
function powerkit_alert_warning( $message ) {
if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
+ // Messages are built in-plugin and carry only a settings link, but some of
+ // them embed an error string returned by a remote API. Allow exactly the
+ // markup the plugin's own messages use and drop everything else.
+ $allowed_html = array(
+ 'object' => array(),
+ 'a' => array(
+ 'href' => true,
+ 'target' => true,
+ 'rel' => true,
+ 'title' => true,
+ ),
+ 'br' => array(),
+ 'em' => array(),
+ 'strong' => array(),
+ 'code' => array(),
+ );
?>
<p class="pk-alert pk-alert-warning" role="alert">
<object>
- <?php call_user_func( 'printf', '%s', $message ); ?>
+ <?php echo wp_kses( $message, $allowed_html ); ?>
</object>
<?php esc_html_e( ' Don’t worry, this error is visible to site admins only, and your site visitors won’t see it.', 'powerkit' ); ?>
--- a/powerkit/core/core-powerkit-post-meta.php
+++ b/powerkit/core/core-powerkit-post-meta.php
@@ -223,8 +223,10 @@
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
/* translators: %s: author name */
esc_attr( sprintf( __( 'View all posts by %s', 'powerkit' ), get_the_author() ) ),
- // Author.
- get_the_author()
+ // Author. Filtered rather than escaped so that a display name containing
+ // markup keeps rendering as it does today, while scripts and event
+ // handlers are removed even if a caller echoes this return value raw.
+ wp_kses_post( get_the_author() )
);
$output .= '</' . esc_html( $tag ) . '>';
--- a/powerkit/extensions/connect/class-powerkit-connect.php
+++ b/powerkit/extensions/connect/class-powerkit-connect.php
@@ -80,7 +80,8 @@
<?php
$connect_list = array_values( $connect_list );
- $tab = sanitize_title( isset( $_GET['tab'] ) ? $_GET['tab'] : $connect_list[0]['id'] ); // Input var ok; sanitization ok.
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab switch, changes nothing.
+ $tab = sanitize_title( isset( $_GET['tab'] ) ? wp_unslash( $_GET['tab'] ) : $connect_list[0]['id'] );
?>
<nav class="nav-tab-wrapper woo-nav-tab-wrapper">
@@ -365,7 +366,7 @@
}
if ( isset( $_POST['logout_account_type'] ) ) {
- $this->location_reset_cache( $_POST['logout_account_type'] );
+ $this->location_reset_cache( sanitize_key( wp_unslash( $_POST['logout_account_type'] ) ) );
}
printf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Account disabled successfully.', 'powerkit' ) );
--- a/powerkit/extensions/fonts/class-powerkit-fonts.php
+++ b/powerkit/extensions/fonts/class-powerkit-fonts.php
@@ -85,7 +85,8 @@
<?php
$first_settings = current( $fonts_settings );
- $tab = sanitize_title( isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : $first_settings['id'] ); // Input var ok; sanitization ok.
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab switch, changes nothing.
+ $tab = sanitize_title( isset( $_REQUEST['tab'] ) ? wp_unslash( $_REQUEST['tab'] ) : $first_settings['id'] );
?>
<nav class="nav-tab-wrapper">
<?php
--- a/powerkit/modules/basic-elements/templates/progressbars.php
+++ b/powerkit/modules/basic-elements/templates/progressbars.php
@@ -93,10 +93,10 @@
function powerkit_basic_shortcodes_progressbar( $output, $atts, $content ) {
// Value.
- $atts['value'] = $atts['value'] > 100 ? 100 : $atts['value'];
+ $atts['value'] = ( is_numeric( $atts['value'] ) && $atts['value'] > 100 ) ? 100 : $atts['value'];
// Display value.
- $display_value = ( 'true' === $atts['display_value'] ) ? $atts['value'] . '%' : '';
+ $display_value = ( 'true' === $atts['display_value'] ) ? esc_html( $atts['value'] ) . '%' : '';
// Striped and animated.
$class = 'pk-progress-bar';
@@ -104,15 +104,22 @@
$class .= ( 'true' === $atts['animated'] ) ? ' pk-progress-bar-animated' : '';
// Color.
- $class .= sprintf( ' pk-bg-%s', $atts['color'] );
+ $class .= ' pk-bg-' . sanitize_html_class( $atts['color'] );
+
+ // Dimensions. Both are cast to a number so they can never break out of the
+ // style attribute. A non-numeric value drops the declaration, which is how
+ // a browser already treats an invalid one.
+ $height_css = is_numeric( $atts['height'] ) ? sprintf( 'height: %spx;', (float) $atts['height'] ) : '';
+ $width_css = is_numeric( $atts['value'] ) ? sprintf( 'width: %s%%;', (float) $atts['value'] ) : '';
$output = sprintf(
- '<div class="pk-progress" style="height: %2$spx;">
- <div class="%s" role="progressbar" style="width: %3$s%%;" aria-valuenow="%3$s" aria-valuemin="0" aria-valuemax="100">%4$s</div>
+ '<div class="pk-progress" style="%2$s">
+ <div class="%1$s" role="progressbar" style="%3$s" aria-valuenow="%4$s" aria-valuemin="0" aria-valuemax="100">%5$s</div>
</div>',
- $class,
- $atts['height'],
- $atts['value'],
+ esc_attr( $class ),
+ esc_attr( $height_css ),
+ esc_attr( $width_css ),
+ esc_attr( $atts['value'] ),
$display_value
);
--- a/powerkit/modules/basic-elements/templates/separators.php
+++ b/powerkit/modules/basic-elements/templates/separators.php
@@ -61,10 +61,20 @@
*/
function powerkit_basic_shortcodes_separator( $output, $atts, $content ) {
+ // Allowed CSS border-style keywords. The list is wider than the options the
+ // radio field offers, so a hand-written style="groove" keeps working. Any
+ // other value drops the declaration, which is how a browser already treats
+ // an invalid one.
+ $allowed_styles = array( 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset' );
+
if ( 'blank' === $atts['style'] ) {
$inl_css = sprintf( 'style="height: %dpx;"', absint( $atts['height'] ) );
} else {
- $inl_css = sprintf( 'style="border-bottom-width: %dpx; border-bottom-style: %s;"', absint( $atts['height'] ), $atts['style'] );
+ $border_style = in_array( $atts['style'], $allowed_styles, true )
+ ? sprintf( ' border-bottom-style: %s;', $atts['style'] )
+ : '';
+
+ $inl_css = sprintf( 'style="border-bottom-width: %dpx;%s"', absint( $atts['height'] ), $border_style );
}
$output = sprintf(
--- a/powerkit/modules/basic-elements/templates/tabs.php
+++ b/powerkit/modules/basic-elements/templates/tabs.php
@@ -130,9 +130,9 @@
// Tabs Output.
$output = '';
- $output .= '<div class="pk-tabs pk-tabs-' . $atts['nav'] . '">';
+ $output .= '<div class="pk-tabs pk-tabs-' . sanitize_html_class( $atts['nav'] ) . '">';
$output .= '<div class="pk-tabs-container">';
- $output .= '<div class="pk-tabs-navigation"><ul class="pk-nav pk-nav-' . $atts['type'] . '" role="tablist">' . $nav_items . '</ul></div>';
+ $output .= '<div class="pk-tabs-navigation"><ul class="pk-nav pk-nav-' . sanitize_html_class( $atts['type'] ) . '" role="tablist">' . $nav_items . '</ul></div>';
$output .= '<div class="pk-tabs-content"><div class="pk-tab-content">' . $pane_items . '</div></div>';
$output .= '</div>';
$output .= '</div>';
--- a/powerkit/modules/class-powerkit-custom-fonts.php
+++ b/powerkit/modules/class-powerkit-custom-fonts.php
@@ -302,7 +302,7 @@
// Check custom action.
if ( isset( $_REQUEST['action'] ) ) { // Input var ok; sanitization ok.
- $action = sanitize_title( $_REQUEST['action'] ); // Input var ok; sanitization ok.
+ $action = sanitize_title( wp_unslash( $_REQUEST['action'] ) ); // Input var ok; sanitization ok.
if ( isset( $_REQUEST['powerkit_custom_fonts_id'] ) && 'edit' === $action ) { // Input var ok.
$powerkit_custom_fonts_id = sanitize_key( wp_unslash( $_REQUEST['powerkit_custom_fonts_id'] ) ); // Input var ok.
@@ -626,7 +626,7 @@
// Set new settings.
if ( isset( $_POST['powerkit_custom_fonts_name'] ) ) { // Input var ok.
- $font_list[ $id ]['slug'] = sanitize_title( $_POST['powerkit_custom_fonts_name'] ); // Input var ok; sanitization ok.
+ $font_list[ $id ]['slug'] = sanitize_title( wp_unslash( $_POST['powerkit_custom_fonts_name'] ) ); // Input var ok; sanitization ok.
}
if ( isset( $_POST['powerkit_custom_fonts_name'] ) ) { // Input var ok.
$font_list[ $id ]['name'] = sanitize_text_field( wp_unslash( $_POST['powerkit_custom_fonts_name'] ) ); // Input var ok; sanitization ok.
--- a/powerkit/modules/featured-categories/admin/class-powerkit-featured-categories-admin.php
+++ b/powerkit/modules/featured-categories/admin/class-powerkit-featured-categories-admin.php
@@ -113,7 +113,7 @@
}
// if our nonce isn't there, or we can't verify it, bail.
- if ( ! isset( $_POST['powerkit_category'] ) || ! wp_verify_nonce( $_POST['powerkit_category'], 'category_options' ) ) { // Input var ok; sanitization ok.
+ if ( ! isset( $_POST['powerkit_category'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['powerkit_category'] ) ), 'category_options' ) ) { // Input var ok; sanitization ok.
return;
}
--- a/powerkit/modules/headers-footers/admin/class-powerkit-headers-footers-admin.php
+++ b/powerkit/modules/headers-footers/admin/class-powerkit-headers-footers-admin.php
@@ -121,11 +121,17 @@
if ( isset( $_POST['save_settings'] ) ) { // Input var ok.
+ // sanitize_code() is the sanitiser here: it keeps the markup intact only
+ // for users who hold unfiltered_html and runs wp_kses_post() for everyone
+ // else. That is the whole point of this screen, so the raw value has to
+ // reach it unmodified.
if ( isset( $_POST['powerkit_insert_header_code'] ) ) { // Input var ok.
- update_option( 'powerkit_insert_header_code', $this->sanitize_code( wp_unslash( $_POST['powerkit_insert_header_code'] ) ) ); // Input var ok.
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitised by sanitize_code().
+ update_option( 'powerkit_insert_header_code', $this->sanitize_code( wp_unslash( $_POST['powerkit_insert_header_code'] ) ) );
}
if ( isset( $_POST['powerkit_insert_footer_code'] ) ) { // Input var ok.
- update_option( 'powerkit_insert_footer_code', $this->sanitize_code( wp_unslash( $_POST['powerkit_insert_footer_code'] ) ) ); // Input var ok.
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitised by sanitize_code().
+ update_option( 'powerkit_insert_footer_code', $this->sanitize_code( wp_unslash( $_POST['powerkit_insert_footer_code'] ) ) );
}
printf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Settings saved.', 'powerkit' ) );
}
--- a/powerkit/modules/post-format-ui/admin/class-powerkit-post-format-ui-admin.php
+++ b/powerkit/modules/post-format-ui/admin/class-powerkit-post-format-ui-admin.php
@@ -98,7 +98,7 @@
}
if ( isset( $_POST['url'] ) ) { // Input var ok; sanitization ok.
- $url = $_POST['url']; // Input var ok; sanitization ok.
+ $url = esc_url_raw( wp_unslash( $_POST['url'] ) ); // Input var ok; sanitization ok.
}
if ( ! isset( $url ) ) {
@@ -341,7 +341,7 @@
}
// if our nonce isn't there, or we can't verify it, bail.
- if ( ! isset( $_POST['pk-post-format'] ) || ! wp_verify_nonce( $_POST['pk-post-format'], 'pk-post-format' ) ) { // Input var ok; sanitization ok.
+ if ( ! isset( $_POST['pk-post-format'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['pk-post-format'] ) ), 'pk-post-format' ) ) { // Input var ok; sanitization ok.
return;
}
--- a/powerkit/modules/post-views/admin/class-powerkit-post-views-admin.php
+++ b/powerkit/modules/post-views/admin/class-powerkit-post-views-admin.php
@@ -250,7 +250,7 @@
$result = $request->request( 'https://accounts.google.com/o/oauth2/token', array(
'method' => 'POST',
'body' => array(
- 'code' => sanitize_text_field( isset( $_GET['code'] ) ? $_GET['code'] : null ), // Input var ok; sanitization ok.
+ 'code' => sanitize_text_field( isset( $_GET['code'] ) ? wp_unslash( $_GET['code'] ) : null ), // Input var ok; sanitization ok.
'client_id' => $options['clientid'],
'client_secret' => $options['psecret'],
'redirect_uri' => powerkit_get_page_url( $this->slug ),
--- a/powerkit/modules/post-views/public/class-powerkit-post-views-public.php
+++ b/powerkit/modules/post-views/public/class-powerkit-post-views-public.php
@@ -38,8 +38,10 @@
return;
}
- if ( isset( $_REQUEST['post_id'] ) && $_REQUEST['post_id'] ) { // Input var ok; sanitization ok.
- $post_id = (int) sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) ); // Input var ok; sanitization ok.
+ $requested_post_id = isset( $_REQUEST['post_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) ) : ''; // Input var ok; sanitization ok.
+
+ if ( $requested_post_id ) {
+ $post_id = (int) $requested_post_id;
$result = esc_html( powerkit_get_post_views( $post_id, true, false ) );
--- a/powerkit/modules/share-buttons/admin/class-powerkit-share-buttons-admin.php
+++ b/powerkit/modules/share-buttons/admin/class-powerkit-share-buttons-admin.php
@@ -162,7 +162,8 @@
<?php
$locations = array_values( $locations );
- $tab = sanitize_title( isset( $_GET['tab'] ) ? $_GET['tab'] : $locations[0]['location'] ); // Input var ok; sanitization ok.
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab switch, changes nothing.
+ $tab = sanitize_title( isset( $_GET['tab'] ) ? wp_unslash( $_GET['tab'] ) : $locations[0]['location'] );
?>
<nav class="nav-tab-wrapper woo-nav-tab-wrapper">
--- a/powerkit/powerkit.php
+++ b/powerkit/powerkit.php
@@ -2,7 +2,7 @@
/**
* Plugin Name: Powerkit
* Description: Powerkit – essential components for every WordPress site.
- * Version: 3.1.0
+ * Version: 3.1.1
* Author: Code Supply Co.
* Author URI: https://codesupply.co
* License: GPL-2.0+