Changeset 29388
- Timestamp:
- 08/06/2014 05:44:39 AM (10 years ago)
- Location:
- branches/3.7
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.7
- Property svn:mergeinfo changed
/branches/3.9 (added) merged: 29384 /trunk merged: 29382
- Property svn:mergeinfo changed
-
branches/3.7/src/wp-includes/compat.php
r18404 r29388 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.7/src/wp-includes/pluggable.php
r28055 r29388 547 547 $hash = hash_hmac('md5', $username . '|' . $expiration, $key); 548 548 549 if ( hash_hmac( 'md5', $hmac, $key ) !== hash_hmac( 'md5', $hash, $key) ) {549 if ( ! hash_equals( $hash, $hmac ) ) { 550 550 do_action('auth_cookie_bad_hash', $cookie_elements); 551 551 return false; … … 1298 1298 1299 1299 // Nonce generated 0-12 hours ago 1300 if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce ) 1300 $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 ); 1301 if ( hash_equals( $expected, $nonce ) ) { 1301 1302 return 1; 1303 } 1304 1302 1305 // Nonce generated 12-24 hours ago 1303 if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) === $nonce ) 1306 $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 1307 if ( hash_equals( $expected, $nonce ) ) { 1304 1308 return 2; 1309 } 1310 1305 1311 // Invalid nonce 1306 1312 return false; … … 1785 1791 endif; 1786 1792 1793 if ( ! function_exists( 'hash_equals' ) ) : 1794 /** 1795 * Compare two strings in constant time. 1796 * 1797 * This function is NOT pluggable. It is in this file (in addition to 1798 * compat.php) to prevent errors if, during an update, pluggable.php 1799 * copies over but compat.php does not. 1800 * 1801 * This function was added in PHP 5.6. 1802 * It can leak the length of a string. 1803 * 1804 * @since 3.9.2 1805 * 1806 * @param string $a Expected string. 1807 * @param string $b Actual string. 1808 * @return bool Whether strings are equal. 1809 */ 1810 function hash_equals( $a, $b ) { 1811 $a_length = strlen( $a ); 1812 if ( $a_length !== strlen( $b ) ) { 1813 return false; 1814 } 1815 $result = 0; 1816 1817 // Do not attempt to "optimize" this. 1818 for ( $i = 0; $i < $a_length; $i++ ) { 1819 $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] ); 1820 } 1821 1822 return $result === 0; 1823 } 1824 endif;
Note: See TracChangeset
for help on using the changeset viewer.