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/upgrade.php

    r59027 r59803  
    3737
    3838/**
    39  * @global string $wp_version             The WordPress version string.
    40  * @global string $required_php_version   The required PHP version string.
    41  * @global string $required_mysql_version The required MySQL version string.
    42  * @global wpdb   $wpdb                   WordPress database abstraction object.
     39 * @global string   $wp_version              The WordPress version string.
     40 * @global string   $required_php_version    The required PHP version string.
     41 * @global string[] $required_php_extensions The names of required PHP extensions.
     42 * @global string   $required_mysql_version  The required MySQL version string.
     43 * @global wpdb     $wpdb                    WordPress database abstraction object.
    4344 */
    44 global $wp_version, $required_php_version, $required_mysql_version, $wpdb;
     45global $wp_version, $required_php_version, $required_php_extensions, $required_mysql_version, $wpdb;
    4546
    4647$step = (int) $step;
     
    5354} else {
    5455    $mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' );
     56}
     57
     58$missing_extensions = array();
     59
     60if ( isset( $required_php_extensions ) && is_array( $required_php_extensions ) ) {
     61    foreach ( $required_php_extensions as $extension ) {
     62        if ( extension_loaded( $extension ) ) {
     63            continue;
     64        }
     65
     66        $missing_extensions[] = sprintf(
     67            /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: The PHP extension name needed. */
     68            __( 'You cannot upgrade because <a href="%1$s">WordPress %2$s</a> requires the %3$s PHP extension.' ),
     69            $version_url,
     70            $wp_version,
     71            $extension
     72        );
     73    }
    5574}
    5675
     
    127146
    128147    echo '<p>' . $message . '</p>';
    129     ?>
    130     <?php
     148elseif ( count( $missing_extensions ) > 0 ) :
     149    echo '<p>' . implode( '</p><p>', $missing_extensions ) . '</p>';
    131150else :
    132151    switch ( $step ) :
Note: See TracChangeset for help on using the changeset viewer.