-
Notifications
You must be signed in to change notification settings - Fork 79
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
Jetpack Tweaks: Decode child selectors >
in Custom CSS
#746
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
64 changes: 64 additions & 0 deletions
64
public_html/wp-content/mu-plugins/tests/test-jetpack-css-sanitization.php
This file contains 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,64 @@ | ||
<?php | ||
|
||
namespace WordCamp\Tests; | ||
|
||
use WP_UnitTestCase; | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
/** | ||
* Class Test_Jetpack_CSS_Sanitization | ||
* | ||
* @group mu-plugins | ||
* @group jetpack-tweaks | ||
* @group jetpack-css | ||
* | ||
* @package WordCamp\Tests | ||
*/ | ||
class Test_Jetpack_CSS_Sanitization extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test that no selector characters are encoded. | ||
*/ | ||
public function test_selectors_not_encoded() { | ||
$input = <<<CSS | ||
.class > p, | ||
p ~ span, | ||
h2 + p, | ||
col || td, | ||
.pseudo:visited, | ||
.pseudo::before, | ||
[title], | ||
a[href="https://example.org"], | ||
a[title*='an example'], | ||
span[data-emoji~=🐈⬛] | ||
span[attr$="한글"] { | ||
color: lightcoral; | ||
} | ||
CSS; | ||
|
||
$post = wp_update_custom_css_post( $input ); | ||
$this->assertNotWPError( $post ); | ||
|
||
$output = wp_get_custom_css(); | ||
$this->assertEquals( $input, $output ); | ||
} | ||
|
||
/** | ||
* Test that HTML code is correcly stripped. | ||
*/ | ||
public function test_html_not_allowed() { | ||
$input = <<<CSS | ||
/* HTML-ish code should be stripped */ | ||
<class> p { | ||
color: lightcoral; | ||
} | ||
CSS; | ||
|
||
$post = wp_update_custom_css_post( $input ); | ||
$this->assertNotWPError( $post ); | ||
|
||
$output = wp_get_custom_css(); | ||
$this->assertNotEquals( $input, $output ); | ||
} | ||
} |
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.
Are there any other characters this could happen to? Would it make sense to run something like
html_entity_decode()
here instead of a simple string replace?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.
I was hesitant to do that at first because I'm not totally sure why it's encoded, if there would be a security implication to decoding everything. Looking at the different selectors available, no others are encoded, but it would be possible to add anything to an attribute selector, which could get encoded (like
a[href*='a=1&b=2]
, would becomea[href*='a=1&b=2]
). I'm not sure if supporting that edge case is worth any security issue (but… maybe there is no issue here?)I updated the test to check against almost all the selectors available.
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.
I'm going to merge this as-is, if other selectors become a problem we can make the switch then.