Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r29389 r28143  
    11201120
    11211121    /**
    1122      * Get MAC for a serialized widget instance string.
    1123      *
    1124      * Allows values posted back from JS to be rejected if any tampering of the
    1125      * data has occurred.
     1122     * Get a widget instance's hash key.
     1123     *
     1124     * Serialize an instance and hash it with the AUTH_KEY; when a JS value is
     1125     * posted back to save, this instance hash key is used to ensure that the
     1126     * serialized_instance was not tampered with, but that it had originated
     1127     * from WordPress and so is sanitized.
    11261128     *
    11271129     * @since 3.9.0
    11281130     * @access protected
    11291131     *
    1130      * @param string $serialized_instance Widget instance.
    1131      * @return string MAC for serialized widget instance.
    1132      */
    1133     protected function get_instance_hash_key( $serialized_instance ) {
    1134         return wp_hash( $serialized_instance );
     1132     * @param array $instance Widget instance.
     1133     * @return string Widget instance's hash key.
     1134     */
     1135    protected function get_instance_hash_key( $instance ) {
     1136        $hash = md5( AUTH_KEY . serialize( $instance ) );
     1137        return $hash;
    11351138    }
    11361139
     
    11601163
    11611164        $decoded = base64_decode( $value['encoded_serialized_instance'], true );
     1165
    11621166        if ( false === $decoded ) {
    11631167            return null;
    11641168        }
    1165 
    1166         if ( $this->get_instance_hash_key( $decoded ) !== $value['instance_hash_key'] ) {
    1167             return null;
    1168         }
    1169 
    11701169        $instance = unserialize( $decoded );
     1170
    11711171        if ( false === $instance ) {
    11721172            return null;
    11731173        }
    1174 
     1174        if ( $this->get_instance_hash_key( $instance ) !== $value['instance_hash_key'] ) {
     1175            return null;
     1176        }
    11751177        return $instance;
    11761178    }
     
    11931195                'title'                         => empty( $value['title'] ) ? '' : $value['title'],
    11941196                'is_widget_customizer_js_value' => true,
    1195                 'instance_hash_key'             => $this->get_instance_hash_key( $serialized ),
     1197                'instance_hash_key'             => $this->get_instance_hash_key( $value ),
    11961198            );
    11971199        }
Note: See TracChangeset for help on using the changeset viewer.