SECURITY: Make SVG @import checking case insensitive
authorTyler Romeo <tylerromeo@gmail.com>
Tue, 30 Dec 2014 20:24:04 +0000 (15:24 -0500)
committercsteipp <csteipp@wikimedia.org>
Wed, 1 Apr 2015 16:54:44 +0000 (09:54 -0700)
@import in embedded CSS is case-insensitive, meaning
an attacker can put "@iMpOrT" and it should still
work.

This uses stripos instead of strpos to make the check
case insensitive.

Bug: T85349
Change-Id: I31db9d81f46460af2d8d3f161ba46c2ab7a170d1

includes/upload/UploadBase.php
tests/phpunit/includes/upload/UploadBaseTest.php

index a79526e..a001fea 100644 (file)
@@ -1524,7 +1524,7 @@ abstract class UploadBase {
        private static function checkCssFragment( $value ) {
 
                # Forbid external stylesheets, for both reliability and to protect viewer's privacy
-               if ( strpos( $value, '@import' ) !== false ) {
+               if ( stripos( $value, '@import' ) !== false ) {
                        return true;
                }
 
index 63ad8c0..dd43af9 100644 (file)
@@ -305,6 +305,12 @@ class UploadBaseTest extends MediaWikiTestCase {
                                true,
                                'SVG with @import in style element and child element (bug 69008#c11)'
                        ),
+                       array(
+                               '<svg xmlns="http://www.w3.org/2000/svg" viewBox="6 3 177 153" xmlns:xlink="http://www.w3.org/1999/xlink"> <style>@imporT "https://fonts.googleapis.com/css?family=Bitter:700&amp;text=WebPlatform.org";</style> <g transform="translate(-.5,-.5)"> <text fill="#474747" x="95" y="150" text-anchor="middle" font-family="Bitter" font-size="20" font-weight="bold">WebPlatform.org</text> </g> </svg>',
+                               true,
+                               true,
+                               'SVG with case-insensitive @import in style element (bug T85349)'
+                       ),
                        array(
                                '<svg xmlns="http://www.w3.org/2000/svg"> <rect width="100" height="100" style="background-image:url(https://www.google.com/images/srpr/logo11w.png)"/> </svg>',
                                true,