Changeset 29221
- Timestamp:
- 07/18/2014 09:12:05 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r28939 r29221 587 587 */ 588 588 function wp_logout() { 589 wp_destroy_current_session(); 589 590 wp_clear_auth_cookie(); 590 591 … … 632 633 $username = $cookie_elements['username']; 633 634 $hmac = $cookie_elements['hmac']; 635 $token = $cookie_elements['token']; 634 636 $expired = $expiration = $cookie_elements['expiration']; 635 637 … … 667 669 $pass_frag = substr($user->user_pass, 8, 4); 668 670 669 $key = wp_hash( $username . $pass_frag . '|' . $expiration, $scheme);670 $hash = hash_hmac( 'md5', $username . '|' . $expiration, $key);671 672 if ( hash_hmac( ' md5', $hmac, $key ) !== hash_hmac( 'md5', $hash, $key ) ) {671 $key = wp_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme ); 672 $hash = hash_hmac( 'sha256', $username . '|' . $expiration . '|' . $token, $key ); 673 674 if ( hash_hmac( 'sha256', $hmac, $key ) !== hash_hmac( 'sha256', $hash, $key ) ) { 673 675 /** 674 676 * Fires if a bad authentication cookie hash is encountered. … … 682 684 } 683 685 684 if ( $expiration < time() ) {// AJAX/POST grace period set above 686 $manager = WP_Session_Tokens::get_instance( $user->ID ); 687 if ( ! $manager->verify_token( $token ) ) { 688 do_action( 'auth_cookie_bad_session_token', $cookie_elements ); 689 return false; 690 } 691 692 // AJAX/POST grace period set above 693 if ( $expiration < time() ) { 685 694 $GLOBALS['login_grace_period'] = 1; 686 695 } … … 709 718 * @param int $expiration Cookie expiration in seconds 710 719 * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in 711 * @return string Authentication cookie contents 712 */ 713 function wp_generate_auth_cookie($user_id, $expiration, $scheme = 'auth') { 720 * @param string $token User's session token to use for this cookie 721 * @return string Authentication cookie contents. Empty string if user does not exist. 722 */ 723 function wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' ) { 714 724 $user = get_userdata($user_id); 725 if ( ! $user ) { 726 return ''; 727 } 728 729 if ( ! $token ) { 730 $manager = WP_Session_Tokens::get_instance( $user_id ); 731 $token = $manager->create_token( $expiration ); 732 } 715 733 716 734 $pass_frag = substr($user->user_pass, 8, 4); 717 735 718 $key = wp_hash( $user->user_login . $pass_frag . '|' . $expiration, $scheme);719 $hash = hash_hmac( 'md5', $user->user_login . '|' . $expiration, $key);720 721 $cookie = $user->user_login . '|' . $expiration . '|' . $ hash;736 $key = wp_hash( $user->user_login . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme ); 737 $hash = hash_hmac( 'sha256', $user->user_login . '|' . $expiration . '|' . $token, $key ); 738 739 $cookie = $user->user_login . '|' . $expiration . '|' . $token . '|' . $hash; 722 740 723 741 /** … … 730 748 * @param int $expiration Authentication cookie expiration in seconds. 731 749 * @param string $scheme Cookie scheme used. Accepts 'auth', 'secure_auth', or 'logged_in'. 732 */ 733 return apply_filters( 'auth_cookie', $cookie, $user_id, $expiration, $scheme ); 750 * @param string $token User's session token used. 751 */ 752 return apply_filters( 'auth_cookie', $cookie, $user_id, $expiration, $scheme, $token ); 734 753 } 735 754 endif; … … 773 792 774 793 $cookie_elements = explode('|', $cookie); 775 if ( count( $cookie_elements) != 3 )794 if ( count( $cookie_elements ) !== 4 ) { 776 795 return false; 777 778 list($username, $expiration, $hmac) = $cookie_elements; 779 780 return compact('username', 'expiration', 'hmac', 'scheme'); 796 } 797 798 list( $username, $expiration, $token, $hmac ) = $cookie_elements; 799 800 return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' ); 781 801 } 782 802 endif; … … 794 814 * @param int $user_id User ID 795 815 * @param bool $remember Whether to remember the user 816 * @param mixed $secure Whether the admin cookies should only be sent over HTTPS. 817 * Default is_ssl(). 796 818 */ 797 819 function wp_set_auth_cookie($user_id, $remember = false, $secure = '') { … … 855 877 } 856 878 857 $auth_cookie = wp_generate_auth_cookie($user_id, $expiration, $scheme); 858 $logged_in_cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in'); 879 $manager = WP_Session_Tokens::get_instance( $user_id ); 880 $token = $manager->create_token( $expiration ); 881 882 $auth_cookie = wp_generate_auth_cookie( $user_id, $expiration, $scheme, $token ); 883 $logged_in_cookie = wp_generate_auth_cookie( $user_id, $expiration, 'logged_in', $token ); 859 884 860 885 /** … … 1683 1708 } 1684 1709 1710 $token = wp_get_session_token(); 1685 1711 $i = wp_nonce_tick(); 1686 1712 1687 1713 // Nonce generated 0-12 hours ago 1688 if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce )1714 if ( $nonce === substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 ) ) { 1689 1715 return 1; 1716 } 1717 1690 1718 // Nonce generated 12-24 hours ago 1691 if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) === $nonce )1719 if ( $nonce === substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ) ) { 1692 1720 return 2; 1721 } 1722 1693 1723 // Invalid nonce 1694 1724 return false; … … 1713 1743 } 1714 1744 1745 $token = wp_get_session_token(); 1715 1746 $i = wp_nonce_tick(); 1716 1747 1717 return substr( wp_hash($i . $action . $uid, 'nonce'), -12, 10);1748 return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 1718 1749 } 1719 1750 endif; -
trunk/src/wp-includes/user.php
r29165 r29221 2174 2174 return $user_id; 2175 2175 } 2176 2177 /** 2178 * Retrieve the current session token from the logged_in cookie. 2179 * 2180 * @since 4.0.0 2181 * 2182 * @return string Token. 2183 */ 2184 function wp_get_session_token() { 2185 $cookie = wp_parse_auth_cookie( '', 'logged_in' ); 2186 return ! empty( $cookie['token'] ) ? $cookie['token'] : ''; 2187 } 2188 2189 /** 2190 * Retrieve a list of sessions for the current user. 2191 * 2192 * @since 4.0.0 2193 * @return array Array of sessions. 2194 */ 2195 function wp_get_all_sessions() { 2196 $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); 2197 return $manager->get_all_sessions(); 2198 } 2199 2200 /** 2201 * Remove the current session token from the database. 2202 * 2203 * @since 4.0.0 2204 */ 2205 function wp_destroy_current_session() { 2206 $token = wp_get_session_token(); 2207 if ( $token ) { 2208 $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); 2209 $manager->destroy_token( $token ); 2210 } 2211 } 2212 2213 /** 2214 * Remove all but the current session token for the current user for the database. 2215 * 2216 * @since 4.0.0 2217 */ 2218 function wp_destroy_other_sessions() { 2219 $token = wp_get_session_token(); 2220 if ( $token ) { 2221 $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); 2222 $manager->destroy_other_tokens( $token ); 2223 } 2224 } 2225 2226 /** 2227 * Remove all session tokens for the current user from the database. 2228 * 2229 * @since 4.0.0 2230 */ 2231 function wp_destroy_all_sessions() { 2232 $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); 2233 $manager->destroy_all_tokens(); 2234 } -
trunk/src/wp-settings.php
r29044 r29221 120 120 require( ABSPATH . WPINC . '/template.php' ); 121 121 require( ABSPATH . WPINC . '/user.php' ); 122 require( ABSPATH . WPINC . '/session.php' ); 122 123 require( ABSPATH . WPINC . '/meta.php' ); 123 124 require( ABSPATH . WPINC . '/general-template.php' );
Note: See TracChangeset
for help on using the changeset viewer.