Make WordPress Core


Ignore:
Timestamp:
04/29/2020 04:04:20 PM (6 years 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.4 branch.

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

Location:
branches/5.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.3

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

    r46548 r47644  
    29242924
    29252925        /*
    2926          * Update the changeset post. The publish_customize_changeset action
    2927          * will cause the settings in the changeset to be saved via
    2928          * WP_Customize_Setting::save().
     2926         * Update the changeset post. The publish_customize_changeset action will cause the settings in the
     2927         * changeset to be saved via WP_Customize_Setting::save(). Updating a post with publish status will
     2928         * trigger WP_Customize_Manager::publish_changeset_values().
    29292929         */
    2930 
    2931         // Prevent content filters from corrupting JSON in post_content.
    2932         $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
    2933         if ( $has_kses ) {
    2934             kses_remove_filters();
    2935         }
    2936         $has_targeted_link_rel_filters = ( false !== has_filter( 'content_save_pre', 'wp_targeted_link_rel' ) );
    2937         if ( $has_targeted_link_rel_filters ) {
    2938             wp_remove_targeted_link_rel_filters();
    2939         }
    2940 
    2941         // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values().
     2930        add_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5, 3 );
    29422931        if ( $changeset_post_id ) {
    29432932            if ( $args['autosave'] && 'auto-draft' !== get_post_status( $changeset_post_id ) ) {
     
    29662955            }
    29672956        }
    2968 
    2969         // Restore removed content filters.
    2970         if ( $has_kses ) {
    2971             kses_init_filters();
    2972         }
    2973         if ( $has_targeted_link_rel_filters ) {
    2974             wp_init_targeted_link_rel_filters();
    2975         }
     2957        remove_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5 );
    29762958
    29772959        $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
     
    29892971
    29902972        return $response;
     2973    }
     2974
     2975    /**
     2976     * Preserve the initial JSON post_content passed to save into the post.
     2977     *
     2978     * This is needed to prevent KSES and other {@see 'content_save_pre'} filters
     2979     * from corrupting JSON data.
     2980     *
     2981     * Note that WP_Customize_Manager::validate_setting_values() have already
     2982     * run on the setting values being serialized as JSON into the post content
     2983     * so it is pre-sanitized.
     2984     *
     2985     * Also, the sanitization logic is re-run through the respective
     2986     * WP_Customize_Setting::sanitize() method when being read out of the
     2987     * changeset, via WP_Customize_Manager::post_value(), and this sanitized
     2988     * value will also be sent into WP_Customize_Setting::update() for
     2989     * persisting to the DB.
     2990     *
     2991     * Multiple users can collaborate on a single changeset, where one user may
     2992     * have the unfiltered_html capability but another may not. A user with
     2993     * unfiltered_html may add a script tag to some field which needs to be kept
     2994     * intact even when another user updates the changeset to modify another field
     2995     * when they do not have unfiltered_html.
     2996     *
     2997     * @since 5.4.1
     2998     *
     2999     * @param array $data                An array of slashed and processed post data.
     3000     * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
     3001     * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as originally passed to wp_insert_post().
     3002     * @return array Filtered post data.
     3003     */
     3004    public function preserve_insert_changeset_post_content( $data, $postarr, $unsanitized_postarr ) {
     3005        if (
     3006            isset( $data['post_type'] ) &&
     3007            isset( $unsanitized_postarr['post_content'] ) &&
     3008            'customize_changeset' === $data['post_type'] ||
     3009            (
     3010                'revision' === $data['post_type'] &&
     3011                ! empty( $data['post_parent'] ) &&
     3012                'customize_changeset' === get_post_type( $data['post_parent'] )
     3013            )
     3014        ) {
     3015            $data['post_content'] = $unsanitized_postarr['post_content'];
     3016        }
     3017        return $data;
    29913018    }
    29923019
Note: See TracChangeset for help on using the changeset viewer.