Merge "(bug 36938) XSS in uselang parameter"
authorCatrope <roan.kattouw@gmail.com>
Wed, 13 Jun 2012 17:43:19 +0000 (17:43 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 13 Jun 2012 17:43:19 +0000 (17:43 +0000)
includes/SkinTemplate.php
languages/Language.php

index b74f7c5..aee2e83 100644 (file)
@@ -294,7 +294,11 @@ class SkinTemplate extends Skin {
                $tpl->set( 'specialpageattributes', '' ); # obsolete
 
                if ( $userlang !== $wgContLang->getHtmlCode() || $userdir !== $wgContLang->getDir() ) {
-                       $attrs = " lang='$userlang' dir='$userdir'";
+                       $escUserlang = htmlspecialchars( $userlang );
+                       $escUserdir = htmlspecialchars( $userdir );
+                       // Attributes must be in double quotes because htmlspecialchars() doesn't
+                       // escape single quotes
+                       $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
                        $tpl->set( 'userlangattributes', $attrs );
                }
 
index 5bb7762..85b9fab 100644 (file)
@@ -3687,6 +3687,9 @@ class Language {
        /**
         * Get the RFC 3066 code for this language object
         *
+        * NOTE: The return value of this function is NOT HTML-safe and must be escaped with
+        * htmlspecialchars() or similar
+        *
         * @return string
         */
        public function getCode() {
@@ -3696,6 +3699,10 @@ class Language {
        /**
         * Get the code in Bcp47 format which we can use
         * inside of html lang="" tags.
+        *
+        * NOTE: The return value of this function is NOT HTML-safe and must be escaped with
+        * htmlspecialchars() or similar.
+        *
         * @since 1.19
         * @return string
         */