Ticket #19599: 19599.2.diff

File 19599.2.diff, 5.4 KB (added by nacin, 4 months ago)
  • wp-includes/default-constants.php

     
    140140 * @since 3.0.0 
    141141 */ 
    142142function wp_cookie_constants( ) { 
    143         global $wp_default_secret_key; 
    144  
    145143        /** 
    146144         * Used to guarantee unique hash cookies 
    147145         * @since 1.5 
     
    155153        } 
    156154 
    157155        /** 
    158          * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php 
    159          * @since 2.5.0 
    160          */ 
    161         $wp_default_secret_key = 'put your unique phrase here'; 
    162  
    163         /** 
    164156         * @since 2.0.0 
    165157         */ 
    166158        if ( !defined('USER_COOKIE') ) 
  • wp-includes/pluggable.php

     
    13061306 * 
    13071307 * @link https://api.wordpress.org/secret-key/1.1/salt/ Create secrets for wp-config.php 
    13081308 * 
    1309  * @param string $scheme Authentication scheme 
     1309 * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce) 
    13101310 * @return string Salt value 
    13111311 */ 
    1312 function wp_salt($scheme = 'auth') { 
    1313         global $wp_default_secret_key; 
    1314         $secret_key = ''; 
    1315         if ( defined('SECRET_KEY') && ('' != SECRET_KEY) && ( $wp_default_secret_key != SECRET_KEY) ) 
    1316                 $secret_key = SECRET_KEY; 
     1312function wp_salt( $scheme = 'auth' ) { 
     1313        global $wp_secret_key_default; // This is set for localized builds for versions > 3.4.0. 
    13171314 
    1318         if ( 'auth' == $scheme ) { 
    1319                 if ( defined('AUTH_KEY') && ('' != AUTH_KEY) && ( $wp_default_secret_key != AUTH_KEY) ) 
    1320                         $secret_key = AUTH_KEY; 
    1321  
    1322                 if ( defined('AUTH_SALT') && ('' != AUTH_SALT) && ( $wp_default_secret_key != AUTH_SALT) ) { 
    1323                         $salt = AUTH_SALT; 
    1324                 } elseif ( defined('SECRET_SALT') && ('' != SECRET_SALT) && ( $wp_default_secret_key != SECRET_SALT) ) { 
    1325                         $salt = SECRET_SALT; 
    1326                 } else { 
    1327                         $salt = get_site_option('auth_salt'); 
    1328                         if ( empty($salt) ) { 
    1329                                 $salt = wp_generate_password( 64, true, true ); 
    1330                                 update_site_option('auth_salt', $salt); 
     1315        static $duplicated_keys; 
     1316        if ( null === $duplicated_keys ) { 
     1317                $duplicated_keys = array( 'put your unique phrase here' => true ); 
     1318                foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) { 
     1319                        foreach ( array( 'KEY', 'SALT' ) as $second ) { 
     1320                                if ( ! defined( "{$first}_{$second}" ) ) 
     1321                                        continue; 
     1322                                $value = constant( "{$first}_{$second}" ); 
     1323                                $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] ); 
    13311324                        } 
    13321325                } 
    1333         } elseif ( 'secure_auth' == $scheme ) { 
    1334                 if ( defined('SECURE_AUTH_KEY') && ('' != SECURE_AUTH_KEY) && ( $wp_default_secret_key != SECURE_AUTH_KEY) ) 
    1335                         $secret_key = SECURE_AUTH_KEY; 
     1326                if ( ! empty( $wp_secret_key_default ) ) 
     1327                        $duplicated_keys[ $wp_secret_key_default ] = true; 
     1328        } 
    13361329 
    1337                 if ( defined('SECURE_AUTH_SALT') && ('' != SECURE_AUTH_SALT) && ( $wp_default_secret_key != SECURE_AUTH_SALT) ) { 
    1338                         $salt = SECURE_AUTH_SALT; 
    1339                 } else { 
    1340                         $salt = get_site_option('secure_auth_salt'); 
    1341                         if ( empty($salt) ) { 
    1342                                 $salt = wp_generate_password( 64, true, true ); 
    1343                                 update_site_option('secure_auth_salt', $salt); 
    1344                         } 
    1345                 } 
    1346         } elseif ( 'logged_in' == $scheme ) { 
    1347                 if ( defined('LOGGED_IN_KEY') && ('' != LOGGED_IN_KEY) && ( $wp_default_secret_key != LOGGED_IN_KEY) ) 
    1348                         $secret_key = LOGGED_IN_KEY; 
    13491330 
    1350                 if ( defined('LOGGED_IN_SALT') && ('' != LOGGED_IN_SALT) && ( $wp_default_secret_key != LOGGED_IN_SALT) ) { 
    1351                         $salt = LOGGED_IN_SALT; 
    1352                 } else { 
    1353                         $salt = get_site_option('logged_in_salt'); 
    1354                         if ( empty($salt) ) { 
    1355                                 $salt = wp_generate_password( 64, true, true ); 
    1356                                 update_site_option('logged_in_salt', $salt); 
    1357                         } 
    1358                 } 
    1359         } elseif ( 'nonce' == $scheme ) { 
    1360                 if ( defined('NONCE_KEY') && ('' != NONCE_KEY) && ( $wp_default_secret_key != NONCE_KEY) ) 
    1361                         $secret_key = NONCE_KEY; 
     1331        $key = $salt = ''; 
     1332        if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) 
     1333                $key = SECRET_KEY; 
     1334        if ( 'auth' == $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) 
     1335                $salt = SECRET_SALT; 
    13621336 
    1363                 if ( defined('NONCE_SALT') && ('' != NONCE_SALT) && ( $wp_default_secret_key != NONCE_SALT) ) { 
    1364                         $salt = NONCE_SALT; 
    1365                 } else { 
    1366                         $salt = get_site_option('nonce_salt'); 
    1367                         if ( empty($salt) ) { 
    1368                                 $salt = wp_generate_password( 64, true, true ); 
    1369                                 update_site_option('nonce_salt', $salt); 
     1337        if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) ) ) { 
     1338                foreach ( array( 'key', 'salt' ) as $type ) { 
     1339                        $const = strtoupper( "{$scheme}_{$type}" ); 
     1340                        if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) { 
     1341                                $$type = constant( $const ); 
     1342                        } elseif ( ! $$type ) { 
     1343                                $$type = get_site_option( "{$scheme}_{$type}" ); 
     1344                                if ( ! $$type ) { 
     1345                                        $$type = wp_generate_password( 64, true, true ); 
     1346                                        update_site_option( "{$scheme}_{$type}", $$type ); 
     1347                                } 
    13701348                        } 
    13711349                } 
    13721350        } else { 
    1373                 // ensure each auth scheme has its own unique salt 
    1374                 $salt = hash_hmac('md5', $scheme, $secret_key); 
     1351                if ( ! $key ) { 
     1352                        $key = get_site_option( 'secret_key' ); 
     1353                        if ( ! $key ) { 
     1354                                $key = wp_generate_password( 64, true, true ); 
     1355                                update_site_option( 'secret_key', $key ); 
     1356                        } 
     1357                } 
     1358                $salt = hash_hmac( 'md5', $scheme, $key ); 
    13751359        } 
    13761360 
    1377         return apply_filters('salt', $secret_key . $salt, $scheme); 
     1361        return apply_filters('salt', $key . $salt, $scheme); 
    13781362} 
    13791363endif; 
    13801364