Make WordPress Core

Changeset 30468


Ignore:
Timestamp:
11/20/2014 04:05:10 PM (11 years ago)
Author:
nacin
Message:

Prevent high resource usage when hashing large passwords. props mdawaffe, pento

Merges [30466] to the 3.9 branch.

Location:
branches/3.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.9

  • branches/3.9/src/wp-includes/class-phpass.php

    r26868 r30468  
    215215    function HashPassword($password)
    216216    {
     217        if ( strlen( $password ) > 4096 ) {
     218            return '*';
     219        }
     220
    217221        $random = '';
    218222
     
    250254    function CheckPassword($password, $stored_hash)
    251255    {
     256        if ( strlen( $password ) > 4096 ) {
     257            return false;
     258        }
     259
    252260        $hash = $this->crypt_private($password, $stored_hash);
    253261        if ($hash[0] == '*')
  • branches/3.9/tests/phpunit/tests/auth.php

    r25709 r30468  
    33/**
    44 * @group pluggable
     5 * @group auth
    56 */
    67class Tests_Auth extends WP_UnitTestCase {
     
    9293        $this->assertTrue( wp_check_password( 'pass with vertial tab o_O', wp_hash_password( $password ) ) );
    9394    }
     95
     96    function test_password_length_limit() {
     97        $passwords = array(
     98            str_repeat( 'a', 4095 ), // short
     99            str_repeat( 'a', 4096 ), // limit
     100            str_repeat( 'a', 4097 ), // long
     101        );
     102
     103        $user_id = $this->factory->user->create( array( 'user_login' => 'password-length-test' ) );
     104
     105        wp_set_password( $passwords[1], $user_id );
     106        $user = get_user_by( 'id', $user_id );
     107        // phpass hashed password
     108        $this->assertStringStartsWith( '$P$', $user->data->user_pass );
     109
     110        $user = wp_authenticate( 'password-length-test', $passwords[0] );
     111        // Wrong Password
     112        $this->assertInstanceOf( 'WP_Error', $user );
     113
     114        $user = wp_authenticate( 'password-length-test', $passwords[1] );
     115        $this->assertInstanceOf( 'WP_User', $user );
     116        $this->assertEquals( $user_id, $user->ID );
     117
     118        $user = wp_authenticate( 'password-length-test', $passwords[2] );
     119        // Wrong Password
     120        $this->assertInstanceOf( 'WP_Error', $user );
     121
     122
     123        wp_set_password( $passwords[2], $user_id );
     124        $user = get_user_by( 'id', $user_id );
     125        // Password broken by setting it to be too long.
     126        $this->assertEquals( '*', $user->data->user_pass );
     127
     128        $user = wp_authenticate( 'password-length-test', $passwords[0] );
     129        // Wrong Password
     130        $this->assertInstanceOf( 'WP_Error', $user );
     131
     132        $user = wp_authenticate( 'password-length-test', $passwords[1] );
     133        // Wrong Password
     134        $this->assertInstanceOf( 'WP_Error', $user );
     135
     136        $user = wp_authenticate( 'password-length-test', $passwords[2] );
     137        // Password broken by setting it to be too long.
     138        $this->assertInstanceOf( 'WP_Error', $user );
     139    }
    94140}
Note: See TracChangeset for help on using the changeset viewer.