Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/post-duplicator/includes/api.php
+++ b/post-duplicator/includes/api.php
@@ -809,14 +809,26 @@
$duplicate['post_author'] = get_current_user_id();
}
- // Sanitize post content
- add_filter( 'wp_kses_allowed_html', __NAMESPACE__ . 'additional_kses', 10, 2 );
- $duplicate['post_content'] = wp_slash( wp_kses_post( $duplicate['post_content'] ) );
- remove_filter( 'wp_kses_allowed_html', __NAMESPACE__ . 'additional_kses', 10, 2 );
+ // Users who can save unfiltered HTML already stored this content. Running it
+ // through KSES again drops inline styles WordPress itself kept, including
+ // transparent rgba() highlight backgrounds on <mark>.
+ $kses_post_content = ! current_user_can( 'unfiltered_html' );
+ if ( $kses_post_content ) {
+ add_filter( 'safecss_filter_attr_allow_css', __NAMESPACE__ . 'allow_safe_inline_color_css', 10, 2 );
+ add_filter( 'wp_kses_allowed_html', __NAMESPACE__ . 'additional_kses', 10, 2 );
+ $duplicate['post_content'] = wp_kses_post( $duplicate['post_content'] );
+ remove_filter( 'wp_kses_allowed_html', __NAMESPACE__ . 'additional_kses', 10, 2 );
+ }
+ $duplicate['post_content'] = wp_slash( $duplicate['post_content'] );
- // Insert the post into the database
+ // Insert the post into the database. Keep the color filter active so
+ // content_save_pre does not strip the same styles for users without unfiltered_html.
$duplicate_id = wp_insert_post( $duplicate );
+ if ( $kses_post_content ) {
+ remove_filter( 'safecss_filter_attr_allow_css', __NAMESPACE__ . 'allow_safe_inline_color_css', 10, 2 );
+ }
+
if ( is_wp_error( $duplicate_id ) || ! $duplicate_id ) {
return new WP_Error( 'insert_failed', esc_html__( 'Failed to create duplicate post.', 'post-duplicator' ) );
}
@@ -1089,6 +1101,39 @@
}
/**
+ * Allow safe rgb()/hsl() values in inline styles during duplication.
+ *
+ * WordPress strips these because safecss_filter_attr() rejects parentheses
+ * that are not in its function list. Block editor highlights use
+ * background-color:rgba(0, 0, 0, 0) for a transparent mark, and removing it
+ * exposes the browser's default yellow background.
+ *
+ * Only numeric color functions are allowed. The rest of the declaration still
+ * has to pass WordPress's unsafe-character check.
+ *
+ * @param bool $allow_css Whether the CSS declaration is already allowed.
+ * @param string $css_test_string CSS declaration with supported functions already removed.
+ * @return bool
+ */
+function allow_safe_inline_color_css( $allow_css, $css_test_string ) {
+ if ( $allow_css || ! is_string( $css_test_string ) || '' === $css_test_string ) {
+ return $allow_css;
+ }
+
+ $stripped = preg_replace(
+ '/b(?:rgba?|hsla?)(s*[0-9.%s,/+-]+s*)/',
+ '',
+ $css_test_string
+ );
+
+ if ( null === $stripped || $stripped === $css_test_string ) {
+ return $allow_css;
+ }
+
+ return 0 === preg_match( '%[\(&=}]|/*%', $stripped );
+}
+
+/**
* Add custom allowed kses
*/
function additional_kses( $allowed_tags ) {
--- a/post-duplicator/includes/mtphr-settings/index.php
+++ b/post-duplicator/includes/mtphr-settings/index.php
@@ -274,6 +274,21 @@
}
/**
+ * Whether an option name was registered by a settings section.
+ *
+ * @param mixed $option Option name.
+ * @return bool
+ */
+ private function is_registered_option( $option ) {
+ if ( ! is_string( $option ) || '' === $option ) {
+ return false;
+ }
+
+ $options = self::$instance->options;
+ return is_array( $options ) && in_array( $option, $options, true );
+ }
+
+ /**
* Return available options keys
*/
public function get_options( $option = false ) {
@@ -1062,22 +1077,32 @@
return current_user_can('manage_options');
},
'callback' => function( $request ) {
- $args = $request->get_params();
$data = $request->get_json_params();
+ if ( ! is_array( $data ) ) {
+ $data = [];
+ }
- $value_keys = isset( $data['valueKeys'] ) ? $data['valueKeys'] : [];
- $values = isset( $data['values'] ) ? $data['values'] : [];
+ $value_keys = isset( $data['valueKeys'] ) && is_array( $data['valueKeys'] ) ? $data['valueKeys'] : [];
+ $values = isset( $data['values'] ) && is_array( $data['values'] ) ? $data['values'] : [];
- if ( is_array( $value_keys ) && ! empty( $value_keys ) ) {
- foreach ( $value_keys as $option => $keys ) {
- $values_to_update = array_intersect_key( $values[$option], array_flip( $keys ) );
- $updated_values = self::$instance->update_values( $option, $values_to_update );
- $values[$option] = $updated_values;
+ foreach ( $value_keys as $option => $keys ) {
+ if ( ! self::$instance->is_registered_option( $option ) || ! is_array( $keys ) ) {
+ return new WP_Error(
+ 'mtphr_settings_invalid_option',
+ __( 'Invalid settings option.', 'post-duplicator' ),
+ array( 'status' => 400 )
+ );
}
}
-
- //self::$instance->update_values( $values );
- return rest_ensure_response( $values , 200);
+
+ foreach ( $value_keys as $option => $keys ) {
+ $option_values = isset( $values[ $option ] ) && is_array( $values[ $option ] ) ? $values[ $option ] : [];
+ $setting_keys = array_values( array_filter( $keys, 'is_string' ) );
+ $values_to_update = array_intersect_key( $option_values, array_flip( $setting_keys ) );
+ $values[ $option ] = self::$instance->update_values( $option, $values_to_update );
+ }
+
+ return rest_ensure_response( $values );
},
) );
}
@@ -1124,6 +1149,11 @@
* Update the settings
*/
public function update_values( $option, $values = [] ) {
+ // Never read or write an option this plugin did not register.
+ if ( ! $this->is_registered_option( $option ) ) {
+ return [];
+ }
+
$settings = self::$instance->get_settings( $option );
$sanitize_settings = self::$instance->get_sanitize_settings( $option );
$option_values = self::$instance->get_option_values( $option );
--- a/post-duplicator/includes/settings.php
+++ b/post-duplicator/includes/settings.php
@@ -612,28 +612,55 @@
}
/**
- * Update a role capability
+ * Update a role capability.
+ *
+ * Only the capabilities defined by this feature may be added or removed.
+ * Any other submitted string is ignored.
*/
function update_capabilities( $value, $key, $option, $type ) {
- if ( 'update' == $type ) {
- $role = get_role( $key );
- $active_capabilities = get_active_capabilities( $role );
- $capability_value = is_array( $value ) ? $value : [];
- $added_capabilities = array_diff( $capability_value, $active_capabilities );
- $removed_capabilities = array_diff( $active_capabilities, $capability_value );
-
- if ( is_array( $added_capabilities ) && count( $added_capabilities ) > 0 ) {
- foreach ( $added_capabilities as $added_capability ) {
- $role->add_cap( esc_attr( $added_capability ) );
+ $allowed_capabilities = array_values( get_capabilities() );
+ $submitted_capabilities = [];
+
+ if ( is_array( $value ) ) {
+ foreach ( $value as $capability ) {
+ if ( is_string( $capability ) && in_array( $capability, $allowed_capabilities, true ) ) {
+ $submitted_capabilities[] = $capability;
}
}
- if ( is_array( $removed_capabilities ) && count( $removed_capabilities ) > 0 ) {
- foreach ( $removed_capabilities as $removed_capability ) {
- $role->remove_cap( esc_attr( $removed_capability ) );
- }
+ }
+
+ $submitted_capabilities = array_values( array_unique( $submitted_capabilities ) );
+
+ if ( 'update' !== $type ) {
+ return $submitted_capabilities;
+ }
+
+ $role = get_role( $key );
+ if ( ! $role instanceof WP_Role ) {
+ return $submitted_capabilities;
+ }
+
+ $active_capabilities = get_active_capabilities( $role );
+ if ( ! is_array( $active_capabilities ) ) {
+ $active_capabilities = [];
+ }
+
+ $added_capabilities = array_diff( $submitted_capabilities, $active_capabilities );
+ $removed_capabilities = array_diff( $active_capabilities, $submitted_capabilities );
+
+ foreach ( $added_capabilities as $added_capability ) {
+ if ( in_array( $added_capability, $allowed_capabilities, true ) ) {
+ $role->add_cap( $added_capability );
}
}
- return $value;
+
+ foreach ( $removed_capabilities as $removed_capability ) {
+ if ( in_array( $removed_capability, $allowed_capabilities, true ) ) {
+ $role->remove_cap( $removed_capability );
+ }
+ }
+
+ return $submitted_capabilities;
}
/**
--- a/post-duplicator/m4c-postduplicator.php
+++ b/post-duplicator/m4c-postduplicator.php
@@ -3,7 +3,7 @@
Plugin Name: Post Duplicator
Plugin URI: https://www.metaphorcreations.com/post-duplicator/
Description: Creates functionality to duplicate any and all post types, including taxonomies & custom fields
-Version: 3.0.17
+Version: 3.0.18
Author: Meta4Creations
Author URI: https://www.metaphorcreations.com/
License: GPL-2.0+
@@ -36,7 +36,7 @@
// Plugin version.
if ( ! defined( 'MTPHR_POST_DUPLICATOR_VERSION' ) ) {
- define( 'MTPHR_POST_DUPLICATOR_VERSION', '3.0.17' );
+ define( 'MTPHR_POST_DUPLICATOR_VERSION', '3.0.18' );
}
// Plugin Folder Path.