Last modified: 2013-04-22 16:14:45 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T28585, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 26585 - ProxyTools "wfGetIP()" cannot handle CSV values of $_SERVER['REMOTE_ADDR']
ProxyTools "wfGetIP()" cannot handle CSV values of $_SERVER['REMOTE_ADDR']
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.16.x
All All
: Normal major (vote)
: ---
Assigned To: Ilmari Karonen
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-01-05 18:41 UTC by Charles Broughton
Modified: 2013-04-22 16:14 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
A quick draft of a patch to fix this (not tested) (746 bytes, patch)
2011-01-05 19:06 UTC, Ilmari Karonen
Details
Patch v2, use last IP in REMOTE_ADDR and canonicalize it properly (792 bytes, patch)
2011-01-05 19:22 UTC, Ilmari Karonen
Details

Description Charles Broughton 2011-01-05 18:41:53 UTC
For example:  "xx.xxx.xx.xxx, xx.xxx.xxx.xx" or even an array, it simply cannot handle it an denies access to all users who connect with this.
Comment 1 Ilmari Karonen 2011-01-05 18:46:11 UTC
Shouldn't take much to change wfGetIP() in ProxyTools.php to handle this.  However, it'd be nice to know what's generating these kinds of REMOTE_ADDRs and why.  In particular, if we get multiple IPs in REMOTE_ADDR, which one should we use?  The first?  The last?  Something else?
Comment 2 Charles Broughton 2011-01-05 18:47:53 UTC
You should use the LAST technically, as under apache the FIRST is the X_FORWARDED_BY.  Or perhaps you should test against X_FORWARDED_FOR ?  Because that ALSO returns two IPs... grrr
Comment 3 Charles Broughton 2011-01-05 18:50:42 UTC
TESTCASE: http://dpaste.com/hold/294530/
Comment 4 Ilmari Karonen 2011-01-05 19:06:26 UTC
Created attachment 7954 [details]
A quick draft of a patch to fix this (not tested)

Here's a quick patch that should at least stop it from crashing.  I'm still not quite sure _how_ we should properly interpret such input, though.
Comment 5 Charles Broughton 2011-01-05 19:09:01 UTC
Should you not canonicalize the parts then reformat it?
@Iimari Karonen
Comment 6 Ilmari Karonen 2011-01-05 19:12:03 UTC
I was assuming the loop below was doing that already, but now I see that I'd been reading it wrong.  New patch coming soon.
Comment 7 Platonides 2011-01-05 19:20:18 UTC
What kind of setup is generating such REMOTE_ADDR?

The tcp connection can only be established with one remote ip. That seems oddly moved into HTTP_X_REAL_IP header.
Comment 8 Ilmari Karonen 2011-01-05 19:22:32 UTC
Created attachment 7955 [details]
Patch v2, use last IP in REMOTE_ADDR and canonicalize it properly
Comment 9 Brion Vibber 2011-01-08 01:50:33 UTC
It *shouldn't* be possible for REMOTE_ADDR to contain more than one IP, but it looks like it can happen if the server's using something like this apache module: http://stderr.net/apache/rpaf/ or this nginx module: http://wiki.nginx.org/HttpRealIpModule

These will replace the value used to fill REMOTE_ADDR with the X-Forwarded-For value, and it's a good bet that they're not actually thinking to validate the value and format it correctly... (the apache module I found definitely doesn't). If there was another proxy in the chain, then the X-Forwarded-For header will have two or more IPs in it, and they can get copied right in.

This isn't an ideal thing to do in your server config -- it's meant to fix 3rd-party apps looking only at REMOTE_ADDR, but is then just as likely to break them in the multi-IP case -- and it really should be fixed in that module or whatever similar system is triggering it.


But, when we *do* find ourselves receiving such a bogus value, it's probably best to treat it like an XFF from a trusted proxy: use the most recent value in the stack, since it's the IP that the trusted proxy saw itself and can verify.

Patch v2 looks like it should be fine.
Comment 10 Sumana Harihareswara 2011-11-10 02:49:07 UTC
(In reply to comment #9)
> Patch v2 looks like it should be fine.

So should Ilmari commit it?
Comment 11 Sumana Harihareswara 2012-07-20 18:53:32 UTC
Ilmari, I guess you should check for IPv6 compatibility and anything else that's changed in the last several months and commit to Git.
Comment 12 Tyler Romeo 2012-08-22 20:40:53 UTC
Moved patch into Gerrit (also adjusted for current version because wfGetIP has been deprecated and moved to WebRequest::getRawIP).

https://gerrit.wikimedia.org/r/21135
Comment 13 Dereckson 2012-08-27 20:29:45 UTC
Bug assigned to code submitter (Ilmari Karonen).
Comment 14 Sumana Harihareswara 2012-10-24 05:45:39 UTC
Thanks to Ilmari and to Tyler! https://gerrit.wikimedia.org/r/21135 is now merged so I'm closing this as fixed.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links