-
Notifications
You must be signed in to change notification settings - Fork 882
Boost: stop stripping SVG markup from Critical CSS while keeping style-tag breakout protection #49547
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
Draft
kraftbj
wants to merge
2
commits into
trunk
Choose a base branch
from
claude/boost-audit-prioritize-09rf6a-ccss-svg
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Boost: stop stripping SVG markup from Critical CSS while keeping style-tag breakout protection #49547
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions
4
projects/plugins/boost/changelog/fix-critical-css-svg-stripping
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,4 @@ | ||
| Significance: patch | ||
| Type: fixed | ||
|
|
||
| Critical CSS: stop stripping inline SVG markup and double quotes from valid CSS values while still preventing style-tag breakout. |
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
100 changes: 100 additions & 0 deletions
100
projects/plugins/boost/tests/php/lib/critical-css/Critical_CSS_Storage_Test.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,100 @@ | ||
| <?php | ||
| /** | ||
| * Tests for Critical_CSS_Storage class. | ||
| * | ||
| * @package automattic/jetpack-boost | ||
| */ | ||
|
|
||
| namespace Automattic\Jetpack_Boost\Tests\Lib\Critical_CSS; | ||
|
|
||
| use Automattic\Jetpack_Boost\Lib\Critical_CSS\Critical_CSS_Storage; | ||
| use WorDBless\BaseTestCase; | ||
|
|
||
| /** | ||
| * Class Critical_CSS_Storage_Test | ||
| * | ||
| * Verifies that generated Critical CSS survives a save/load round-trip intact, | ||
| * including double quotes and inline SVG markup in CSS values. | ||
| * | ||
| * @see https://github.com/Automattic/jetpack/issues/42321 | ||
| */ | ||
| class Critical_CSS_Storage_Test extends BaseTestCase { | ||
|
|
||
| /** | ||
| * Set up test environment. | ||
| * | ||
| * WorDBless does not implement the SQL used by WP_Query post_name lookups, | ||
| * so emulate them from the WorDBless in-memory post store. | ||
| */ | ||
| public function set_up() { | ||
| parent::set_up(); | ||
|
|
||
| add_filter( 'posts_pre_query', array( $this, 'emulate_name_query' ), 10, 2 ); | ||
| } | ||
|
|
||
| /** | ||
| * Tear down test environment. | ||
| */ | ||
| public function tear_down() { | ||
| remove_filter( 'posts_pre_query', array( $this, 'emulate_name_query' ), 10 ); | ||
| \WorDBless\Posts::init()->clear_all_posts(); | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * Emulate WP_Query post_name lookups against the WorDBless post store. | ||
| * | ||
| * @param \WP_Post[]|null $posts Posts with which to short-circuit the query, or null. | ||
| * @param \WP_Query $query The running query. | ||
| * @return \WP_Post[]|null | ||
| */ | ||
| public function emulate_name_query( $posts, $query ) { | ||
| $name = $query->get( 'name' ); | ||
| $post_type = $query->get( 'post_type' ); | ||
|
|
||
| if ( ! $name || ! $post_type ) { | ||
| return $posts; | ||
| } | ||
|
|
||
| foreach ( \WorDBless\Posts::init()->posts as $id => $post ) { | ||
| if ( $post->post_name === $name && $post->post_type === $post_type ) { | ||
| return array( get_post( $id ) ); | ||
| } | ||
| } | ||
|
|
||
| return array(); | ||
| } | ||
|
|
||
| /** | ||
| * Test that double quotes and inline SVG markup in CSS values survive a | ||
| * save/load round-trip. | ||
| */ | ||
| public function test_store_css_round_trip_preserves_double_quotes_and_svg() { | ||
| $css = '.test-svg-background { background-image: url("data:image/svg+xml,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 8 8\'><circle cx=\'4\' cy=\'4\' r=\'4\' fill=\'%23f00\'/></svg>"); }'; | ||
|
|
||
| $storage = new Critical_CSS_Storage(); | ||
| $storage->store_css( 'core_front_page', $css ); | ||
|
|
||
| $result = $storage->get_css( array( 'core_front_page' ) ); | ||
|
|
||
| $this->assertIsArray( $result ); | ||
| $this->assertSame( 'core_front_page', $result['key'] ); | ||
| $this->assertSame( $css, $result['css'] ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that updating an existing entry does not corrupt double quotes. | ||
| */ | ||
| public function test_store_css_update_preserves_double_quotes() { | ||
| $storage = new Critical_CSS_Storage(); | ||
| $storage->store_css( 'core_posts_page', '.a { content: "first"; }' ); | ||
|
|
||
| $css = '.quote::before { content: "\201C"; font-family: "Times New Roman", serif; }'; | ||
| $storage->store_css( 'core_posts_page', $css ); | ||
|
|
||
| $result = $storage->get_css( array( 'core_posts_page' ) ); | ||
|
|
||
| $this->assertIsArray( $result ); | ||
| $this->assertSame( $css, $result['css'] ); | ||
| } | ||
| } |
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.
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.