-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Media: Use Document-Isolation-Policy for cross-origin isolation #11098
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
Closed
Closed
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
52839e5
Media: Use Document-Isolation-Policy for COI
adamsilverstein f4bfea0
remove md file
adamsilverstein 064ee21
Disable client-side media processing on non-DIP browsers
adamsilverstein aa34c2d
Add tests for cross-origin isolation functions
adamsilverstein c936dcc
Update for DIP-only approach
adamsilverstein 602018a
Fix header tests to run in separate processes
adamsilverstein 291c608
Add __documentIsolationPolicy JS flag
adamsilverstein 05dcc36
Tests: Fix output buffer test to correctly capture callback-processed…
adamsilverstein 0bdef9d
Remove wp_use_document_isolation_policy filter
adamsilverstein 7ff16b3
Merge branch 'trunk' into backport-75991
adamsilverstein 0f03b4b
Merge branch 'trunk' into backport-75991
adamsilverstein 8f838ff
Merge branch 'trunk' into backport-75991
adamsilverstein d501fb9
Update src/wp-includes/media.php
adamsilverstein 1c61294
Apply suggestions from code review
adamsilverstein fa9c07f
Merge branch 'trunk' into backport-75991
adamsilverstein 7b11b34
Merge branch 'trunk' into backport-75991
adamsilverstein 86107f1
Tests: Rename wpGetChromeMajorVersion test to wpGetChromiumMajorVersion.
adamsilverstein 619cb05
Update src/wp-includes/media.php
adamsilverstein a022152
Media: Remove page builder skip logic from cross-origin isolation.
adamsilverstein 513471f
Update src/wp-includes/media.php
adamsilverstein bfb8a9b
Tests: Remove obsolete page builder skip tests from cross-origin isol…
adamsilverstein 23ee73a
Tests: Merge cross-origin isolation test files into one.
adamsilverstein 41102e0
Merge branch 'trunk' into backport-75991
adamsilverstein acece5a
Merge branch 'trunk' into backport-75991
adamsilverstein 049f357
Merge remote-tracking branch 'origin/trunk' into backport-75991
adamsilverstein 42f9d6d
Add @ticket 64766 annotations to tests
adamsilverstein 7922385
Add comments explaining @runInSeparateProcess usage
adamsilverstein 4cf424e
Refactor Chromium version tests to use dataProvider
adamsilverstein ef0e41c
Fix array double arrow alignment in data provider
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
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,71 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests for the `wp_get_chrome_major_version()` function. | ||
| * | ||
| * @group media | ||
| * @covers ::wp_get_chrome_major_version | ||
| */ | ||
| class Tests_Media_wpGetChromeMajorVersion extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Original HTTP_USER_AGENT value. | ||
| * | ||
| * @var string|null | ||
| */ | ||
| private $original_user_agent; | ||
|
|
||
| public function set_up() { | ||
| parent::set_up(); | ||
| $this->original_user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null; | ||
| } | ||
|
|
||
| public function tear_down() { | ||
| if ( null === $this->original_user_agent ) { | ||
| unset( $_SERVER['HTTP_USER_AGENT'] ); | ||
| } else { | ||
| $_SERVER['HTTP_USER_AGENT'] = $this->original_user_agent; | ||
| } | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| public function test_returns_null_when_no_user_agent() { | ||
| unset( $_SERVER['HTTP_USER_AGENT'] ); | ||
| $this->assertNull( wp_get_chrome_major_version() ); | ||
| } | ||
|
|
||
| public function test_returns_null_for_empty_user_agent() { | ||
| $_SERVER['HTTP_USER_AGENT'] = ''; | ||
| $this->assertNull( wp_get_chrome_major_version() ); | ||
| } | ||
|
|
||
| public function test_returns_null_for_firefox() { | ||
| $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0'; | ||
| $this->assertNull( wp_get_chrome_major_version() ); | ||
| } | ||
|
|
||
| public function test_returns_null_for_safari() { | ||
| $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15'; | ||
| $this->assertNull( wp_get_chrome_major_version() ); | ||
| } | ||
|
|
||
| public function test_returns_version_for_chrome() { | ||
| $_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'; | ||
| $this->assertSame( 137, wp_get_chrome_major_version() ); | ||
| } | ||
|
|
||
| public function test_returns_version_for_edge() { | ||
| $_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 Edg/137.0.0.0'; | ||
| $this->assertSame( 137, wp_get_chrome_major_version() ); | ||
| } | ||
|
|
||
| public function test_returns_version_for_opera() { | ||
| $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 OPR/122.0.0.0'; | ||
| $this->assertSame( 136, wp_get_chrome_major_version() ); | ||
| } | ||
|
|
||
| public function test_returns_version_for_older_chrome() { | ||
| $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36'; | ||
| $this->assertSame( 100, wp_get_chrome_major_version() ); | ||
| } | ||
| } |
|
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. This test file seems to be misnamed because it's about testing the cases where the functionality is not enabled, right? |
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,71 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests for the `wp_set_up_cross_origin_isolation()` function. | ||
| * | ||
| * @group media | ||
| * @covers ::wp_set_up_cross_origin_isolation | ||
| */ | ||
| class Tests_Media_wpSetUpCrossOriginIsolation extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Original $_GET values. | ||
| * | ||
| * @var array | ||
| */ | ||
| private $original_get; | ||
|
|
||
| public function set_up() { | ||
| parent::set_up(); | ||
| $this->original_get = $_GET; | ||
| } | ||
|
|
||
| public function tear_down() { | ||
| $_GET = $this->original_get; | ||
| remove_all_filters( 'wp_client_side_media_processing_enabled' ); | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| public function test_returns_early_when_client_side_processing_disabled() { | ||
| add_filter( 'wp_client_side_media_processing_enabled', '__return_false' ); | ||
|
|
||
| // Should not error or start an output buffer. | ||
| $level_before = ob_get_level(); | ||
| wp_set_up_cross_origin_isolation(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| $this->assertSame( $level_before, $level_after ); | ||
| } | ||
|
|
||
| public function test_returns_early_when_no_screen() { | ||
| // No screen is set, so it should return early. | ||
| $level_before = ob_get_level(); | ||
| wp_set_up_cross_origin_isolation(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| $this->assertSame( $level_before, $level_after ); | ||
| } | ||
|
|
||
| public function test_skips_for_third_party_editor_action() { | ||
|
adamsilverstein marked this conversation as resolved.
Outdated
|
||
| $_GET['action'] = 'third_party_editor'; | ||
|
|
||
| $level_before = ob_get_level(); | ||
| wp_set_up_cross_origin_isolation(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| $this->assertSame( $level_before, $level_after, 'Should skip when action is not "edit".' ); | ||
| } | ||
|
|
||
| public function test_does_not_skip_for_edit_action() { | ||
| $_GET['action'] = 'edit'; | ||
|
|
||
| // Still won't start the buffer because no screen is set, | ||
| // but confirms the action check doesn't block 'edit'. | ||
| $level_before = ob_get_level(); | ||
| wp_set_up_cross_origin_isolation(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| // Returns early at the screen check, not the action check. | ||
| $this->assertSame( $level_before, $level_after ); | ||
| } | ||
| } | ||
103 changes: 103 additions & 0 deletions
103
tests/phpunit/tests/media/wpStartCrossOriginIsolationOutputBuffer.php
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,103 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests for the `wp_start_cross_origin_isolation_output_buffer()` function. | ||
| * | ||
| * @group media | ||
| * @covers ::wp_start_cross_origin_isolation_output_buffer | ||
| */ | ||
| class Tests_Media_wpStartCrossOriginIsolationOutputBuffer extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Original HTTP_USER_AGENT value. | ||
| * | ||
| * @var string|null | ||
| */ | ||
| private $original_user_agent; | ||
|
|
||
| public function set_up() { | ||
| parent::set_up(); | ||
| $this->original_user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null; | ||
| } | ||
|
|
||
| public function tear_down() { | ||
| if ( null === $this->original_user_agent ) { | ||
| unset( $_SERVER['HTTP_USER_AGENT'] ); | ||
| } else { | ||
| $_SERVER['HTTP_USER_AGENT'] = $this->original_user_agent; | ||
| } | ||
|
|
||
| // Clean up any output buffers started during tests. | ||
| while ( ob_get_level() > 1 ) { | ||
| ob_end_clean(); | ||
| } | ||
|
|
||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * @runInSeparateProcess | ||
| * @preserveGlobalState disabled | ||
| */ | ||
| public function test_starts_output_buffer_for_chrome_137() { | ||
| $_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'; | ||
|
|
||
| $level_before = ob_get_level(); | ||
| wp_start_cross_origin_isolation_output_buffer(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| $this->assertSame( $level_before + 1, $level_after, 'Output buffer should be started for Chrome 137.' ); | ||
|
|
||
| ob_end_clean(); | ||
| } | ||
|
|
||
| public function test_does_not_start_output_buffer_for_chrome_136() { | ||
| $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36'; | ||
|
|
||
| $level_before = ob_get_level(); | ||
| wp_start_cross_origin_isolation_output_buffer(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| $this->assertSame( $level_before, $level_after, 'Output buffer should not be started for Chrome < 137.' ); | ||
| } | ||
|
|
||
| public function test_does_not_start_output_buffer_for_firefox() { | ||
| $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0'; | ||
|
|
||
| $level_before = ob_get_level(); | ||
| wp_start_cross_origin_isolation_output_buffer(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| $this->assertSame( $level_before, $level_after, 'Output buffer should not be started for Firefox.' ); | ||
| } | ||
|
|
||
| public function test_does_not_start_output_buffer_for_safari() { | ||
| $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15'; | ||
|
|
||
| $level_before = ob_get_level(); | ||
| wp_start_cross_origin_isolation_output_buffer(); | ||
| $level_after = ob_get_level(); | ||
|
|
||
| $this->assertSame( $level_before, $level_after, 'Output buffer should not be started for Safari.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @runInSeparateProcess | ||
| * @preserveGlobalState disabled | ||
| */ | ||
| public function test_output_buffer_adds_crossorigin_attributes() { | ||
| $_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'; | ||
|
|
||
| // Start an outer buffer to capture the callback-processed output. | ||
| ob_start(); | ||
|
|
||
| wp_start_cross_origin_isolation_output_buffer(); | ||
| echo '<img src="https://external.example.com/image.jpg" />'; | ||
|
|
||
| // Flush the inner buffer to trigger the callback, sending processed output to the outer buffer. | ||
| ob_end_flush(); | ||
| $output = ob_get_clean(); | ||
|
|
||
| $this->assertStringContainsString( 'crossorigin="anonymous"', $output ); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.