wp-includes/customize/class-wp-customize-custom-css-setting.php:165Validate a received value for being valid CSS.
$valuestringtrue|WP_Error public function validate( $value ) { // Restores the more descriptive, specific name for use within this method. $css = $value; $validity = new WP_Error(); $length = strlen( $css ); for ( $at = strcspn( $css, '<' ); $at < $length; $at += strcspn( $css, '<', ++$at ) ) { $remaining_strlen = $length - $at; /** * Custom CSS text is expected to render inside an HTML STYLE element. * A STYLE closing tag must not appear within the CSS text because it * would close the element prematurely. * * The text must also *not* end with a partial closing tag (e.g., `<`, * `</`, … `</style`) because subsequent styles which are concatenated * could complete it, forming a valid `</style>` tag. * * Example: * * $style_a = 'p { font-weight: bold; </sty'; * $style_b = 'le> gotcha!'; * $combined = "{$style_a}{$style_b}"; * * $style_a = 'p { font-weight: bold; </style'; * $style_b = 'p > b { color: red; }'; * $combined = "{$style_a}\n{$style_b}"; * * Note how in the second example, both of the style contents are benign * when analyzed on their own. The first style was likely the result of * improper truncation, while the second is perfectly sound. It was only * through concatenation that these two styles combined to form content * that would have broken out of the containing STYLE element, thus * corrupting the page and potentially introducing security issues. * * @see https://html.spec.whatwg.org/multipage/parsing.html#rawtext-end-tag-name-state */ $possible_style_close_tag = 0 === substr_compare( $css, '</style', $at, min( 7, $remaining_strlen ), true ); if ( $possible_style_close_tag ) { if ( $remaining_strlen < 8 ) { $validity->add( 'illegal_markup', sprintf( /* translators: %s is the CSS that was provided. */ __( 'The CSS must not end in "%s".' ), esc_html( substr( $css, $at ) ) ) ); break; } if ( 1 === strspn( $css, " \t\f\r\n/>", $at + 7, 1 ) ) { $validity->add( 'illegal_markup', sprintf( /* translators: %s is the CSS that was provided. */ __( 'The CSS must not contain "%s".' ), esc_html( substr( $css, $at, 8 ) ) ) ); break; } } } if ( ! $validity->has_errors() ) { $validity = parent::validate( $css ); } return $validity; }Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/customize/class-wp-customize-custom-css-setting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.