Make WordPress Core

Changeset 65532


Ignore:
Timestamp:
11/16/2026 05:43:33 PM (25 hours ago)
Author:
adamsilverstein
Message:

Media: Stop enabling client-side uploads on plugin-isolated screens.

Fix an issue where a plugin screen that sends its own Document-Isolation-Policy header, such as the Elementor editor, got the client-side upload pipeline in every media frame without asking for it. wp_is_cross_origin_isolated_request() treated any queued Document-Isolation-Policy header as a sign the screen was set up for the pipeline, so it could not tell core's isolation apart from a plugin's.

The function now returns true only when wp_send_document_isolation_policy_header() has sent the header. Media frames on a screen a plugin isolates itself upload through plupload again, as they did in 7.1. To opt a screen into the pipeline, call wp_send_document_isolation_policy_header() before wp_enqueue_media() runs.

The Gutenberg plugin sends the header itself on the editor screens, so its media modal uses classic uploads until a site updates to a release that includes ​https://github.com/WordPress/gutenberg/pull/86542. Uploads made in the block editor itself are unaffected.

Follow-up to [64588].

Props andrewserong.
Fixes #66490.

Location:
trunk
Files:
4 edited

Legend:

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

    r65410 r65532  
    68916891 * becomes cross-origin isolated, the script would no-op, and the whole
    68926892 * wp-upload-media dependency chain would be loaded for nothing. The same
    6893  * goes for a screen wp_set_up_cross_origin_isolation() did not isolate,
    6894  * such as the Customizer or the Site Icon picker: the media frame loads
    6895  * there too, but its uploads stay on the classic path.
     6893 * goes for a screen wp_send_document_isolation_policy_header() did not
     6894 * isolate, such as the Customizer or the Site Icon picker: the media frame
     6895 * loads there too, but its uploads stay on the classic path.
    68966896 *
    68976897 * The screen script self-guards at runtime too: when the browser turns out
    … …  
    69516951 * Media Library grid and the media modal the block editor, the site editor
    69526952 * and the block widgets screen open. wp_enqueue_media() calls this on any
    6953  * screen that was cross-origin isolated, so it rarely needs calling directly.
     6953 * screen wp_send_document_isolation_policy_header() isolated, so it rarely
     6954 * needs calling directly.
    69546955 *
    69556956 * @since 7.2.0
    … …  
    69786979 * and break any resource served without `Access-Control-Allow-Origin`.
    69796980 *
     6981 * Sending the header also opts the screen's media frames into client-side
     6982 * uploads, so call this before wp_enqueue_media() runs.
     6983 *
    69806984 * @since 7.2.0
    69816985 *
    … …  
    70027006 * Whether the current request has been set up for cross-origin isolation.
    70037007 *
    7004  * True once wp_set_up_cross_origin_isolation() has sent the
     7008 * True once wp_send_document_isolation_policy_header() has sent the
    70057009 * Document-Isolation-Policy header for the screen being rendered, which is
    70067010 * what lets scripts that need a cross-origin isolated page, such as the
    70077011 * client-side media upload integration, decide whether to load at all.
    70087012 *
    7009  * A plugin can isolate a screen on its own by sending the header directly,
    7010  * as the Gutenberg plugin does on the block editor screens, so a header
    7011  * already queued for the response counts too.
     7013 * A header a plugin sends itself does not count, since the plugin may
     7014 * isolate its screen for reasons of its own. To run the client-side
     7015 * pipeline on a screen core does not isolate, call
     7016 * wp_send_document_isolation_policy_header() before wp_enqueue_media().
    70127017 *
    70137018 * @since 7.2.0
    … …  
    70207025        global $_wp_cross_origin_isolated;
    70217026
    7022         if ( true === $_wp_cross_origin_isolated ) {
    7023                 return true;
    7024         }
    7025 
    7026         return array_any(
    7027                 headers_list(),
    7028                 fn( $header ) => 0 === stripos( $header, 'Document-Isolation-Policy:' )
    7029         );
    7030 }
    7031 
     7027        return true === $_wp_cross_origin_isolated;
     7028}
     7029
  • trunk/tests/phpunit/tests/media/wpCrossOriginIsolation.php

    r65007 r65532  
    77 * @covers ::wp_set_up_cross_origin_isolation
    88 * @covers ::wp_send_document_isolation_policy_header
     9 * @covers ::wp_is_cross_origin_isolated_request
    910 * @covers ::wp_is_client_side_media_processing_enabled
    1011 */
    … …  
    8990
    9091                $GLOBALS['current_screen'] = null;
     92                unset( $GLOBALS['_wp_cross_origin_isolated'] );
    9193
    9294                remove_all_filters( 'wp_client_side_media_processing_enabled' );
    … …  
    120122
    121123                $this->assertTrue( wp_send_document_isolation_policy_header(), 'The Document-Isolation-Policy header should be sent for Chrome 137.' );
     124        }
     125
     126        /**
     127         * @ticket 66490
     128         *
     129         * @runInSeparateProcess
     130         * @preserveGlobalState disabled
     131         */
     132        public function test_sending_header_marks_request_isolated(): void {
     133                $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36';
     134
     135                $this->assertFalse( wp_is_cross_origin_isolated_request(), 'The request should not be isolated before the header is sent.' );
     136
     137                wp_send_document_isolation_policy_header();
     138
     139                $this->assertTrue( wp_is_cross_origin_isolated_request(), 'The request should be isolated once core sends the header.' );
     140        }
     141
     142        /**
     143         * @ticket 66490
     144         */
     145        public function test_request_not_isolated_when_header_not_sent(): void {
     146                $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0';
     147
     148                $this->assertFalse( wp_send_document_isolation_policy_header() );
     149                $this->assertFalse( wp_is_cross_origin_isolated_request(), 'The request should not be isolated when the header was not sent.' );
    122150        }
    123151
  • trunk/tests/phpunit/tests/media/wpEnqueueMediaFrameUpload.php

    r64588 r65532  
    5757                $wp_scripts                = new WP_Scripts();
    5858
    59                 // The screen was cross-origin isolated, as wp_set_up_cross_origin_isolation() records.
     59                // The screen was cross-origin isolated, as wp_send_document_isolation_policy_header() records.
    6060                $GLOBALS['_wp_cross_origin_isolated'] = true;
    6161        }
    … …  
    9292
    9393        /**
    94          * A screen wp_set_up_cross_origin_isolation() did not isolate cannot run
    95          * the pipeline, so the media frame there keeps its classic uploads and
    96          * does not download the pipeline bundles.
     94         * A screen wp_send_document_isolation_policy_header() did not isolate
     95         * cannot run the pipeline, so the media frame there keeps its classic
     96         * uploads and does not download the pipeline bundles.
    9797         *
    9898         * @ticket 65661
  • trunk/tests/phpunit/tests/media/wpEnqueueMediaNewUpload.php

    r64588 r65532  
    5555                $wp_scripts                = new WP_Scripts();
    5656
    57                 // The screen was cross-origin isolated, as wp_set_up_cross_origin_isolation() records.
     57                // The screen was cross-origin isolated, as wp_send_document_isolation_policy_header() records.
    5858                $GLOBALS['_wp_cross_origin_isolated'] = true;
    5959        }
Note: See TracChangeset for help on using the changeset viewer.