WordPress.org

Make WordPress Core

Changeset 29395


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

Don't pass around the password reset key.

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

props mdawaffe.
fixes #29060.

Location:
branches/3.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8

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

    r26583 r29395  
    564564case 'resetpass' :
    565565case 'rp' :
    566     $user = check_password_reset_key($_GET['key'], $_GET['login']);
    567 
    568     if ( is_wp_error($user) ) {
    569         if ( $user->get_error_code() === 'expired_key' )
     566    list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
     567    $rp_cookie = 'wp-resetpass-' . COOKIEHASH;
     568    if ( isset( $_GET['key'] ) ) {
     569        $value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) );
     570        setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
     571        wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) );
     572        exit;
     573    }
     574
     575    if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
     576        list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
     577        $user = check_password_reset_key( $rp_key, $rp_login );
     578    } else {
     579        $user = false;
     580    }
     581
     582    if ( ! $user || is_wp_error( $user ) ) {
     583        setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
     584        if ( $user && $user->get_error_code() === 'expired_key' )
    570585            wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
    571586        else
     
    591606    if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
    592607        reset_password($user, $_POST['pass1']);
     608        setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
    593609        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>' );
    594610        login_footer();
     
    602618
    603619?>
    604 <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">
    605     <input type="hidden" id="user_login" value="<?php echo esc_attr( $_GET['login'] ); ?>" autocomplete="off" />
     620<form name="resetpassform" id="resetpassform" action="<?php echo esc_url( site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
     621    <input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
    606622
    607623    <p>
Note: See TracChangeset for help on using the changeset viewer.