Media: Broaden the Document-Isolation-Policy header to all admin pages (backport GB #76662)#11298
Draft
adamsilverstein wants to merge 1 commit into
Draft
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. |
Open
4 tasks
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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