Media: Broaden the Document-Isolation-Policy header to all admin pages (backport GB #76662)#11298
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Send the Document-Isolation-Policy (DIP) header on every admin page via `admin_init` rather than only on the four block-editor screens (`load-post.php`, `load-post-new.php`, `load-site-editor.php`, and `load-widgets.php`). Hooking the narrow set of screens placed the editor in its own browser agent cluster while sibling admin navigations (site editor sub-routes, template and pattern operations) loaded without the header. The agent cluster mismatch broke cross-window communication and SharedArrayBuffer access required for WebAssembly-based client-side media processing in Chromium 137+. The block-editor screen gate is replaced by an `upload_files` capability check, since cross-origin isolation is only needed for users who can upload media. The existing escape hatch for third-party page builders that override the block editor via a custom `action` query parameter is retained. The front-end preview is intentionally out of scope; DIP remains an admin-only concern. See related Gutenberg pull request: WordPress/gutenberg#76662.
543c846 to
7962e83
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
The test asserting that wp_set_up_cross_origin_isolation() returns early for users who cannot upload files never reached the capability check: in the PHPUnit environment the default host is non-secure, so wp_is_client_side_media_processing_enabled() returns false and the function returns at its first guard. Enable client-side media processing explicitly so the current_user_can( 'upload_files' ) gate is exercised.
Summary
Send the
Document-Isolation-Policy(DIP) header on all admin pages (viaadmin_init) instead of only on the four block-editor screens (load-post.php,load-post-new.php,load-site-editor.php,load-widgets.php).wp_set_up_cross_origin_isolation()with anupload_filescapability check.actionquery parameter (see "Page-builder compatibility" below).Why
When the editor sends the DIP header but sibling admin navigations (site editor sub-routes, template and pattern operations) load without it, Chromium 137+ places them in different agent clusters. The mismatch breaks cross-window communication (
window.opener, popup references) and SharedArrayBuffer access required for WebAssembly-based client-side media processing. Broadening the header to every admin page keeps all admin navigations in the same agent cluster.The block-editor screen gate is no longer needed: cross-origin isolation is only relevant for users who can upload media, so an
upload_filescapability check is sufficient and cheaper than resolving the current screen on every admin request.Scope
Page-builder compatibility
The
action !== 'edit'escape hatch is retained. It skips DIP when a third-party builder takes over an admin editor screen via a customactionvalue, because those builders embed a same-origin front-end preview iframe and access it synchronously — which DIP breaks when only the admin frame is isolated.At risk — admin chrome + synchronous same-origin preview iframe:
action=elementor) no longer strictly needs the hatch: as of v4.x it sends the DIP header on both its editor frame and its preview iframe itself (elementor/elementor#35976), so it self-isolates. The hatch is harmless to it.action=in-front-editor) still relies on the hatch and would regress without it — no equivalent fix shipped.vc_action=vc_inline) and Visual Composer standalone (vcv-action=frontend) match the same pattern but trigger on a different query parameter, so theaction-based hatch never covered them.Unaffected — editor chrome served on the front end (admin header never reaches it): Beaver Builder (
?fl_builder), Divi Visual Builder (?et_fb=1), Oxygen (?ct_builder=true), Bricks (?bricks=run), Cornerstone (?cornerstone=1), Avada Live (?fb-edit=1), Thrive Architect (?tve=true), Breakdance (?breakdance=builder), Zion Builder.Unaffected — backend metabox on the standard
action=editscreen (already coexists with DIP): WPBakery backend editor, Divi Classic Builder, SiteOrigin Page Builder, Avada backend builder.Alternate approaches considered
template_redirect). Earlier iterations of this backport added awp_set_up_cross_origin_isolation_for_preview()helper so editor → preview popups stayed in the same agent cluster. Rejected: DIP is kept admin-only; front-end isolation is out of scope and the upstream Gutenberg change dropped this path, leaving no core counterpart. (Removed from this PR.)action !== 'edit'heuristic with editor-replacement detection (e.g.use_block_editor_for_post() === false/ thereplace_editorfilter). This would protect all editor-replacing builders regardless of query parameter — including WPBakery and Visual Composer, which theaction-based check misses. Deferred: larger change that needs the screen/post context restored, and the current heuristic plus builders self-isolating (as Elementor now does) covers the practical cases. Worth a follow-up.load-post.phpetc., the status quo). Rejected: this is the root cause — sibling admin navigations load without DIP and fall into a different agent cluster, which is the bug this PR fixes.Changes
src/wp-includes/default-filters.phpwp_set_up_cross_origin_isolationonadmin_initinstead of the fourload-*screen actions.src/wp-includes/media.phpwp_set_up_cross_origin_isolation()— drop theget_current_screen()block-editor gate; gate oncurrent_user_can( 'upload_files' )instead. The third-party page-builder escape hatch is unchanged.tests/phpunit/tests/media/wpCrossOriginIsolation.phptest_returns_early_when_no_screen()withtest_returns_early_when_user_cannot_upload().Test plan
vendor/bin/phpunit tests/phpunit/tests/media/wpCrossOriginIsolation.php— all tests pass.upload_files, confirm theDocument-Isolation-Policy: isolate-and-credentiallessresponse header is present on/wp-admin/index.php,/wp-admin/site-editor.php,/wp-admin/edit.php, and/wp-admin/post.php?post=…&action=edit.upload_files) and confirm the header is not sent on any admin page.?action=elementor(or similar customaction) and confirm the header is not sent.Related
Trac ticket: https://core.trac.wordpress.org/ticket/65493