Page MenuHomePhabricator

Support for IP ranges in block lists
Open, Needs TriagePublic

Description

Imported from https://github.com/wikimedia/countervandalism-CVNBot/issues/10.

@Krinkle@github.com wrote on 23 Nov 2012:

Imported from https://jira.toolserver.org/browse/SWMTBOT-7

Krinkle wrote on 3 June 2010:

It's been suggested by mike in 2008: support for ranges should be implemented.

At the very least the ranges MediaWiki also supports in blocking, but I think it'd be better to extend this to a more flexible range, and as a bonus put in a ranges MediaWiki supports.

So that for example the following would be possible

  • CVNBot bl add 127.0.0.1-127.0.1.214

And to make make it compatible with Autoblacklistings that follow a range-block:

  • CVNBot bl add 127.0.0.0/25 x=0 r=Autoblacklist: Repeated vandalism, {{schoolblock}} on commons.wikimedia

which the software would convert to

  • CVNBot bl add 127.0.0.0-127.0.0.127

See also: https://commons.wikimedia.org/wiki/User:Kanonkas/Tools#Range_block_calculators

Then when performing the "intel" or "bl show" command it could return something like this

  • CVNBot intel 127.0.0.50 CVNBot: 127.0.0.50 in range 127.0.0.0-127.0.0.127 is on global blacklist , added by Krinke until the end of time ("Autoblacklist: Repeated vandalism, {{schoolblock}} on commons.wikimedia")
Mike.lifeguard wrote on 3 June 2010:

Using CIDR is standard; we should do so here. Perhaps a utility function to convert back and forth would be useful though.

Event Timeline

@Krinkle wrote 23 Feb 2017:

Given how we query lists right now, this will require some added logic. I'd recommend matching the logic that MediaWiki uses to store IP range blocks.

  • Change database to also include a range_start and range_end for IP addresses, and using hexadecimal syntax.
  • That way, the addressed can be matched using < and > in SQL syntax. For example, we can store 127.0.0.0/25 as range_start=7F000000 range_end=7F00007F. And then, where previously we queried for trying to find 127.0.0.1, we'll now first convert it to hex (7F000001) and then also query range_start <= 7F000001 AND range_end >= 7F000001.

https://github.com/wikimedia/mediawiki/blob/1.28.0/includes/Block.php#L348-L373
https://github.com/wikimedia/mediawiki/blob/1.28.0/includes/libs/IP.php#L503-L540