Make WordPress Core


Ignore:
Timestamp:
04/29/2020 04:22:22 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.
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.7 branch.

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

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

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

    r41430 r47650  
    25262526        add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 );
    25272527
    2528         // Update the changeset post. The publish_customize_changeset action will cause the settings in the changeset to be saved via WP_Customize_Setting::save().
    2529         $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
    2530         if ( $has_kses ) {
    2531             kses_remove_filters(); // Prevent KSES from corrupting JSON in post_content.
    2532         }
    2533 
    2534         // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values().
     2528        /*
     2529         * Update the changeset post. The publish_customize_changeset action will cause the settings in the
     2530         * changeset to be saved via WP_Customize_Setting::save(). Updating a post with publish status will
     2531         * trigger WP_Customize_Manager::publish_changeset_values().
     2532         */
     2533        add_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5, 3 );
    25352534        if ( $changeset_post_id ) {
    25362535            $post_array['edit_date'] = true; // Prevent date clearing.
     
    25422541            }
    25432542        }
    2544         if ( $has_kses ) {
    2545             kses_init_filters();
    2546         }
     2543
     2544        remove_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5 );
     2545
    25472546        $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
    25482547
     
    25592558
    25602559        return $response;
     2560    }
     2561
     2562    /**
     2563     * Preserve the initial JSON post_content passed to save into the post.
     2564     *
     2565     * This is needed to prevent KSES and other {@see 'content_save_pre'} filters
     2566     * from corrupting JSON data.
     2567     *
     2568     * Note that WP_Customize_Manager::validate_setting_values() have already
     2569     * run on the setting values being serialized as JSON into the post content
     2570     * so it is pre-sanitized.
     2571     *
     2572     * Also, the sanitization logic is re-run through the respective
     2573     * WP_Customize_Setting::sanitize() method when being read out of the
     2574     * changeset, via WP_Customize_Manager::post_value(), and this sanitized
     2575     * value will also be sent into WP_Customize_Setting::update() for
     2576     * persisting to the DB.
     2577     *
     2578     * Multiple users can collaborate on a single changeset, where one user may
     2579     * have the unfiltered_html capability but another may not. A user with
     2580     * unfiltered_html may add a script tag to some field which needs to be kept
     2581     * intact even when another user updates the changeset to modify another field
     2582     * when they do not have unfiltered_html.
     2583     *
     2584     * @since 5.4.1
     2585     *
     2586     * @param array $data                An array of slashed and processed post data.
     2587     * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
     2588     * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as originally passed to wp_insert_post().
     2589     * @return array Filtered post data.
     2590     */
     2591    public function preserve_insert_changeset_post_content( $data, $postarr, $unsanitized_postarr ) {
     2592        if (
     2593            isset( $data['post_type'] ) &&
     2594            isset( $unsanitized_postarr['post_content'] ) &&
     2595            'customize_changeset' === $data['post_type'] ||
     2596            (
     2597                'revision' === $data['post_type'] &&
     2598                ! empty( $data['post_parent'] ) &&
     2599                'customize_changeset' === get_post_type( $data['post_parent'] )
     2600            )
     2601        ) {
     2602            $data['post_content'] = $unsanitized_postarr['post_content'];
     2603        }
     2604        return $data;
    25612605    }
    25622606
Note: See TracChangeset for help on using the changeset viewer.