Changeset 29384 for branches/3.9
- Timestamp:
- 08/06/2014 05:41:12 AM (10 years ago)
- Location:
- branches/3.9
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.9
-
branches/3.9/src/wp-includes/compat.php
r18404 r29384 95 95 } 96 96 } 97 98 if ( ! function_exists( 'hash_equals' ) ) : 99 /** 100 * Compare two strings in constant time. 101 * 102 * This function was added in PHP 5.6. 103 * It can leak the length of a string. 104 * 105 * @since 3.9.2 106 * 107 * @param string $a Expected string. 108 * @param string $b Actual string. 109 * @return bool Whether strings are equal. 110 */ 111 function hash_equals( $a, $b ) { 112 $a_length = strlen( $a ); 113 if ( $a_length !== strlen( $b ) ) { 114 return false; 115 } 116 $result = 0; 117 118 // Do not attempt to "optimize" this. 119 for ( $i = 0; $i < $a_length; $i++ ) { 120 $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] ); 121 } 122 123 return $result === 0; 124 } 125 endif; -
branches/3.9/src/wp-includes/pluggable.php
r28053 r29384 648 648 $hash = hash_hmac('md5', $username . '|' . $expiration, $key); 649 649 650 if ( hash_hmac( 'md5', $hmac, $key ) !== hash_hmac( 'md5', $hash, $key) ) {650 if ( ! hash_equals( $hash, $hmac ) ) { 651 651 /** 652 652 * Fires if a bad authentication cookie hash is encountered. … … 1659 1659 1660 1660 // Nonce generated 0-12 hours ago 1661 if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce ) 1661 $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 ); 1662 if ( hash_equals( $expected, $nonce ) ) { 1662 1663 return 1; 1664 } 1665 1663 1666 // Nonce generated 12-24 hours ago 1664 if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) === $nonce ) 1667 $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 1668 if ( hash_equals( $expected, $nonce ) ) { 1665 1669 return 2; 1670 } 1671 1666 1672 // Invalid nonce 1667 1673 return false; … … 2201 2207 endif; 2202 2208 2209 if ( ! function_exists( 'hash_equals' ) ) : 2210 /** 2211 * Compare two strings in constant time. 2212 * 2213 * This function is NOT pluggable. It is in this file (in addition to 2214 * compat.php) to prevent errors if, during an update, pluggable.php 2215 * copies over but compat.php does not. 2216 * 2217 * This function was added in PHP 5.6. 2218 * It can leak the length of a string. 2219 * 2220 * @since 3.9.2 2221 * 2222 * @param string $a Expected string. 2223 * @param string $b Actual string. 2224 * @return bool Whether strings are equal. 2225 */ 2226 function hash_equals( $a, $b ) { 2227 $a_length = strlen( $a ); 2228 if ( $a_length !== strlen( $b ) ) { 2229 return false; 2230 } 2231 $result = 0; 2232 2233 // Do not attempt to "optimize" this. 2234 for ( $i = 0; $i < $a_length; $i++ ) { 2235 $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] ); 2236 } 2237 2238 return $result === 0; 2239 } 2240 endif;
Note: See TracChangeset
for help on using the changeset viewer.