Changeset 29386
- Timestamp:
- 08/06/2014 05:42:55 AM (10 years ago)
- Location:
- branches/3.8
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.8
- Property svn:mergeinfo changed
/branches/3.9 (added) merged: 29384 /trunk merged: 29382 reverse-merged: 18512
- Property svn:mergeinfo changed
-
branches/3.8/src/wp-includes/compat.php
r18404 r29386 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.8/src/wp-includes/pluggable.php
r28054 r29386 544 544 $hash = hash_hmac('md5', $username . '|' . $expiration, $key); 545 545 546 if ( hash_hmac( 'md5', $hmac, $key ) !== hash_hmac( 'md5', $hash, $key) ) {546 if ( ! hash_equals( $hash, $hmac ) ) { 547 547 do_action('auth_cookie_bad_hash', $cookie_elements); 548 548 return false; … … 1343 1343 1344 1344 // Nonce generated 0-12 hours ago 1345 if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce ) 1345 $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 ); 1346 if ( hash_equals( $expected, $nonce ) ) { 1346 1347 return 1; 1348 } 1349 1347 1350 // Nonce generated 12-24 hours ago 1348 if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) === $nonce ) 1351 $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 1352 if ( hash_equals( $expected, $nonce ) ) { 1349 1353 return 2; 1354 } 1355 1350 1356 // Invalid nonce 1351 1357 return false; … … 1831 1837 endif; 1832 1838 1839 if ( ! function_exists( 'hash_equals' ) ) : 1840 /** 1841 * Compare two strings in constant time. 1842 * 1843 * This function is NOT pluggable. It is in this file (in addition to 1844 * compat.php) to prevent errors if, during an update, pluggable.php 1845 * copies over but compat.php does not. 1846 * 1847 * This function was added in PHP 5.6. 1848 * It can leak the length of a string. 1849 * 1850 * @since 3.9.2 1851 * 1852 * @param string $a Expected string. 1853 * @param string $b Actual string. 1854 * @return bool Whether strings are equal. 1855 */ 1856 function hash_equals( $a, $b ) { 1857 $a_length = strlen( $a ); 1858 if ( $a_length !== strlen( $b ) ) { 1859 return false; 1860 } 1861 $result = 0; 1862 1863 // Do not attempt to "optimize" this. 1864 for ( $i = 0; $i < $a_length; $i++ ) { 1865 $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] ); 1866 } 1867 1868 return $result === 0; 1869 } 1870 endif;
Note: See TracChangeset
for help on using the changeset viewer.