Make WordPress Core


Ignore:
Timestamp:
02/11/2025 11:12:03 AM (2 months ago)
Author:
johnbillion
Message:

Security: Explicitly require the hash PHP extension and add requirement checks during installation and upgrade.

This extension provides the hash() function and support for the SHA-256 algorithm, both of which are required for upcoming security related changes. This extension is almost universally enabled, however it is technically possible to disable it on PHP 7.2 and 7.3, hence the introduction of this requirement and the corresponding requirement checks prior to installing or upgrading WordPress.

Props peterwilsoncc, ayeshrajans, dd32, SergeyBiryukov, johnbillion.

Fixes #60638, #62815, #56017

See #21022

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/install.php

    r59027 r59803  
    233233
    234234/**
    235  * @global string $wp_version             The WordPress version string.
    236  * @global string $required_php_version   The required PHP version string.
    237  * @global string $required_mysql_version The required MySQL version string.
    238  * @global wpdb   $wpdb                   WordPress database abstraction object.
    239  */
    240 global $wp_version, $required_php_version, $required_mysql_version, $wpdb;
     235 * @global string   $wp_version              The WordPress version string.
     236 * @global string   $required_php_version    The required PHP version string.
     237 * @global string[] $required_php_extensions The names of required PHP extensions.
     238 * @global string   $required_mysql_version  The required MySQL version string.
     239 * @global wpdb     $wpdb                    WordPress database abstraction object.
     240 */
     241global $wp_version, $required_php_version, $required_php_extensions, $required_mysql_version, $wpdb;
    241242
    242243$php_version   = PHP_VERSION;
     
    299300}
    300301
     302if ( isset( $required_php_extensions ) && is_array( $required_php_extensions ) ) {
     303    $missing_extensions = array();
     304
     305    foreach ( $required_php_extensions as $extension ) {
     306        if ( extension_loaded( $extension ) ) {
     307            continue;
     308        }
     309
     310        $missing_extensions[] = sprintf(
     311            /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: The PHP extension name needed. */
     312            __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires the %3$s PHP extension.' ),
     313            $version_url,
     314            $wp_version,
     315            $extension
     316        );
     317    }
     318
     319    if ( count( $missing_extensions ) > 0 ) {
     320        display_header();
     321        die( '<h1>' . __( 'Requirements Not Met' ) . '</h1><p>' . implode( '</p><p>', $missing_extensions ) . '</p></body></html>' );
     322    }
     323}
     324
    301325if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
    302326    display_header();
Note: See TracChangeset for help on using the changeset viewer.