r85844 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85843‎ | r85844 | r85845 >
Date:00:55, 12 April 2011
Author:tstarling
Status:ok
Tags:
Comment:
Fix for bug 28235: IE6 looks for the file extension in the query string
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/images/.htaccess (added) (history)
  • /trunk/phase3/img_auth.php (modified) (history)
  • /trunk/phase3/includes/RawPage.php (modified) (history)
  • /trunk/phase3/includes/WebRequest.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/load.php (modified) (history)

Diff [purge]

Index: trunk/phase3/images/.htaccess
@@ -0,0 +1,6 @@
 2+# Protect against bug 28235
 3+<IfModule rewrite_module>
 4+ RewriteEngine On
 5+ RewriteCond %{QUERY_STRING} \.[a-z]{1,4}$ [nocase]
 6+ RewriteRule . - [forbidden]
 7+</IfModule>
Property changes on: trunk/phase3/images/.htaccess
___________________________________________________________________
Added: svn:eol-style
18 + native
Index: trunk/phase3/includes/WebRequest.php
@@ -776,10 +776,27 @@
777777 * but only by prefixing it with the script name and maybe some other stuff,
778778 * the extension is not mangled. So this should be a reasonably portable
779779 * way to perform this security check.
 780+ *
 781+ * Also checks for anything that looks like a file extension at the end of
 782+ * QUERY_STRING, since IE 6 and earlier will use this to get the file type
 783+ * if there was no dot before the question mark (bug 28235).
780784 */
781785 public function isPathInfoBad() {
782786 global $wgScriptExtension;
783787
 788+ if ( isset( $_SERVER['QUERY_STRING'] )
 789+ && preg_match( '/\.[a-z]{1,4}$/i', $_SERVER['QUERY_STRING'] ) )
 790+ {
 791+ // Bug 28235
 792+ // Block only Internet Explorer 6, and requests with missing UA
 793+ // headers that could be IE users behind a privacy proxy.
 794+ if ( !isset( $_SERVER['HTTP_USER_AGENT'] )
 795+ || preg_match( '/; *MSIE 6/', $_SERVER['HTTP_USER_AGENT'] ) )
 796+ {
 797+ return true;
 798+ }
 799+ }
 800+
784801 if ( !isset( $_SERVER['PATH_INFO'] ) ) {
785802 return false;
786803 }
Index: trunk/phase3/includes/RawPage.php
@@ -132,7 +132,7 @@
133133 #
134134 # Just return a 403 Forbidden and get it over with.
135135 wfHttpError( 403, 'Forbidden',
136 - 'Invalid file extension found in PATH_INFO. ' .
 136+ 'Invalid file extension found in PATH_INFO or QUERY_STRING. ' .
137137 'Raw pages must be accessed through the primary script entry point.' );
138138 return;
139139 }
Index: trunk/phase3/img_auth.php
@@ -38,6 +38,13 @@
3939 wfForbidden('img-auth-accessdenied','img-auth-public');
4040 }
4141
 42+// Check for bug 28235: QUERY_STRING overriding the correct extension
 43+if ( isset( $_SERVER['QUERY_STRING'] )
 44+ && preg_match( '/\.[a-z]{1,4}$/i', $_SERVER['QUERY_STRING'] ) )
 45+{
 46+ wfForbidden( 'img-auth-accessdenied', 'img-auth-bad-query-string' );
 47+}
 48+
4249 $matches = WebRequest::getPathInfo();
4350 $path = $matches['title'];
4451 $filename = realpath( $wgUploadDirectory . $path );
Index: trunk/phase3/api.php
@@ -55,8 +55,7 @@
5656 //
5757 if ( $wgRequest->isPathInfoBad() ) {
5858 wfHttpError( 403, 'Forbidden',
59 - 'Invalid file extension found in PATH_INFO. ' .
60 - 'The API must be accessed through the primary script entry point.' );
 59+ 'Invalid file extension found in PATH_INFO or QUERY_STRING.' );
6160 return;
6261 }
6362
Index: trunk/phase3/load.php
@@ -37,11 +37,8 @@
3838 //
3939 if ( $wgRequest->isPathInfoBad() ) {
4040 wfHttpError( 403, 'Forbidden',
41 - 'Invalid file extension found in PATH_INFO. ' .
42 - 'The resource loader must be accessed through the primary script entry point.' );
 41+ 'Invalid file extension found in PATH_INFO or QUERY_STRING.' );
4342 return;
44 - // FIXME: Doesn't this execute the rest of the request anyway?
45 - // Was taken from api.php so I guess it's maybe OK but it doesn't look good.
4643 }
4744
4845 // Respond to resource loading request
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2261,6 +2261,7 @@
22622262 This wiki is configured as a public wiki.
22632263 For optimal security, img_auth.php is disabled.',
22642264 'img-auth-noread' => 'User does not have access to read "$1".',
 2265+'img-auth-bad-query-string' => 'The URL has an invalid query string.',
22652266
22662267 # HTTP errors
22672268 'http-invalid-url' => 'Invalid URL: $1',

Follow-up revisions

RevisionCommit summaryAuthorDate
r85845MFT r85844, fix for bug 28235 (IE6 looks for the file extension in the query ...tstarling01:07, 12 April 2011
r85846MFT r85844, fix for bug 28235 (IE6 looks for the file extension in the query ...tstarling01:15, 12 April 2011
r85848MFT r85844 via REL1_17 85846: IE 6 XSS fixtstarling01:23, 12 April 2011
r85871Add new message key from r85844 to maintenance fileraymond12:05, 12 April 2011
r86027(bug 28507) Fix for r85844: that revision was not actually sufficient to fix ...tstarling07:10, 14 April 2011
r87482* Fix for bug 28534: IE 6 content type detection again...tstarling05:29, 5 May 2011
r89397(bug 28840) If the query string hits bug 28235, redirect to a safer URL inste...tstarling05:32, 3 June 2011
r89558* Added a REQUEST_URI check to the bug 28235 handling....tstarling11:59, 6 June 2011

Status & tagging log