diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 0d07356..c4a2cd8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2589,7 +2589,6 @@ function typed_data() { * HMAC and timestamp. */ function drupal_valid_test_ua($new_prefix = NULL) { - global $drupal_hash_salt; static $test_prefix; if (isset($new_prefix)) { @@ -2605,7 +2604,7 @@ function drupal_valid_test_ua($new_prefix = NULL) { // We use the salt from settings.php to make the HMAC key, since // the database is not yet initialized and we can't access any Drupal variables. // The file properties add more entropy not easily accessible to others. - $key = $drupal_hash_salt . filectime(__FILE__) . fileinode(__FILE__); + $key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__); $time_diff = REQUEST_TIME - $time; // Since we are making a local request a 5 second time window is allowed, // and the HMAC must match. @@ -2623,14 +2622,13 @@ function drupal_valid_test_ua($new_prefix = NULL) { * Generates a user agent string with a HMAC and timestamp for simpletest. */ function drupal_generate_test_ua($prefix) { - global $drupal_hash_salt; static $key; if (!isset($key)) { // We use the salt from settings.php to make the HMAC key, since // the database is not yet initialized and we can't access any Drupal variables. // The file properties add more entropy not easily accessible to others. - $key = $drupal_hash_salt . filectime(__FILE__) . fileinode(__FILE__); + $key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__); } // Generate a moderately secure HMAC based on the database credentials. $salt = uniqid('', TRUE); @@ -3142,7 +3140,7 @@ function drupal_classloader($class_loader = NULL) { case 'apc': if (function_exists('apc_store')) { require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php'; - $loader = new ApcUniversalClassLoader('drupal.' . $GLOBALS['drupal_hash_salt']); + $loader = new ApcUniversalClassLoader('drupal.' . drupal_get_hash_salt()); break; } // Fall through to the default loader if APC was not loaded, so that the @@ -3382,6 +3380,19 @@ function drupal_is_cli() { } /** + * Gets a salt useful for hardening against SQL injection. + * + * @return + * A salt based on information in settings.php, not in the database. + */ +function drupal_get_hash_salt() { + global $drupal_hash_salt, $databases; + // If the $drupal_hash_salt variable is empty, a hash of the serialized + // database credentials is used as a fallback salt. + return empty($drupal_hash_salt) ? hash('sha256', serialize($databases)) : $drupal_hash_salt; +} + +/** * Formats text for emphasized display in a placeholder inside a sentence. * * Used automatically by format_string(). diff --git a/core/includes/common.inc b/core/includes/common.inc index 14e4357..6c2038f 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4795,19 +4795,6 @@ function drupal_json_decode($var) { } /** - * Gets a salt useful for hardening against SQL injection. - * - * @return - * A salt based on information in settings.php, not in the database. - */ -function drupal_get_hash_salt() { - global $drupal_hash_salt, $databases; - // If the $drupal_hash_salt variable is empty, a hash of the serialized - // database credentials is used as a fallback salt. - return empty($drupal_hash_salt) ? hash('sha256', serialize($databases)) : $drupal_hash_salt; -} - -/** * Ensures the private key variable used to generate tokens is set. * * @return @@ -4829,8 +4816,10 @@ function drupal_get_private_key() { * * @return string * A 43-character URL-safe token for validation, based on the user session ID, - * the global $drupal_hash_salt variable from settings.php, and the + * the hash salt provided from drupal_get_hash_salt(), and the * 'drupal_private_key' configuration variable. + * + * @see drupal_get_hash_salt() */ function drupal_get_token($value = '') { return drupal_hmac_base64($value, session_id() . drupal_get_private_key() . drupal_get_hash_salt()); diff --git a/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php b/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php index 2952488..c82cfcd 100644 --- a/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php @@ -41,7 +41,7 @@ static function get($name) { else { $configuration = array( 'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage', - 'secret' => $GLOBALS['drupal_hash_salt'], + 'secret' => drupal_get_hash_salt(), ); } $class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage'; diff --git a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php index 9e869ee..0f4139e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php @@ -33,7 +33,7 @@ function setUp() { 'bin' => 'service_container', 'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage', 'directory' => DRUPAL_ROOT . '/' . $this->public_files_directory . '/php', - 'secret' => $GLOBALS['drupal_hash_salt'], + 'secret' => drupal_get_hash_salt(), ); // Use a non-persistent cache to avoid queries to non-existing tables. $conf['cache_classes'] = array('cache' => 'Drupal\Core\Cache\MemoryBackend');