Breaking out disallowed CSS into a global variable
authorDanielRenfro <bluecurio@gmail.com>
Sat, 5 Jul 2014 03:29:11 +0000 (23:29 -0400)
committerDanielRenfro <bluecurio@gmail.com>
Tue, 8 Jul 2014 01:28:53 +0000 (21:28 -0400)
Bug: 11106
Change-Id: Iac6e9a3b1d0265dbd159509dd8938bddeb6f3bba

includes/DefaultSettings.php
includes/Sanitizer.php

index 11196ae..70978f1 100644 (file)
@@ -2981,6 +2981,20 @@ $wgUseSiteJs = true;
  */
 $wgUseSiteCss = true;
 
+/**
+ * CSS that is disallowed by the sanitizer, as a regular expression.
+ */
+$wgDisallowedCss = '! expression
+       | filter\s*:
+       | accelerator\s*:
+       | -o-link\s*:
+       | -o-link-source\s*:
+       | -o-replace\s*:
+       | url\s*\(
+       | image\s*\(
+       | image-set\s*\(
+!ix';
+
 /**
  * Break out of framesets. This can be used to prevent clickjacking attacks,
  * or to prevent external sites from framing your site with ads.
index 6a568c2..75812f2 100644 (file)
@@ -849,6 +849,8 @@ class Sanitizer {
         * @return string
         */
        static function checkCss( $value ) {
+               global $wgDisallowedCss;
+
                // Decode character references like &#123;
                $value = Sanitizer::decodeCharReferences( $value );
 
@@ -937,18 +939,12 @@ class Sanitizer {
                // Reject problematic keywords and control characters
                if ( preg_match( '/[\000-\010\013\016-\037\177]/', $value ) ) {
                        return '/* invalid control char */';
-               } elseif ( preg_match(
-                       '! expression
-                               | filter\s*:
-                               | accelerator\s*:
-                               | -o-link\s*:
-                               | -o-link-source\s*:
-                               | -o-replace\s*:
-                               | url\s*\(
-                               | image\s*\(
-                               | image-set\s*\(
-                       !ix', $value ) ) {
-                       return '/* insecure input */';
+               } else {
+                       if ( $wgDisallowedCss ) {
+                               if ( preg_match( $wgDisallowedCss, $value ) ) {
+                                       return '/* insecure input */';
+                               }
+                       }
                }
                return $value;
        }