r81338 MediaWiki - Code Review archive

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

Diff [purge]

Index: branches/REL1_15/phase3/includes/StubObject.php
@@ -154,7 +154,7 @@
155155 }
156156
157157 # Validate $code
158 - if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) || ( $code === 'qqq' ) ) {
 158+ if( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) {
159159 wfDebug( "Invalid user language code\n" );
160160 $code = $wgContLanguageCode;
161161 }
Index: branches/REL1_15/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 {
@@ -179,6 +187,14 @@
180188 return $lang;
181189 }
182190
 191+ /**
 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+
183199 function __construct() {
184200 $this->mConverter = new FakeConverter($this);
185201 // Set the code to the name of the descendant
@@ -2318,6 +2334,13 @@
23192335 }
23202336
23212337 static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
 2338+ // Protect against path traversal
 2339+ if ( !Language::isValidCode( $code )
 2340+ || strcspn( $code, "/\\\000" ) !== strlen( $code ) )
 2341+ {
 2342+ throw new MWException( "Invalid language code \"$code\"" );
 2343+ }
 2344+
23222345 return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
23232346 }
23242347
Index: branches/REL1_15/phase3/RELEASE-NOTES
@@ -10,6 +10,9 @@
1111 bug 24564)
1212 * Fixed $wgLicenseTerms register globals.
1313 * (bug 27093, CVE-2011-0047): Fixed CSS injection vulnerability.
 14+* (bug 27094) Fixed server-side arbitrary script inclusion vulnerability.
 15+ Affects Windows servers only. A malicious file with extension ".php" must
 16+ exist on the server for the exploit to be effective.
1417
1518 == MediaWiki 1.15.5 ==
1619

Past revisions this follows-up on

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

Status & tagging log