Page MenuHomePhabricator

Fix non-sequential indices in TemporaryAccountHandler API results
Closed, ResolvedPublic

Description

Background

TemporaryAccountHandler returns a list of IPs used by a temporary account.

The returned list should be an array, e.g.:

{
  "ips": [
    "192:168:1:1:0:0:0:0"
  ]
}

However, sometimes an object is returned with numerical indices that are non-sequential, e.g.:

{
  "ips": {
    "0": "192:168:1:1:0:0:0:0",
    "2": "192:168:1:0:0:0:0:0"
  }
}

This should instead be:

{
  "ips": [
    "0": "192:168:1:1:0:0:0:0",
    "1": "192:168:1:0:0:0:0:0"
  ]
}

This might only happen if there are multiple rows for the same actor-IP-timestamp. For more information see T324603#8577985 and the following comments.

Acceptance criteria
  • The returned list of IPs is always an array
Notes

The problem might arise here when calling array_unique here: https://gerrit.wikimedia.org/g/mediawiki/extensions/CheckUser/+/d5a63f4df9c6f77310c3ebbf6e90baa56136d9e5/src/Api/Rest/Handler/TemporaryAccountHandler.php#47 Could we use something like array_values(array_unique($ips))?

Testing Notes

-To use this API, you'll need the checkuser-temporary-account right that's introduced in this patch.You must also have Enable revealing IP addresses for temporary accounts enabled on your Special:Preferences

-The URL is rest.php/checkuser/v0/temporaryaccount/{name}, where {name} is the user name you want to look up (see RestRoutes in extension.json)

-You can add the optional params in TemporaryAccountHandler::getParamSettings via the querystring (e.g. ?revision=123, etc)

-In case you have been switching $wgAutoCreateTempUser['enabled'] on and off locally, it needs to be true to avoid a nonexistent account error

-Visiting this URL : http://localhost:8080/w/rest.php/checkuser/v0/temporaryaccount/{nameoftemporaryaccount} should give JSON object with a single key "ips" which maps to an array of unique IP addresses used by a temporary account

Event Timeline

Change 888056 had a related patch set uploaded (by Cyndywikime; author: Cyndywikime):

[mediawiki/extensions/CheckUser@master] Fix non-sequential indices in TemporaryAccountHandler API results

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

Make sure to go into Special:Preferences, can you check the option "Enable revealing IP addresses for temporary accounts"

Change 888056 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Fix non-sequential indices in TemporaryAccountHandler API results

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

dom_walden subscribed.

I wrote a script to check that:

  • the IPs are always returned as a list (not an object or dictionary), which I believe means their indices are always sequential
  • the IPs returned match the IPs in the cu_changes table and are in the correct order (descending lexicographic order of IP; I was concerned that array_values() might change this)

Test environment: local docker CheckUser 2.5 (7f54d18) 07:29, 13 February 2023.