No Code Attached Yet bug
avatar bernd5
bernd5
26 Sep 2023

Steps to reproduce the issue

Exec web api request:

get http://my_joomla_domain/api/index.php/v1/content/articles
Authorization: Bearer SomeToken
Accept: application/vnd.api+json

Expected result

Some parsable json with article data

Actual result

<br />
<b>Warning</b>:  Attempt to read property "status" on int in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on string in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on null in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
<br />
<b>Warning</b>:  Attempt to read property "status" on null in <b>C:\xampp\htdocs\sipam\libraries\src\Application\CMSApplication.php</b> on line <b>830</b><br />
{"links":{
...
}}

The warnings (I assume generated by php) - should not be written to the response.

The warnings belong to the folowing line of code:

foreach ($authorisations as $authorisation) {
                if ((int) $authorisation->status & $denied_states) {
...
avatar bernd5 bernd5 - open - 26 Sep 2023
avatar joomla-cms-bot joomla-cms-bot - change - 26 Sep 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 26 Sep 2023
avatar bernd5 bernd5 - change - 26 Sep 2023
The description was changed
avatar bernd5 bernd5 - edited - 26 Sep 2023
avatar alikon
alikon - comment - 26 Sep 2023

on what joomla version ?

avatar bernd5
bernd5 - comment - 26 Sep 2023

Version 4.2.9

avatar brianteeman
brianteeman - comment - 26 Sep 2023

Before reporting any issue please make sure that you are running the current release as your problem might already have been resolved.

avatar bernd5
bernd5 - comment - 26 Sep 2023

The issue seems to be caused by my own plugin somehow - but that is not my problem.
Warnings should never appear there...

Warnings could appear in the document like:

{
   "data": [
          //what ever
   ],
   "warnings": [
      {
         "text": "something went wrong...",
         location: "..."
      }
   ]

}
avatar bernd5
bernd5 - comment - 26 Sep 2023

I actually set the "result" property while processing the "onUserAuthorisation" event. This seems to be not used by other plugins - therefore the result is usually []... - we do not enter the loop

The spec/doc says it should return "null" or JAuthenticationResponse. JAuthenticationResponse->status is of type string - so this code is bad...

avatar bernd5
bernd5 - comment - 26 Sep 2023

The actual problem was / is that I used the non-legacy plugin api (Event - based).
And I called:

$event->setArgument('result', $result);

where $result is actually a JAuthenticationResponse.

Now triggerEvent simply returned that non-array object. See:

return !isset($result['result']) || \is_null($result['result']) ? [] : $result['result'];

This caused that we were not iterating over authorisations - but over fields of an JAuthenticationResponse:

foreach ($authorisations as $authorisation) {
                if ((int) $authorisation->status & $denied_states) {
...
avatar Hackwar Hackwar - change - 27 Mar 2024
Labels Added: bug
avatar Hackwar Hackwar - labeled - 27 Mar 2024

Add a Comment

Login with GitHub to post a comment