Skip to content

Commit a8e8ed6

Browse files
committed
Verify the MAC earlier in WP_Customize_Widgets. props duck_.
git-svn-id: https://develop.svn.wordpress.org/trunk@29377 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e5836da commit a8e8ed6

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

src/wp-includes/class-wp-customize-widgets.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,21 +1150,19 @@ public function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar
11501150
}
11511151

11521152
/**
1153-
* Get a widget instance's hash key.
1153+
* Get MAC for a serialized widget instance string.
11541154
*
1155-
* Serialize an instance and hash it with the AUTH_KEY; when a JS value is
1156-
* posted back to save, this instance hash key is used to ensure that the
1157-
* serialized_instance was not tampered with, but that it had originated
1158-
* from WordPress and so is sanitized.
1155+
* Allows values posted back from JS to be rejected if any tampering of the
1156+
* data has occurred.
11591157
*
11601158
* @since 3.9.0
11611159
* @access protected
11621160
*
1163-
* @param array $instance Widget instance.
1164-
* @return string Widget instance's hash key.
1161+
* @param string $serialized_instance Widget instance.
1162+
* @return string MAC for serialized widget instance.
11651163
*/
1166-
protected function get_instance_hash_key( $instance ) {
1167-
return wp_hash( serialize( $instance ) );
1164+
protected function get_instance_hash_key( $serialized_instance ) {
1165+
return wp_hash( $serialized_instance );
11681166
}
11691167

11701168
/**
@@ -1192,18 +1190,19 @@ public function sanitize_widget_instance( $value ) {
11921190
}
11931191

11941192
$decoded = base64_decode( $value['encoded_serialized_instance'], true );
1195-
11961193
if ( false === $decoded ) {
11971194
return null;
11981195
}
1199-
$instance = unserialize( $decoded );
12001196

1201-
if ( false === $instance ) {
1197+
if ( $this->get_instance_hash_key( $decoded ) !== $value['instance_hash_key'] ) {
12021198
return null;
12031199
}
1204-
if ( $this->get_instance_hash_key( $instance ) !== $value['instance_hash_key'] ) {
1200+
1201+
$instance = unserialize( $decoded );
1202+
if ( false === $instance ) {
12051203
return null;
12061204
}
1205+
12071206
return $instance;
12081207
}
12091208

@@ -1224,7 +1223,7 @@ public function sanitize_widget_js_instance( $value ) {
12241223
'encoded_serialized_instance' => base64_encode( $serialized ),
12251224
'title' => empty( $value['title'] ) ? '' : $value['title'],
12261225
'is_widget_customizer_js_value' => true,
1227-
'instance_hash_key' => $this->get_instance_hash_key( $value ),
1226+
'instance_hash_key' => $this->get_instance_hash_key( $serialized ),
12281227
);
12291228
}
12301229
return $value;

0 commit comments

Comments
 (0)