Make WordPress Core

Changeset 62651


Ignore:
Timestamp:
07/07/2026 03:05:44 AM (4 months ago)
Author:
westonruter
Message:

Login and Registration: Fix signup and activation URL schemes.

When an already-active signup is revisited, wp-activate.php hard-coded the http:// scheme and passed the scheme-less domain and path through esc_url(), which prepended its own http:// and produced a doubled, broken http://http:// link. Build the full URL with the correct scheme from is_ssl() before escaping it.

Additionally, the signup confirmation heading in wp-signup.php now uses a scheme-relative // URL so the link honors the network's HTTPS configuration instead of forcing http.

This also hardens related code in wp-activate.php and wpmu_activate_signup() against type issues surfaced by PHPStan, including normalizing the signup meta to always be an array.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12257.
Follow-up to r12603, r48672, r57625.

Props meet_hasmukh, westonruter.
See #64898.
Fixes #65506.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-activate.php

    r61662 r62651  
    118118get_header( 'wp-activate' );
    119119
     120/** @var WP_Site $blog_details */
    120121$blog_details = get_site();
    121122?>
    … …  
    139140        } else {
    140141                if ( is_wp_error( $result ) && in_array( $result->get_error_code(), $valid_error_codes, true ) ) {
     142                        /** @var object{ signup_id: string, domain: string, path: string, title: string, user_login: string, user_email: string, registered: string, activated: string, active: string, activation_key: string, meta: string|null } $signup */
    141143                        $signup = $result->get_error_data();
    142144                        ?>
    … …  
    154156                                );
    155157                        } else {
     158                                $url = ( is_ssl() ? 'https://' : 'http://' ) . $signup->domain . $blog_details->path;
     159
    156160                                printf(
    157161                                        /* translators: 1: Site URL, 2: Username, 3: User email address, 4: Lost password URL. */
    158162                                        __( 'Your site at %1$s is active. You may now log in to your site using your chosen username of &#8220;%2$s&#8221;. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ),
    159                                         sprintf( '<a href="http://%1$s">%1$s</a>', esc_url( $signup->domain . $blog_details->path ) ),
     163                                        sprintf( '<a href="%1$s">%1$s</a>', esc_url( $url ) ),
    160164                                        esc_html( $signup->user_login ),
    161165                                        esc_html( $signup->user_email ),
    … …  
    172176                        <?php
    173177                } else {
    174                         $url  = isset( $result['blog_id'] ) ? esc_url( get_home_url( (int) $result['blog_id'] ) ) : '';
     178                        $url = isset( $result['blog_id'] ) ? esc_url( get_home_url( (int) $result['blog_id'] ) ) : '';
     179                        /** @var WP_User $user */
    175180                        $user = get_userdata( (int) $result['user_id'] );
    176181                        ?>
  • trunk/src/wp-includes/ms-functions.php

    r62178 r62651  
    11911191 * @param string $key The activation key provided to the user.
    11921192 * @return array|WP_Error An array containing information about the activated user and/or blog.
     1193 * @phpstan-return array{
     1194 *     user_id: int,
     1195 *     password: string,
     1196 *     meta: array<string, mixed>,
     1197 * }|array{
     1198 *     blog_id: int,
     1199 *     user_id: int,
     1200 *     password: string,
     1201 *     title: string,
     1202 *     meta: array<string, mixed>,
     1203 * }|WP_Error
    11931204 */
    11941205function wpmu_activate_signup(
    … …  
    11981209        global $wpdb;
    11991210
     1211        /** @var object{ signup_id: string, domain: string, path: string, title: string, user_login: string, user_email: string, registered: string, activated: string, active: string, activation_key: string, meta: string|null }|null $signup */
    12001212        $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key ) );
    12011213
    … …  
    12121224        }
    12131225
    1214         $meta     = maybe_unserialize( $signup->meta );
     1226        if ( is_string( $signup->meta ) ) {
     1227                /** @var array<string, mixed> $meta */
     1228                $meta = maybe_unserialize( $signup->meta );
     1229        } else {
     1230                $meta = array();
     1231        }
    12151232        $password = wp_generate_password( 12, false );
    12161233
    … …  
    12311248        if ( empty( $signup->domain ) ) {
    12321249                $wpdb->update(
    1233                         $wpdb->signups,
     1250                        (string) $wpdb->signups,
    12341251                        array(
    12351252                                'active'    => 1,
    … …  
    12731290                        $blog_id->add_data( $signup );
    12741291                        $wpdb->update(
    1275                                 $wpdb->signups,
     1292                                (string) $wpdb->signups,
    12761293                                array(
    12771294                                        'active'    => 1,
    … …  
    12851302
    12861303        $wpdb->update(
    1287                 $wpdb->signups,
     1304                (string) $wpdb->signups,
    12881305                array(
    12891306                        'active'    => 1,
  • trunk/src/wp-signup.php

    r61662 r62651  
    866866        <?php
    867867        /* translators: %s: Site address. */
    868         printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" )
     868        printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='//{$domain}{$path}'>{$blog_title}</a>" )
    869869        ?>
    870870        </h2>
Note: See TracChangeset for help on using the changeset viewer.