@@ -90,6 +90,38 @@ function stackable_blocksy_global_color_schemes_compatibility( $styles, $scheme,
9090}
9191
9292if ( ! function_exists ( 'stackable_blocksy_theme_global_styles ' ) ) {
93+ function stackable_sanitize_css_string ( $ css ) {
94+ if ( ! is_string ( $ css ) ) {
95+ return '' ;
96+ }
97+
98+ // sanitize css content
99+ $ css = wp_strip_all_tags ( $ css );
100+ $ css = preg_replace ('/\bexpression\s*\([^)]*\)/i ' , '' , $ css );
101+ $ css = preg_replace ('/\bjavascript\s*:/i ' , '' , $ css );
102+
103+ // clean urls
104+ $ css = preg_replace ('/url\(\s*[ \'"]?\s*https?:\/\/[^ \'")]+\s*[ \'"]?\s*\)/i ' , 'url("") ' , $ css );
105+
106+ // Block unsafe tokens
107+ $ css = preg_replace ('/\b(?:eval|mocha)\b(\s*:|\s*\()/i ' , '/* blocked */$1 ' , $ css );
108+
109+ // Block behavior and vendor-prefixed behavior
110+ $ css = preg_replace ('/(?<![a-zA-Z0-9-])(?:-+[a-zA-Z]*behavior|behavior)\b(\s*:|\s*\()/i ' , '/* blocked */$1 ' , $ css );
111+
112+ // Remove redundant semicolons
113+ $ css = preg_replace ('/;+/ ' , '; ' , $ css );
114+
115+ // Remove empty rule blocks (e.g. ".selector { }")
116+ $ css = preg_replace ('/[^{]+\{\s*\}/m ' , '' , $ css );
117+
118+ // Normalize spacing and line breaks
119+ $ css = preg_replace ('/\s+/ ' , ' ' , $ css );
120+ $ css = trim ($ css );
121+
122+ return $ css ;
123+ }
124+
93125 function stackable_blocksy_theme_global_styles ( $ styles ) {
94126
95127 if ( function_exists ( 'blocksy_manager ' ) ) {
@@ -122,6 +154,8 @@ function( $file ) {
122154 }
123155 }
124156
157+ // sanitize all added styles once
158+ $ styles = stackable_sanitize_css_string ( $ styles );
125159 return $ styles ;
126160 }
127161
0 commit comments