WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/29/2020 04:15:39 PM (17 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.
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], [47637], and [47638] to the 4.9 branch.

Props: batmoo, ehti, nickdaugherty, peterwilsoncc, sergeybiryukov, sstoqnov, westi, westonruter, whyisjake, whyisjake, xknown.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

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

    r43707 r47648  
    28602860        add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 );
    28612861
    2862         // Update the changeset post. The publish_customize_changeset action will cause the settings in the changeset to be saved via WP_Customize_Setting::save().
    2863         $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
    2864         if ( $has_kses ) {
    2865             kses_remove_filters(); // Prevent KSES from corrupting JSON in post_content.
    2866         }
    2867 
    2868         // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values().
     2862        /*
     2863         * Update the changeset post. The publish_customize_changeset action will cause the settings in the
     2864         * changeset to be saved via WP_Customize_Setting::save(). Updating a post with publish status will
     2865         * trigger WP_Customize_Manager::publish_changeset_values().
     2866         */
     2867        add_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5, 3 );
    28692868        if ( $changeset_post_id ) {
    28702869            if ( $args['autosave'] && 'auto-draft' !== get_post_status( $changeset_post_id ) ) {
     
    28932892            }
    28942893        }
    2895         if ( $has_kses ) {
    2896             kses_init_filters();
    2897         }
     2894
     2895        remove_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5 );
     2896
    28982897        $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
    28992898
     
    29102909
    29112910        return $response;
     2911    }
     2912
     2913    /**
     2914     * Preserve the initial JSON post_content passed to save into the post.
     2915     *
     2916     * This is needed to prevent KSES and other {@see 'content_save_pre'} filters
     2917     * from corrupting JSON data.
     2918     *
     2919     * Note that WP_Customize_Manager::validate_setting_values() have already
     2920     * run on the setting values being serialized as JSON into the post content
     2921     * so it is pre-sanitized.
     2922     *
     2923     * Also, the sanitization logic is re-run through the respective
     2924     * WP_Customize_Setting::sanitize() method when being read out of the
     2925     * changeset, via WP_Customize_Manager::post_value(), and this sanitized
     2926     * value will also be sent into WP_Customize_Setting::update() for
     2927     * persisting to the DB.
     2928     *
     2929     * Multiple users can collaborate on a single changeset, where one user may
     2930     * have the unfiltered_html capability but another may not. A user with
     2931     * unfiltered_html may add a script tag to some field which needs to be kept
     2932     * intact even when another user updates the changeset to modify another field
     2933     * when they do not have unfiltered_html.
     2934     *
     2935     * @since 5.4.1
     2936     *
     2937     * @param array $data                An array of slashed and processed post data.
     2938     * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
     2939     * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as originally passed to wp_insert_post().
     2940     * @return array Filtered post data.
     2941     */
     2942    public function preserve_insert_changeset_post_content( $data, $postarr, $unsanitized_postarr ) {
     2943        if (
     2944            isset( $data['post_type'] ) &&
     2945            isset( $unsanitized_postarr['post_content'] ) &&
     2946            'customize_changeset' === $data['post_type'] ||
     2947            (
     2948                'revision' === $data['post_type'] &&
     2949                ! empty( $data['post_parent'] ) &&
     2950                'customize_changeset' === get_post_type( $data['post_parent'] )
     2951            )
     2952        ) {
     2953            $data['post_content'] = $unsanitized_postarr['post_content'];
     2954        }
     2955        return $data;
    29122956    }
    29132957
Note: See TracChangeset for help on using the changeset viewer.