-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Media: Use Document-Isolation-Policy for cross-origin isolation on Chromium 137+ #75991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f19689b
Add Document-Isolation-Policy support for cross-origin isolation
adamsilverstein d61fae0
Remove COEP/COOP headers for non-Chrome browsers
adamsilverstein 24178f3
Fix embed breakage on non-DIP browsers
adamsilverstein 79c1cf7
Skip cross-origin isolation for third-party editors
adamsilverstein 731741f
Remove core COEP/COOP hooks in favor of DIP
adamsilverstein 29c3770
Skip COEP/COOP E2E tests on Chrome 137+ where DIP is used
adamsilverstein 71ea0a7
Fix cover focal point E2E test race condition
adamsilverstein 4acfb3a
Remove COEP/COOP and credentialless code
adamsilverstein dd1fb9e
Update tests for DIP-only approach
adamsilverstein a7a1cf2
Update docs and comments for DIP-only
adamsilverstein 8504d84
Add backport changelog for WP 7.0
adamsilverstein 79a2ebf
Rename Chrome references to Chromium
adamsilverstein 7f5dca0
Remove media processing exception from classic block test
adamsilverstein 63ae358
Remove media processing exception from meta box test
adamsilverstein 16a87dc
Remove media processing exception from preview test
adamsilverstein b38ce3b
Remove media processing exception from template mode test
adamsilverstein d763736
Revert "Remove media processing exception from template mode test"
adamsilverstein 6cacd99
Remove media processing exception from plugin and iframed block tests
adamsilverstein 54e1806
Update DIP exception comments in E2E tests
adamsilverstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/11098 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/75991 |
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -219,13 +219,29 @@ function gutenberg_filter_mod_rewrite_rules( string $rules ): string { | |||||
|
|
||||||
| add_filter( 'mod_rewrite_rules', 'gutenberg_filter_mod_rewrite_rules' ); | ||||||
|
|
||||||
| /** | ||||||
| * Returns the major Chromium version from the current request's User-Agent. | ||||||
| * | ||||||
| * Matches all Chromium-based browsers (Chrome, Edge, Opera, Brave). | ||||||
| * | ||||||
| * @return int|null The major Chromium version, or null if not a Chromium browser. | ||||||
| */ | ||||||
| function gutenberg_get_chromium_major_version(): ?int { | ||||||
| if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { | ||||||
| return null; | ||||||
| } | ||||||
| if ( preg_match( '/Chrome\/(\d+)/', $_SERVER['HTTP_USER_AGENT'], $matches ) ) { | ||||||
| return (int) $matches[1]; | ||||||
| } | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Enables cross-origin isolation in the block editor. | ||||||
| * | ||||||
| * Required for enabling SharedArrayBuffer for WebAssembly-based | ||||||
| * media processing in the editor. | ||||||
| * | ||||||
| * @link https://web.dev/coop-coep/ | ||||||
| * media processing in the editor. Uses Document-Isolation-Policy | ||||||
| * on supported browsers (Chromium 137+). | ||||||
| */ | ||||||
| function gutenberg_set_up_cross_origin_isolation() { | ||||||
| // Re-check the filter at action time, since other plugins (loaded after Gutenberg) | ||||||
|
|
@@ -244,6 +260,14 @@ function gutenberg_set_up_cross_origin_isolation() { | |||||
| return; | ||||||
| } | ||||||
|
|
||||||
| // Skip when a third-party page builder overrides the block editor. | ||||||
| // DIP isolates the document into its own agent cluster, | ||||||
| // which blocks same-origin iframe access that these editors rely on. | ||||||
| // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||||||
| if ( isset( $_GET['action'] ) && 'edit' !== $_GET['action'] ) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| $user_id = get_current_user_id(); | ||||||
| if ( ! $user_id ) { | ||||||
| return; | ||||||
|
|
@@ -262,24 +286,44 @@ function gutenberg_set_up_cross_origin_isolation() { | |||||
| add_action( 'load-site-editor.php', 'gutenberg_set_up_cross_origin_isolation' ); | ||||||
| add_action( 'load-widgets.php', 'gutenberg_set_up_cross_origin_isolation' ); | ||||||
|
|
||||||
| // Remove core's COEP/COOP-based cross-origin isolation in favor of | ||||||
| // Gutenberg's DIP-based approach, which also skips third-party editors. | ||||||
| remove_action( 'load-post.php', 'wp_set_up_cross_origin_isolation' ); | ||||||
| remove_action( 'load-post-new.php', 'wp_set_up_cross_origin_isolation' ); | ||||||
| remove_action( 'load-site-editor.php', 'wp_set_up_cross_origin_isolation' ); | ||||||
| remove_action( 'load-widgets.php', 'wp_set_up_cross_origin_isolation' ); | ||||||
|
|
||||||
| /** | ||||||
| * Sends headers for cross-origin isolation. | ||||||
| * Sends the Document-Isolation-Policy header for cross-origin isolation. | ||||||
| * | ||||||
| * Uses an output buffer to add crossorigin="anonymous" where needed. | ||||||
| * | ||||||
| * @link https://web.dev/coop-coep/ | ||||||
| * | ||||||
| * @global bool $is_safari | ||||||
| */ | ||||||
| function gutenberg_start_cross_origin_isolation_output_buffer(): void { | ||||||
| global $is_safari; | ||||||
| $chromium_version = gutenberg_get_chromium_major_version(); | ||||||
|
|
||||||
| /** | ||||||
| * Filters whether to use Document-Isolation-Policy for cross-origin isolation. | ||||||
| * | ||||||
| * Document-Isolation-Policy provides per-document cross-origin isolation | ||||||
| * without affecting other iframes on the page, avoiding breakage of plugins | ||||||
| * whose iframes lose credentials/DOM access. | ||||||
| * | ||||||
| * @since 21.8.0 | ||||||
| * | ||||||
| * @param bool $use_dip Whether DIP is supported and should be used. | ||||||
| */ | ||||||
| $use_dip = apply_filters( | ||||||
| 'gutenberg_use_document_isolation_policy', | ||||||
| null !== $chromium_version && $chromium_version >= 137 | ||||||
| ); | ||||||
|
|
||||||
| $coep = $is_safari ? 'require-corp' : 'credentialless'; | ||||||
| if ( ! $use_dip ) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| ob_start( | ||||||
| function ( string $output ) use ( $coep ): string { | ||||||
| header( 'Cross-Origin-Opener-Policy: same-origin' ); | ||||||
| header( "Cross-Origin-Embedder-Policy: $coep" ); | ||||||
| function ( string $output ): string { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think, based on coding guidelines, closures should be static.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can fix this CS in a follow-up. |
||||||
| header( 'Document-Isolation-Policy: isolate-and-credentialless' ); | ||||||
|
|
||||||
| return gutenberg_add_crossorigin_attributes( $output ); | ||||||
| } | ||||||
|
|
||||||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamsilverstein, this link is broken: https://github.com/nicolo-ribaudo/tc39-proposal-structs/blob/main/test262-filtering/isolation-explainer.md