r81337 MediaWiki - Code Review archive

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

Diff [purge]

Index: branches/REL1_16/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 = $wgContLanguageCode;
159159 }
Index: branches/REL1_16/phase3/languages/Language.php
@@ -144,6 +144,14 @@
145145 protected static function newFromCode( $code ) {
146146 global $IP;
147147 static $recursionLevel = 0;
 148+
 149+ // Protect against path traversal below
 150+ if ( !Language::isValidCode( $code )
 151+ || strcspn( $code, "/\\\000" ) !== strlen( $code ) )
 152+ {
 153+ throw new MWException( "Invalid language code \"$code\"" );
 154+ }
 155+
148156 if ( $code == 'en' ) {
149157 $class = 'Language';
150158 } else {
@@ -174,6 +182,14 @@
175183 }
176184
177185 /**
 186+ * Returns true if a language code string is of a valid form, whether or
 187+ * not it exists.
 188+ */
 189+ public static function isValidCode( $code ) {
 190+ return (bool)preg_match( '/^[a-z-]+$/', $code );
 191+ }
 192+
 193+ /**
178194 * Get the LocalisationCache instance
179195 */
180196 public static function getLocalisationCache() {
@@ -2462,6 +2478,13 @@
24632479 * @return string $prefix . $mangledCode . $suffix
24642480 */
24652481 static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
 2482+ // Protect against path traversal
 2483+ if ( !Language::isValidCode( $code )
 2484+ || strcspn( $code, "/\\\000" ) !== strlen( $code ) )
 2485+ {
 2486+ throw new MWException( "Invalid language code \"$code\"" );
 2487+ }
 2488+
24662489 return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
24672490 }
24682491
Index: branches/REL1_16/phase3/RELEASE-NOTES
@@ -2,6 +2,8 @@
33
44 == MediaWiki 1.16.2 ==
55
 6+2011-02-01
 7+
68 This is a security and maintenance release of the MediaWiki 1.16 branch.
79
810 === Summary of selected changes in 1.16 ===
@@ -48,6 +50,9 @@
4951 language converter.
5052 * The interface translations were updated.
5153 * (bug 27093, CVE-2011-0047): Fixed CSS injection vulnerability.
 54+* (bug 27094) Fixed server-side arbitrary script inclusion vulnerability.
 55+ Affects Windows servers only. A malicious file with extension ".php" must
 56+ exist on the server for the exploit to be effective.
5257
5358 == Changes since 1.16.0 ==
5459

Follow-up revisions

RevisionCommit summaryAuthorDate
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
r81336(bug 27094) fix path traversal vulnerabilitytstarling22:44, 1 February 2011

Status & tagging log