Changeset 44136 for trunk/src/wp-includes/kses.php
- Timestamp:
- 12/14/2018 01:40:50 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43781
- Property svn:mergeinfo changed
-
trunk/src/wp-includes/kses.php
r43984 r44136 1986 1986 $css = str_replace( array( "\n", "\r", "\t" ), '', $css ); 1987 1987 1988 if ( preg_match( '%[\\\\(&=}]|/\*%', $css ) ) { // remove any inline css containing \ ( & } = or comments 1989 return ''; 1990 } 1988 $allowed_protocols = wp_allowed_protocols(); 1991 1989 1992 1990 $css_array = explode( ';', trim( $css ) ); … … 1999 1997 * @since 4.6.0 Added support for `list-style-type`. 2000 1998 * @since 5.0.0 Added support for `text-transform`. 1999 * @since 5.0.0 Added support for `background-image`. 2001 2000 * 2002 2001 * @param string[] $attr Array of allowed CSS attributes. … … 2007 2006 'background', 2008 2007 'background-color', 2008 'background-image', 2009 2009 2010 2010 'border', … … 2077 2077 ); 2078 2078 2079 /* 2080 * CSS attributes that accept URL data types. 2081 * 2082 * This is in accordance to the CSS spec and unrelated to 2083 * the sub-set of supported attributes above. 2084 * 2085 * See: https://developer.mozilla.org/en-US/docs/Web/CSS/url 2086 */ 2087 $css_url_data_types = array( 2088 'background', 2089 'background-image', 2090 2091 'cursor', 2092 2093 'list-style', 2094 'list-style-image', 2095 ); 2096 2079 2097 if ( empty( $allowed_attr ) ) { 2080 2098 return $css; … … 2086 2104 continue; 2087 2105 } 2088 $css_item = trim( $css_item ); 2089 $found = false; 2106 2107 $css_item = trim( $css_item ); 2108 $css_test_string = $css_item; 2109 $found = false; 2110 $url_attr = false; 2111 2090 2112 if ( strpos( $css_item, ':' ) === false ) { 2091 2113 $found = true; 2092 2114 } else { 2093 $parts = explode( ':', $css_item ); 2094 if ( in_array( trim( $parts[0] ), $allowed_attr ) ) { 2095 $found = true; 2115 $parts = explode( ':', $css_item, 2 ); 2116 $css_selector = trim( $parts[0] ); 2117 2118 if ( in_array( $css_selector, $allowed_attr, true ) ) { 2119 $found = true; 2120 $url_attr = in_array( $css_selector, $css_url_data_types, true ); 2096 2121 } 2097 2122 } 2098 if ( $found ) { 2123 2124 if ( $found && $url_attr ) { 2125 // Simplified: matches the sequence `url(*)`. 2126 preg_match_all( '/url\([^)]+\)/', $parts[1], $url_matches ); 2127 2128 foreach ( $url_matches[0] as $url_match ) { 2129 // Clean up the URL from each of the matches above. 2130 preg_match( '/^url\(\s*([\'\"]?)(.*)(\g1)\s*\)$/', $url_match, $url_pieces ); 2131 2132 if ( empty( $url_pieces[2] ) ) { 2133 $found = false; 2134 break; 2135 } 2136 2137 $url = trim( $url_pieces[2] ); 2138 2139 if ( empty( $url ) || $url !== wp_kses_bad_protocol( $url, $allowed_protocols ) ) { 2140 $found = false; 2141 break; 2142 } else { 2143 // Remove the whole `url(*)` bit that was matched above from the CSS. 2144 $css_test_string = str_replace( $url_match, '', $css_test_string ); 2145 } 2146 } 2147 } 2148 2149 // Remove any CSS containing containing \ ( & } = or comments, except for url() useage checked above. 2150 if ( $found && ! preg_match( '%[\\\(&=}]|/\*%', $css_test_string ) ) { 2099 2151 if ( $css != '' ) { 2100 2152 $css .= ';'; 2101 2153 } 2154 2102 2155 $css .= $css_item; 2103 2156 }
Note: See TracChangeset
for help on using the changeset viewer.