WordPress.org

Make WordPress Core

Changeset 29396


Ignore:
Timestamp:
08/06/2014 06:39:30 AM (7 years ago)
Author:
nacin
Message:

Don't pass around the password reset key.

Merges [29327] and [29381] to the 3.7 branch.

props mdawaffe.
fixes #29060.

Location:
branches/3.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

  • branches/3.7/src/wp-login.php

    r25881 r29396  
    558558case 'resetpass' :
    559559case 'rp' :
    560     $user = check_password_reset_key($_GET['key'], $_GET['login']);
    561 
    562     if ( is_wp_error($user) ) {
    563         if ( $user->get_error_code() === 'expired_key' )
     560    list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
     561    $rp_cookie = 'wp-resetpass-' . COOKIEHASH;
     562    if ( isset( $_GET['key'] ) ) {
     563        $value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) );
     564        setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
     565        wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) );
     566        exit;
     567    }
     568
     569    if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
     570        list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
     571        $user = check_password_reset_key( $rp_key, $rp_login );
     572    } else {
     573        $user = false;
     574    }
     575
     576    if ( ! $user || is_wp_error( $user ) ) {
     577        setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
     578        if ( $user && $user->get_error_code() === 'expired_key' )
    564579            wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
    565580        else
     
    585600    if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
    586601        reset_password($user, $_POST['pass1']);
     602        setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
    587603        login_header( __( 'Password Reset' ), '<p class="message reset-pass">' . __( 'Your password has been reset.' ) . ' <a href="' . esc_url( wp_login_url() ) . '">' . __( 'Log in' ) . '</a></p>' );
    588604        login_footer();
     
    596612
    597613?>
    598 <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( site_url( 'wp-login.php?action=resetpass&key=' . urlencode( $_GET['key'] ) . '&login=' . urlencode( $_GET['login'] ), 'login_post' ) ); ?>" method="post" autocomplete="off">
    599     <input type="hidden" id="user_login" value="<?php echo esc_attr( $_GET['login'] ); ?>" autocomplete="off" />
     614<form name="resetpassform" id="resetpassform" action="<?php echo esc_url( site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
     615    <input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
    600616
    601617    <p>
Note: See TracChangeset for help on using the changeset viewer.