-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Customizer: Allow arbitrary custom CSS #10667
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
c124eb5
e055156
33f9616
606539e
c938d4c
dd919f1
d29900a
6c6a72b
aad4744
c3ae9a9
4e88745
d296d6c
d8a6f02
67500e0
01b6fb8
0141653
6585099
b0020d8
407d43f
ffd5b45
8268865
9e7e04d
879c5d1
b340650
c5c8507
6932b6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2134,6 +2134,13 @@ function wp_update_custom_css_post( $css, $args = array() ) { | |||||
|
|
||||||
| // Update post if it already exists, otherwise create a new one. | ||||||
| $post = wp_get_custom_css_post( $args['stylesheet'] ); | ||||||
|
|
||||||
| // Remove KSES HTML filters to prevent CSS mangling. | ||||||
| $priority = has_filter( 'content_save_pre', 'wp_filter_post_kses' ); | ||||||
|
Contributor
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. Naming things: verbose but clearer when reading the code.
Suggested change
🔢 Applies elsewhere but you probably could have figured that out. |
||||||
| if ( false !== $priority ) { | ||||||
| remove_filter( 'content_save_pre', 'wp_filter_post_kses', $priority ); | ||||||
| } | ||||||
|
|
||||||
| if ( $post ) { | ||||||
| $post_data['ID'] = $post->ID; | ||||||
| $r = wp_update_post( wp_slash( $post_data ), true ); | ||||||
|
|
@@ -2153,6 +2160,10 @@ function wp_update_custom_css_post( $css, $args = array() ) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| if ( false !== $priority ) { | ||||||
| add_filter( 'content_save_pre', 'wp_filter_post_kses', $priority ); | ||||||
| } | ||||||
|
|
||||||
| if ( is_wp_error( $r ) ) { | ||||||
| return $r; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,6 +268,27 @@ public function test_get_custom_css_post_queries_after_failed_lookup() { | |
| $this->assertSame( get_num_queries(), $queries_before ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensure that dangerous STYLE tag contents do not break HTML output. | ||
| * | ||
| * @ticket 64418 | ||
| */ | ||
| public function test_wp_custom_css_cb_escapes_dangerous_html() { | ||
|
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 could have the |
||
| wp_update_custom_css_post( | ||
| '*::before { content: "</style><script>alert(1)</script>"; }', | ||
| array( | ||
| 'stylesheet' => $this->setting->stylesheet, | ||
| ) | ||
| ); | ||
| $output = get_echo( 'wp_custom_css_cb' ); | ||
| $expected = <<<'HTML' | ||
| <style id="wp-custom-css"> | ||
| *::before { content: "\3c\2fstyle><script>alert(1)</script>"; } | ||
| </style> | ||
| HTML; | ||
| $this->assertEqualHTML( $expected, $output ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that wp_update_custom_css_post() updates the 'custom_css_post_id' theme mod. | ||
| * | ||
|
|
@@ -373,29 +394,4 @@ public function filter_update_custom_css_data( $data, $args ) { | |
| $data['post_title'] = 'Ignored'; | ||
| return $data; | ||
| } | ||
|
|
||
| /** | ||
| * Tests that validation errors are caught appropriately. | ||
| * | ||
| * Note that the $validity \WP_Error object must be reset each time | ||
| * as it picks up the Errors and passes them to the next assertion. | ||
| * | ||
| * @covers WP_Customize_Custom_CSS_Setting::validate | ||
| */ | ||
| public function test_validate() { | ||
|
|
||
| // Empty CSS throws no errors. | ||
| $result = $this->setting->validate( '' ); | ||
| $this->assertTrue( $result ); | ||
|
|
||
| // Basic, valid CSS throws no errors. | ||
| $basic_css = 'body { background: #f00; } h1.site-title { font-size: 36px; } a:hover { text-decoration: none; } input[type="text"] { padding: 1em; }'; | ||
| $result = $this->setting->validate( $basic_css ); | ||
| $this->assertTrue( $result ); | ||
|
|
||
| // Check for markup. | ||
| $unclosed_comment = $basic_css . '</style>'; | ||
| $result = $this->setting->validate( $unclosed_comment ); | ||
| $this->assertArrayHasKey( 'illegal_markup', $result->errors ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.