Make WordPress Core


Ignore:
Timestamp:
08/06/2014 05:25:03 AM (11 years ago)
Author:
nacin
Message:

Constant time for wp_verify_nonce().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r29221 r29382  
    672672    $hash = hash_hmac( 'sha256', $username . '|' . $expiration . '|' . $token, $key );
    673673
    674     if ( hash_hmac( 'sha256', $hmac, $key ) !== hash_hmac( 'sha256', $hash, $key ) ) {
     674    if ( ! hash_equals( $hash, $hmac ) ) {
    675675        /**
    676676         * Fires if a bad authentication cookie hash is encountered.
     
    17121712
    17131713    // Nonce generated 0-12 hours ago
    1714     if ( $nonce === substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 ) ) {
     1714    $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 );
     1715    if ( hash_equals( $expected, $nonce ) ) {
    17151716        return 1;
    17161717    }
    17171718
    17181719    // Nonce generated 12-24 hours ago
    1719     if ( $nonce === substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ) ) {
     1720    $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
     1721    if ( hash_equals( $expected, $nonce ) ) {
    17201722        return 2;
    17211723    }
Note: See TracChangeset for help on using the changeset viewer.