WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/29/2020 04:06:55 PM (15 months ago)
Author:
whyisjake
Message:

Customize: Add additional filters to Customizer to prevent JSON corruption.
User: Invalidate user_activation_key on password update.
Query: Ensure that only a single post can be returned on date/time based queries.
Block Editor: Coding standards, properly escape class names.
Cache API: Ensure proper escaping around the stats method in the cache API.
Formatting: Expand sanitize_file_name to have better support for utf8 characters.

Brings the changes in [47633], [47634], [47635], [47636], [47637], and [47638] to the 5.1 branch.

Props: aduth, batmoo, ehti, ellatrix, jorgefilipecosta, nickdaugherty, noisysocks, pento, peterwilsoncc, sergeybiryukov, sstoqnov, talldanwp, westi, westonruter, whyisjake, whyisjake, xknown.

Location:
branches/5.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.1

  • branches/5.1/src/wp-includes/class-wp-customize-manager.php

    r44714 r47646  
    28872887
    28882888        /*
    2889          * Update the changeset post. The publish_customize_changeset action
    2890          * will cause the settings in the changeset to be saved via
    2891          * WP_Customize_Setting::save().
     2889         * Update the changeset post. The publish_customize_changeset action will cause the settings in the
     2890         * changeset to be saved via WP_Customize_Setting::save(). Updating a post with publish status will
     2891         * trigger WP_Customize_Manager::publish_changeset_values().
    28922892         */
    2893 
    2894         // Prevent content filters from corrupting JSON in post_content.
    2895         $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
    2896         if ( $has_kses ) {
    2897             kses_remove_filters();
    2898         }
    2899         $has_targeted_link_rel_filters = ( false !== has_filter( 'content_save_pre', 'wp_targeted_link_rel' ) );
    2900         if ( $has_targeted_link_rel_filters ) {
    2901             wp_remove_targeted_link_rel_filters();
    2902         }
    2903 
    2904         // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values().
     2893        add_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5, 3 );
    29052894        if ( $changeset_post_id ) {
    29062895            if ( $args['autosave'] && 'auto-draft' !== get_post_status( $changeset_post_id ) ) {
     
    29292918            }
    29302919        }
    2931 
    2932         // Restore removed content filters.
    2933         if ( $has_kses ) {
    2934             kses_init_filters();
    2935         }
    2936         if ( $has_targeted_link_rel_filters ) {
    2937             wp_init_targeted_link_rel_filters();
    2938         }
     2920        remove_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5 );
    29392921
    29402922        $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
     
    29522934
    29532935        return $response;
     2936    }
     2937
     2938    /**
     2939     * Preserve the initial JSON post_content passed to save into the post.
     2940     *
     2941     * This is needed to prevent KSES and other {@see 'content_save_pre'} filters
     2942     * from corrupting JSON data.
     2943     *
     2944     * Note that WP_Customize_Manager::validate_setting_values() have already
     2945     * run on the setting values being serialized as JSON into the post content
     2946     * so it is pre-sanitized.
     2947     *
     2948     * Also, the sanitization logic is re-run through the respective
     2949     * WP_Customize_Setting::sanitize() method when being read out of the
     2950     * changeset, via WP_Customize_Manager::post_value(), and this sanitized
     2951     * value will also be sent into WP_Customize_Setting::update() for
     2952     * persisting to the DB.
     2953     *
     2954     * Multiple users can collaborate on a single changeset, where one user may
     2955     * have the unfiltered_html capability but another may not. A user with
     2956     * unfiltered_html may add a script tag to some field which needs to be kept
     2957     * intact even when another user updates the changeset to modify another field
     2958     * when they do not have unfiltered_html.
     2959     *
     2960     * @since 5.4.1
     2961     *
     2962     * @param array $data                An array of slashed and processed post data.
     2963     * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
     2964     * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as originally passed to wp_insert_post().
     2965     * @return array Filtered post data.
     2966     */
     2967    public function preserve_insert_changeset_post_content( $data, $postarr, $unsanitized_postarr ) {
     2968        if (
     2969            isset( $data['post_type'] ) &&
     2970            isset( $unsanitized_postarr['post_content'] ) &&
     2971            'customize_changeset' === $data['post_type'] ||
     2972            (
     2973                'revision' === $data['post_type'] &&
     2974                ! empty( $data['post_parent'] ) &&
     2975                'customize_changeset' === get_post_type( $data['post_parent'] )
     2976            )
     2977        ) {
     2978            $data['post_content'] = $unsanitized_postarr['post_content'];
     2979        }
     2980        return $data;
    29542981    }
    29552982
Note: See TracChangeset for help on using the changeset viewer.