Skip to content

Commit 7c01020

Browse files
committed
Relax style tag contents validation
STYLE tags may contain any raw text up to a closing STYLE tag https://html.spec.whatwg.org/multipage/parsing.html#generic-raw-text-element-parsing-algorithm
1 parent bbc6029 commit 7c01020

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/wp-includes/customize/class-wp-customize-custom-css-setting.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,15 @@ public function validate( $value ) {
163163

164164
$validity = new WP_Error();
165165

166-
if ( preg_match( '#</?\w+#', $css ) ) {
166+
/**
167+
* Check for a closing STYLE tag inside the CSS.
168+
*
169+
* STYLE tags are processed using the "generic raw text parsing algorithm." They contain
170+
* raw text up until a matching closing tag.
171+
*
172+
* @see https://html.spec.whatwg.org/multipage/parsing.html#generic-raw-text-element-parsing-algorithm
173+
*/
174+
if ( preg_match( '#</style[ \\t\\f\\n\\r/>]#', $css ) ) {
167175
$validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) );
168176
}
169177

src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,15 @@ public function get_theme_items( $request ) {
668668
* @return true|WP_Error True if the input was validated, otherwise WP_Error.
669669
*/
670670
protected function validate_custom_css( $css ) {
671-
if ( preg_match( '#</?\w+#', $css ) ) {
671+
/**
672+
* Check for a closing STYLE tag inside the CSS.
673+
*
674+
* STYLE tags are processed using the "generic raw text parsing algorithm." They contain
675+
* raw text up until a matching closing tag.
676+
*
677+
* @see https://html.spec.whatwg.org/multipage/parsing.html#generic-raw-text-element-parsing-algorithm
678+
*/
679+
if ( preg_match( '#</style[ \\t\\f\\n\\r/>]#', $css ) ) {
672680
return new WP_Error(
673681
'rest_custom_css_illegal_markup',
674682
__( 'Markup is not allowed in CSS.' ),

0 commit comments

Comments
 (0)