ient_data_types = array( 'background', 'background-image', ); if ( empty( $allowed_attr ) ) { return $css; } $css = ''; foreach ( $css_array as $css_item ) { if ( '' === $css_item ) { continue; } $css_item = trim( $css_item ); $css_test_string = $css_item; $found = false; $url_attr = false; $gradient_attr = false; $is_custom_var = false; if ( ! str_contains( $css_item, ':' ) ) { $found = true; } else { $parts = explode( ':', $css_item, 2 ); $css_selector = trim( $parts[0] ); // Allow assigning values to CSS variables. if ( in_array( '--*', $allowed_attr, true ) && preg_match( '/^--[a-zA-Z0-9-_]+$/', $css_selector ) ) { $allowed_attr[] = $css_selector; $is_custom_var = true; } if ( in_array( $css_selector, $allowed_attr, true ) ) { $found = true; $url_attr = in_array( $css_selector, $css_url_data_types, true ); $gradient_attr = in_array( $css_selector, $css_gradient_data_types, true ); } if ( $is_custom_var ) { $css_value = trim( $parts[1] ); $url_attr = str_starts_with( $css_value, 'url(' ); $gradient_attr = str_contains( $css_value, '-gradient(' ); } } if ( $found && $url_attr ) { // Simplified: matches the sequence `url(*)`. preg_match_all( '/url\([^)]+\)/', $parts[1], $url_matches ); foreach ( $url_matches[0] as $url_match ) { // Clean up the URL from each of the matches above. preg_match( '/^url\(\s*([\'\"]?)(.*)(\g1)\s*\)$/', $url_match, $url_pieces ); if ( empty( $url_pieces[2] ) ) { $found = false; break; } $url = trim( $url_pieces[2] ); if ( empty( $url ) || wp_kses_bad_protocol( $url, $allowed_protocols ) !== $url ) { $found = false; break; } else { // Remove the whole `url(*)` bit that was matched above from the CSS. $css_test_string = str_replace( $url_match, '', $css_test_string ); } } } if ( $found && $gradient_attr ) { /* * Match every `*-gradient()` in the value, allowing one level of nested functions * (e.g. rgb(), hsl(), var()). Matching each occurrence, rather than requiring the * whole value to be a single gradient, lets a gradient combine with a url() image. */ preg_match_all( '/(?:repeating-)?(?:linear|radial|conic)-gradient\((?:[^()]|\([^()]*\))*\)/', $css_test_string, $gradient_matches ); foreach ( $gradient_matches[0] as $gradient_match ) { // Remove each `gradient()` bit that was matched above from the CSS. $css_test_string = str_replace( $gradient_match, '', $css_test_string ); } } if ( $found ) { /* * Allow CSS functions like var(), calc(), etc. by removing them from the test string. * Nested functions and parentheses are also removed, so long as the parentheses are balanced. */ $css_test_string = preg_replace( '/\b(?:' // General purpose value functions. . 'var|calc|min|max|minmax|clamp|repeat' // Transform functions. . '|matrix|matrix3d|perspective' . '|rotate|rotate3d|rotateX|rotateY|rotateZ' . '|scale|scale3d|scaleX|scaleY|scaleZ' . '|skew|skewX|skewY' . '|translate|translate3d|translateX|translateY|translateZ' // Basic shape functions, as used by `clip-path`. . '|circle|ellipse|inset|path|polygon|rect|shape|xywh' . ')(\((?:[^()]|(?1))*\))/', '', $css_test_string ); // Bail if the recursive function stripping hit a PCRE error (e.g. stack/backtrack limit). if ( null === $css_test_string ) { continue; } /* * Disallow CSS containing \ ( & } = or comments, except for within url(), var(), calc(), etc. * which were removed from the test string above. */ $allow_css = 0 === preg_match( '%[\\\(&=}]|/\*%', $css_test_string ); /** * Filters the check for unsafe CSS in `safecss_filter_attr`. * * Enables developers to determine whether a section of CSS should be allowed or discarded. * By default, the value will be false if the part contains \ ( & } = or comments. * Return true to allow the CSS part to be included in the output. * * @since 5.5.0 * * @param bool $allow_css Whether the CSS in the test string is considered safe. * @param string $css_test_string The CSS string to test. */ $allow_css = apply_filters( 'safecss_filter_attr_allow_css', $allow_css, $css_test_string ); // Only add the CSS part if it passes the regex check. if ( $allow_css ) { if ( '' !== $css ) { $css .= ';'; } $css .= $css_item; } } } return $css; } /** * Helper function to add global attributes to a tag in the allowed HTML list. * * @since 3.5.0 * @since 5.0.0 Added support for `data-*` wildcard attributes. * @since 6.0.0 Added `dir`, `lang`, and `xml:lang` to global attributes. * @since 6.3.0 Added `aria-controls`, `aria-current`, and `aria-expanded` attributes. * @since 6.4.0 Added `aria-live` and `hidden` attributes. * @since 7.1.0 Added `tabindex` attribute. * * @access private * @ignore * * @param array $value An array of attributes. * @return array The array of attributes with global attributes added. */ function _wp_add_global_attributes( $value ) { $global_attributes = array( 'aria-controls' => true, 'aria-current' => true, 'aria-describedby' => true, 'aria-details' => true, 'aria-expanded' => true, 'aria-hidden' => true, 'aria-label' => true, 'aria-labelledby' => true, 'aria-live' => true, 'class' => true, 'data-*' => true, 'dir' => true, 'hidden' => true, 'id' => true, 'lang' => true, 'style' => true, 'tabindex' => true, 'title' => true, 'role' => true, 'xml:lang' => true, ); if ( true === $value ) { $value = array(); } if ( is_array( $value ) ) { return array_merge( $value, $global_attributes ); } return $value; } /** * Helper function to check if this is a safe PDF URL. * * @since 5.9.0 * @access private * @ignore * * @param string $url The URL to check. * @return bool True if the URL is safe, false otherwise. */ function _wp_kses_allow_pdf_objects( $url ) { // We're not interested in URLs that contain query strings or fragments. if ( str_contains( $url, '?' ) || str_contains( $url, '#' ) ) { return false; } // If it doesn't have a PDF extension, it's not safe. if ( ! str_ends_with( $url, '.pdf' ) ) { return false; } // If the URL host matches the current site's media URL, it's safe. $upload_info = wp_upload_dir( null, false ); $parsed_url = wp_parse_url( $upload_info['url'] ); $upload_host = $parsed_url['host'] ?? ''; $upload_port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : ''; if ( str_starts_with( $url, "http://$upload_host$upload_port/" ) || str_starts_with( $url, "https://$upload_host$upload_port/" ) ) { return true; } return false; } /** * Determines whether KSES restricts the value of any attribute of an element. * * An attribute rule other than `required` and `valueless` restricts the value itself, * for example `values` or `value_callback`. * * @since 7.1.4 * @access private * @ignore * * @param array|bool $allowed_attributes The attributes KSES allows on the element. * @return bool Whether KSES restricts the value of any attribute of the element. */ function _wp_kses_restricts_attribute_values( $allowed_attributes ): bool { if ( ! is_array( $allowed_attributes ) ) { return false; } foreach ( $allowed_attributes as $attribute_rules ) { if ( ! is_array( $attribute_rules ) ) { continue; } foreach ( array_keys( $attribute_rules ) as $rule ) { if ( ! in_array( strtolower( (string) $rule ), array( 'required', 'valueless' ), true ) ) { return true; } } } return false; } /** * Determines whether a directive binds an attribute whose value KSES restricts. * * This only applies to elements for which KSES restricts the value of at least one * attribute. On those elements, a `data-wp-bind` directive is reported unless it binds * an attribute which KSES allows there with any value. KSES calls this to keep such a * directive out of content saved by an author who cannot post unfiltered HTML. * * @since 7.1.4 * @access private * @ignore * * @param string $directive_name The directive attribute name, in lowercase. * @param array|bool $allowed_attributes The attributes KSES allows on the element. * @return bool Whether the directive binds an attribute whose value KSES restricts. */ function _wp_kses_directive_binds_value_restricted_attribute( string $directive_name, $allowed_attributes ): bool { if ( ! str_starts_with( $directive_name, 'data-wp-bind--' ) ) { return false; } if ( ! _wp_kses_restricts_attribute_values( $allowed_attributes ) ) { return false; } /* * Both the whole remainder of the name and the part before a unique ID are checked, so * that the result does not depend on how the unique ID is parsed. A binding with a unique * ID is not applied at all, so removing one changes nothing. */ $bound_attribute = substr( $directive_name, strlen( 'data-wp-bind--' ) ); $bound_attributes = array( $bound_attribute ); $unique_id_index = strpos( $bound_attribute, '---' ); if ( false !== $unique_id_index ) { $bound_attributes[] = substr( $bound_attribute, 0, $unique_id_index ); } foreach ( $bound_attributes as $attribute_name ) { if ( isset( $allowed_attributes[ $attribute_name ] ) ) { $rules = $allowed_attributes[ $attribute_name ]; } elseif ( 1 === preg_match( '/^data-[a-z0-9_-]+$/', $attribute_name ) && isset( $allowed_attributes['data-*'] ) ) { $rules = $allowed_attributes['data-*']; } else { return true; } if ( ! $rules || is_array( $rules ) ) { return true; } } return false; } 503 Service Unavailable

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Additionally, a 503 Service Unavailable error was encountered while trying to use an ErrorDocument to handle the request.