Fix for 13281: Normalize header names as per RFC 2616
authorAnders Wegge Jakobsen <wegge@users.mediawiki.org>
Fri, 7 Mar 2008 22:12:34 +0000 (22:12 +0000)
committerAnders Wegge Jakobsen <wegge@users.mediawiki.org>
Fri, 7 Mar 2008 22:12:34 +0000 (22:12 +0000)
RELEASE-NOTES
includes/ProxyTools.php

index 8827371..af1c54c 100644 (file)
@@ -75,6 +75,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13273) "Categories:" message at the bottom of the page shouldn't have
   hardcoded colon, use new 'colon-separator' message instead
 * Parse MediaWiki message translations with a correct language setting on preview
+* (bug 13281) Treat X-Forwarde-For, Client-ip and User-Agent headers as
+  case-insensitive names.
 
 === API changes in 1.13 ===
 
index cdaafbe..270edb1 100644 (file)
 function wfGetForwardedFor() {
        if( function_exists( 'apache_request_headers' ) ) {
                // More reliable than $_SERVER due to case and -/_ folding
-               $set = apache_request_headers();
-               $index = 'X-Forwarded-For';
-               $index2 = 'Client-ip';
+               $set = array ();
+               foreach ( apache_request_headers() as $tempName => $tempValue ) {
+                   $set[ strtoupper( $tempName ) ] = $tempValue;
+               }
+               $index = strtoupper ( 'X-Forwarded-For' );
+               $index2 = strtoupper ( 'Client-ip' );
        } else {
                // Subject to spoofing with headers like X_Forwarded_For
                $set = $_SERVER;
                $index = 'HTTP_X_FORWARDED_FOR';
                $index2 = 'CLIENT-IP';
        }
+       
        #Try a couple of headers
        if( isset( $set[$index] ) ) {
                return $set[$index];
@@ -39,8 +43,11 @@ function wfGetForwardedFor() {
 function wfGetAgent() {
        if( function_exists( 'apache_request_headers' ) ) {
                // More reliable than $_SERVER due to case and -/_ folding
-               $set = apache_request_headers();
-               $index = 'User-Agent';
+               $set = array ();
+               foreach ( apache_request_headers() as $tempName => $tempValue ) {
+                   $set[ strtoupper( $tempName ) ] = $tempValue;
+               }
+               $index = strtoupper ( 'User-Agent' );
        } else {
                // Subject to spoofing with headers like X_Forwarded_For
                $set = $_SERVER;