r81336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81335‎ | r81336 | r81337 >
Date:22:44, 1 February 2011
Author:tstarling
Status:ok
Tags:
Comment:
(bug 27094) fix path traversal vulnerability
Modified paths:
  • /branches/REL1_17/phase3/includes/StubObject.php (modified) (history)
  • /branches/REL1_17/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/StubObject.php
@@ -152,7 +152,7 @@
153153 $code = strtolower( $code );
154154
155155 # Validate $code
156 - if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) || ( $code === 'qqq' ) ) {
 156+ if( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) {
157157 wfDebug( "Invalid user language code\n" );
158158 $code = $wgLanguageCode;
159159 }
Index: branches/REL1_17/phase3/languages/Language.php
@@ -150,6 +150,14 @@
151151 protected static function newFromCode( $code ) {
152152 global $IP;
153153 static $recursionLevel = 0;
 154+
 155+ // Protect against path traversal below
 156+ if ( !Language::isValidCode( $code )
 157+ || strcspn( $code, "/\\\000" ) !== strlen( $code ) )
 158+ {
 159+ throw new MWException( "Invalid language code \"$code\"" );
 160+ }
 161+
154162 if ( $code == 'en' ) {
155163 $class = 'Language';
156164 } else {
@@ -180,6 +188,14 @@
181189 }
182190
183191 /**
 192+ * Returns true if a language code string is of a valid form, whether or
 193+ * not it exists.
 194+ */
 195+ public static function isValidCode( $code ) {
 196+ return (bool)preg_match( '/^[a-z-]+$/', $code );
 197+ }
 198+
 199+ /**
184200 * Get the LocalisationCache instance
185201 */
186202 public static function getLocalisationCache() {
@@ -2789,6 +2805,13 @@
27902806 * @return string $prefix . $mangledCode . $suffix
27912807 */
27922808 static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
 2809+ // Protect against path traversal
 2810+ if ( !Language::isValidCode( $code )
 2811+ || strcspn( $code, "/\\\000" ) !== strlen( $code ) )
 2812+ {
 2813+ throw new MWException( "Invalid language code \"$code\"" );
 2814+ }
 2815+
27932816 return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
27942817 }
27952818

Follow-up revisions

RevisionCommit summaryAuthorDate
r81337(bug 27094) fix path traversal vulnerabilitytstarling22:44, 1 February 2011
r81338(bug 27094) fix path traversal vulnerabilitytstarling22:44, 1 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r81335(bug 27094) fix path traversal vulnerabilitytstarling22:43, 1 February 2011

Status & tagging log