Page MenuHomePhabricator

Throttle identifiers are ambiguous
Closed, ResolvedPublic

Description

Looking at the code, I realized that throttle identifiers are ambiguous and could lead to subtle bugs. For instance:

  1. The identifier for 'user' is the user's id. This makes sense, but if the edit comes from an anonymous user the ID is 0, and thus grouping by 'user' effectively counts all IPs to be the same user
    1. The fact that in the 'default' case we use 0 as identifier adds up to this (although there shouldn't be any default, i.e. if reaching the default we should throw)
  2. The 'creationdate' is an integer which could be equal to the ID of an existing user (very unlikely)
  3. The 'site' identifier is 1, which makes it count for throttling the user with ID = 1 (very unlikely)
  4. The 'editcount' is an integer, which could be confused mostly with user ID

All these things together could create some confusion which we should avoid altogether. A simple solution could be to prepend the identifier name: so, for instance, the identifier for 'site' won't be 1 but 'site-1', etc. This will address 1.A, 2, 3 and 4.
As for 1, we could make 'user' fallback to the IP if the ID is 0, or use the username instead of the ID (but I think this could introduce problems in case of renaming).

Event Timeline

Oh, another example: the cool™ method we use to extract the IP range makes use of IP::toHex, which however prepends the return value with 'v6-'. Since we use the first 4 values of it, basically IPv6s are only differentiated for their first digit! Quite big to be a /16 range, huh?

Change 477580 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/extensions/AbuseFilter@master] [WIP] Overhaul throttle identifiers

https://gerrit.wikimedia.org/r/477580

Update: actually, throttle identifiers aren't too bad: when creating the keys we pass $type to the constructor, so that a key is something like

abusefilter:throttle:filterID:group1,group2,group3:value1:value2:value3

and the patch above will change it to

abusefilter:throttle:filterID:group1-value1:group2-value2:group3-value3

Change 477580 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/extensions/AbuseFilter@master] [WIP] Overhaul throttle identifiers

https://gerrit.wikimedia.org/r/477580

Change 553792 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/extensions/AbuseFilter@master] Overhaul throttle identifiers

https://gerrit.wikimedia.org/r/553792

Change 477580 abandoned by Daimona Eaytoy:
[WIP] Overhaul throttle identifiers

Reason:
Re-done in I54c4209f2f0d5a4c5e7b81bed240ca3e28a2ded7, which excludes the (controversial) "user" part

https://gerrit.wikimedia.org/r/477580

Change 553792 merged by jenkins-bot:

[mediawiki/extensions/AbuseFilter@master] Overhaul throttle identifiers

https://gerrit.wikimedia.org/r/553792

Daimona removed a project: Patch-For-Review.