Make WordPress Core

Changeset 62953


Ignore:
Timestamp:
07/31/2026 08:41:49 AM (4 months ago)
Author:
tyxla
Message:

Toolbar: Serve the site icon over HTTPS on SSL admin requests.

wp_get_attachment_url() intentionally limits its scheme correction to the front end, skipping it in the admin and on wp-login.php. Consequently, on a site whose siteurl option is still stored with http:// but which is served over TLS, get_site_icon_url() returned an http:// URL, and browsers blocked the site icon as mixed content in the admin bar and as the admin favicon.

Upgrade the attachment URL to https:// when the current request is served over SSL.

Includes a unit test asserting both the upgrade on an SSL admin request and the absence of a downgrade on a non-SSL one.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12655.

Props hbhalodia, wildworks, mukesh27, tyxla, westonruter, youknowriad, fushar, mirmpro.
Fixes #65696.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r62816 r62953  
    11831183                $attachment_url = wp_get_attachment_image_url( $site_icon_id, $size_data );
    11841184                if ( $attachment_url ) {
    1185                         $url = $attachment_url;
     1185                        $url = is_ssl() ? set_url_scheme( $attachment_url, 'https' ) : $attachment_url;
    11861186                }
    11871187        }
  • trunk/tests/phpunit/tests/general/template.php

    r62521 r62953  
    140140
    141141        /**
     142         * Ensures the site icon URL scheme is upgraded for the current request, but never downgraded.
     143         *
     144         * The site icon is display chrome that also renders in wp-admin and on the
     145         * login screen, where wp_get_attachment_image_url() does not correct the scheme.
     146         *
     147         * On an HTTPS request with an http:// siteurl the icon must still be served
     148         * over HTTPS to avoid a broken, mixed-content image.
     149         *
     150         * @ticket 65696
     151         *
     152         * @group site_icon
     153         *
     154         * @covers ::get_site_icon_url
     155         *
     156         * @requires function imagejpeg
     157         */
     158        public function test_get_site_icon_url_scheme() {
     159                $this->set_site_icon();
     160
     161                set_current_screen( 'dashboard' );
     162                $this->assertTrue( is_admin(), 'Test should run in the admin context.' );
     163                $this->assertFalse( is_ssl(), 'Baseline request should not be detected as SSL.' );
     164                $this->assertStringStartsWith( 'http://', get_site_icon_url(), 'Baseline icon URL should use the HTTP scheme.' );
     165
     166                $_SERVER['HTTPS'] = 'on';
     167                $this->assertTrue( is_ssl(), 'Request should now be detected as SSL.' );
     168                $this->assertStringStartsWith( 'https://', get_site_icon_url(), 'Site icon URL should use the HTTPS scheme on an SSL admin request.' );
     169
     170                add_filter(
     171                        'upload_dir',
     172                        static function ( $uploads ) {
     173                                $uploads['url']     = set_url_scheme( $uploads['url'], 'https' );
     174                                $uploads['baseurl'] = set_url_scheme( $uploads['baseurl'], 'https' );
     175                                return $uploads;
     176                        }
     177                );
     178
     179                unset( $_SERVER['HTTPS'] );
     180                $this->assertFalse( is_ssl(), 'Request should no longer be detected as SSL.' );
     181                $this->assertStringStartsWith( 'https://', get_site_icon_url(), 'Site icon URL should preserve the HTTPS scheme on a non-SSL request.' );
     182        }
     183
     184        /**
    142185         * @group site_icon
    143186         * @covers ::site_icon_url
Note: See TracChangeset for help on using the changeset viewer.