Page MenuHomePhabricator

[S] Error: exception of type TypeError: MediaWiki\User\UserNameUtils::isIP(): Argument #1 ($name) must be of type string, array given, called in /var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php on line 192
Closed, ResolvedPublicBUG REPORT

Description

When submitting a ReportIncident report with a JSON object as the reportedUser property, I can get a 500 error.

Steps to replicate the issue
  1. Install the ReportIncident extension
  2. Log into an account that has a confirmed email address
  3. Open a user talk page that exists
  4. Open DevTools and then the network tab
  5. Click on the Report link in the Tools menu
  6. Navigate to the second step
  7. Fill out the form and submit it
  8. Find the POST request for submitting the form and copy it as fetch
  9. Go to the browser console and paste the fetch command
  10. Modify the command to change the reportedUser property to have the value of {"test": "1234"} (and escape the " character if necessary). An example of what this should look like is below:
await fetch("http://localhost:8080/w/rest.php/reportincident/v0/report", {
    "credentials": "include",
    "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Language": "en-GB,en;q=0.5",
        "Content-Type": "application/json",
        "X-Requested-With": "XMLHttpRequest",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache"
    },
    "referrer": "http://localhost:8080/wiki/User_talk:Dreamyjazz",
    "body": "{\"reportedUser\":{\"test\": \"1234\"},\"details\":\"aaa\",\"behaviors\":[\"threats-or-violence\"],\"revisionId\":1}",
    "method": "POST",
    "mode": "cors"
});
What happens

A 500 server error is returned with the following:

{"message":"Error: exception of type TypeError: MediaWiki\\User\\UserNameUtils::isIP(): Argument #1 ($name) must be of type string, array given, called in /var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php on line 192","exception":{"id":"7a4d263887f7f24aa08fd435","type":"TypeError","file":"/var/www/html/w/includes/user/UserNameUtils.php","line":333,"message":"MediaWiki\\User\\UserNameUtils::isIP(): Argument #1 ($name) must be of type string, array given, called in /var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php on line 192","code":0,"url":"/w/rest.php/reportincident/v0/report","caught_by":"other","backtrace":[{"file":"/var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php","line":192,"function":"isIP","class":"MediaWiki\\User\\UserNameUtils","type":"->"},{"file":"/var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php","line":80,"function":"getIncidentReportObjectFromValidatedBody","class":"MediaWiki\\Extension\\ReportIncident\\Api\\Rest\\Handler\\ReportHandler","type":"->"},{"file":"/var/www/html/w/includes/Rest/SimpleHandler.php","line":38,"function":"run","class":"MediaWiki\\Extension\\ReportIncident\\Api\\Rest\\Handler\\ReportHandler","type":"->"},{"file":"/var/www/html/w/includes/Rest/Router.php","line":536,"function":"execute","class":"MediaWiki\\Rest\\SimpleHandler","type":"->"},{"file":"/var/www/html/w/includes/Rest/Router.php","line":441,"function":"executeHandler","class":"MediaWiki\\Rest\\Router","type":"->"},{"file":"/var/www/html/w/includes/Rest/EntryPoint.php","line":195,"function":"execute","class":"MediaWiki\\Rest\\Router","type":"->"},{"file":"/var/www/html/w/includes/Rest/EntryPoint.php","line":135,"function":"execute","class":"MediaWiki\\Rest\\EntryPoint","type":"->"},{"file":"/var/www/html/w/rest.php","line":31,"function":"main","class":"MediaWiki\\Rest\\EntryPoint","type":"::"}]},"httpCode":500,"httpReason":"Internal Server Error"}
What should have happened instead

A 4XX error should have been returned as the error was due to the submitted data and not the fault of the server.

Software version

MediaWiki 1.42.0-alpha (8d06e10) 13:54, 31 October 2023. ReportIncident – (15aab01) 14:40, 31 October 2023

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Dreamy_Jazz renamed this task from Error: exception of type TypeError: MediaWiki\User\UserNameUtils::isIP(): Argument #1 ($name) must be of type string, array given, called in /var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php on line 192 to [S] Error: exception of type TypeError: MediaWiki\User\UserNameUtils::isIP(): Argument #1 ($name) must be of type string, array given, called in /var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php on line 192.Oct 31 2023, 4:26 PM

Change 970410 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/ReportIncident@master] [WIP] Validate that the reportedUser field is a string

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

Change 970410 merged by jenkins-bot:

[mediawiki/extensions/ReportIncident@master] Validate that the reportedUser field is a string

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

Test wiki created on Patch demo by DJacksonA using patch(es) linked to this task:
https://patchdemo.wmflabs.org/wikis/f15ca4ef95/w

Djackson-ctr subscribed.

I have verified the fix for this issue has been implemented and is working as expected per the Ticket Description...
Thank you @Dreamy_Jazz!!!

image.png (749×1 px, 72 KB)

image.png (913×1 px, 95 KB)


image.png (751×1 px, 73 KB)

image.png (966×1 px, 105 KB)

Test wiki on Patch demo by DJacksonA using patch(es) linked to this task was deleted:

https://patchdemo.wmflabs.org/wikis/f15ca4ef95/w/