Last modified: 2013-12-23 14:30:11 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 T40117, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 38117 - NetworkAuth: Security: Bad IP range recognition
NetworkAuth: Security: Bad IP range recognition
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Other (Other open bugs)
unspecified
All All
: High critical (vote)
: ---
Assigned To: Nobody - You can work on this!
http://www.mediawiki.org/wiki/Extensi...
: patch, patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-02 13:27 UTC by Olaf Lenz
Modified: 2013-12-23 14:30 UTC (History)
3 users (show)

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


Attachments
Patch that fixes the problem. (690 bytes, patch)
2012-10-12 13:54 UTC, Olaf Lenz
Details
Patch that really fixes the problem. (779 bytes, patch)
2012-10-12 13:56 UTC, Olaf Lenz
Details

Description Olaf Lenz 2012-07-02 13:27:04 UTC
This is a security-related bug in the Extension:NetworkAuth.

The problem is that the extension does not to match IP ranges correctly and thus authenticates IP addresses that do not belong to the specified IP range.

Both the IP address that the extension gets via wfGetIP() and the IP range that is specified in LocalSettings.php are transformed to hex numbers via IP::toHex(). Afterwards the obtained IP adress is compared to the range to determine whether the address is in the range.

Here is the somewhat simplified code. parsedRange is an array containing the lower and upper limits of the range.

$ip = wfGetIP();
$hex = IP::toHex( $ip );
if ( $hex >= IP::toHex( $parsedRange[0] ) 
  && $hex <= IP::toHex( $parsedRange[1] )) 
{
  # authenticate user
}

Unfortunately, the function IP::toHex() does *not* return a hex number, but a string containing the hex digits (e.g. IP::toHex("46.115.22.119") -> "2E771673") *without* the leading "0x". This works fine in most cases, as the string is implicitly typecast to a number and compared afterwards.

However, in the case that the string of the IP range contains only decimal digits (e.g. IP::toHex("129.69.120.0") -> "81457800"), this fails spectacularly, as in the one case, it interprets the string as a hex number, and in the other case as a dec number. In the above case, this means that 
  IP::toHex("46.115.22.119") > IP::toHex("129.69.120.0") == true

This bug report is made problematic by the fact that at the moment I cannot even find the current code of the extension, as all "Download" links on

  http://www.mediawiki.org/wiki/Extension:NetworkAuth

seem to be broken. I am willing to provide a patch when anyone can tell me where to find the repo containing the current code of the extension.
Comment 1 Olaf Lenz 2012-07-02 13:29:59 UTC
The proposed fix to this bug is to explicitly cast the transformed IP address to a number by using hexdec() like:

$ip = wfGetIP();
$hex = hexdec(IP::toHex( $ip ));
if ( $hex >= hexdec(IP::toHex( $parsedRange[0] )) 
  && $hex <= hexdec(IP::toHex( $parsedRange[1] ))) 
{
  # authenticate user
}
Comment 2 Andre Klapper 2012-10-12 12:33:04 UTC
CC'ing the maintainer.
Comment 3 Olaf Lenz 2012-10-12 13:54:39 UTC
Created attachment 11184 [details]
Patch that fixes the problem.
Comment 4 Olaf Lenz 2012-10-12 13:56:46 UTC
Created attachment 11185 [details]
Patch that really fixes the problem.
Comment 5 Andre Klapper 2012-12-14 14:45:49 UTC
Tim: ping - do you still maintain this?
Comment 6 Olaf Lenz 2012-12-14 14:50:28 UTC
The problem currently still exists in the code. 
However, I am about to take over maintenance of the whole extension, as Tim Laqua is busy. Still I think until I have actually taken over, the patch should be applied.
Comment 7 Andre Klapper 2012-12-15 17:12:57 UTC
(In reply to comment #6)
> I am about to take over maintenance of the whole extension.

That's great to hear!

> the patch should be applied.

Not sure if somebody else feels comfortable enough to review that code... :-/
Comment 8 Tim Laqua 2012-12-18 09:43:03 UTC
Patch looks good ;-)  And no, I'm not maintaining it anymore - Olaf, feel free to take it over.  I also can't apply the patch, I don't have a working copy checked out any more.
Comment 9 Tony Thomas 2013-12-22 05:03:02 UTC
This patch is applied in the latest release of NetworkAuth. Does the problem still exist ?
Comment 10 Andre Klapper 2013-12-22 14:55:22 UTC
> This patch is applied in the latest release of NetworkAuth.

Direct link to the change on git.wikimedia.org or gerrit.wikimedia.org is highly welcome for such statements.
Comment 12 Andre Klapper 2013-12-23 14:30:11 UTC
Uh, thanks a lot for elaborating! Closing as FIXED then.

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


Navigation
Links