r12484 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12483‎ | r12484 | r12485 >
Date:21:44, 7 January 2006
Author:vibber
Status:old
Tags:
Comment:
* Protect against spoofing of X-Forwarded-For header
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/ProxyTools.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProxyTools.php
@@ -6,6 +6,23 @@
77 * @package MediaWiki
88 */
99
 10+function wfGetForwardedFor() {
 11+ if( function_exists( 'apache_request_headers' ) ) {
 12+ // More reliable than $_SERVER due to case and -/_ folding
 13+ $set = apache_request_headers();
 14+ $index = 'X-Forwarded-For';
 15+ } else {
 16+ // Subject to spoofing with headers like X_Forwarded_For
 17+ $set = $_SERVER;
 18+ $index = 'HTTP_X_FORWARDED_FOR';
 19+ }
 20+ if( isset( $set[$index] ) ) {
 21+ return $set[$index];
 22+ } else {
 23+ return null;
 24+ }
 25+}
 26+
1027 /** Work out the IP address based on various globals */
1128 function wfGetIP() {
1229 global $wgSquidServers, $wgSquidServersNoPurge, $wgIP;
@@ -30,8 +47,9 @@
3148 $trustedProxies = array_flip( array_merge( $wgSquidServers, $wgSquidServersNoPurge ) );
3249 if ( count( $trustedProxies ) ) {
3350 # Append XFF on to $ipchain
34 - if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
35 - $xff = array_map( 'trim', explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
 51+ $forwardedFor = wfGetForwardedFor();
 52+ if ( isset( $forwardedFor ) ) {
 53+ $xff = array_map( 'trim', explode( ',', $forwardedFor ) );
3654 $xff = array_reverse( $xff );
3755 $ipchain = array_merge( $ipchain, $xff );
3856 }
Index: trunk/phase3/RELEASE-NOTES
@@ -412,6 +412,7 @@
413413 http://en.wikipedia.org/wiki/Windows_Metafile_vulnerability
414414 * (bug 4507) Adjust FULLPAGENAMEE escaping to standard form
415415 * Blocked users can no longer roll back, change the protection of, or delete/undelete pages
 416+* Protect against spoofing of X-Forwarded-For header
416417
417418
418419 === Caveats ===

Status & tagging log