PATCH/POST users/levels doesn't check group IDs. Argument is unchecked written to database and can cause exceptions in backend afterwards. Validate that all group IDs are numeric and refer to existing groups; fail otherwise.
curl -k -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -w "\nHTTP status: %{http_code}\n" -X PATCH 'https://localhost:7154/api/index.php/v1/users/levels/1' -d '{ "rules": [ "Public" ] }'
curl -k -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -w "\nHTTP status: %{http_code}\n" -X PATCH 'https://localhost:7154/api/index.php/v1/users/levels/1' -d '{ "rules": 1 }'
curl -k -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -w "\nHTTP status: %{http_code}\n" -X PATCH 'https://localhost:7154/api/index.php/v1/users/levels/1' -d '{ "rules": [ 42 ] }'
curl -kH "Authorization: Bearer $TOKEN" -w "\nHTTP status: %{http_code}\n" -X POST 'https://localhost:7154/api/index.php/v1/users/levels' -d '{
"title": "Test2",
"rules": [ 4711 ]
}'
Tested with 5.4-dev branch.
Found in testing #46080. This may be a minor priority.
| Labels |
Added:
No Code Attached Yet
|
||
| Labels |
Added:
bug
Webservices
|
||
Hi @muhme, I have been working on this issue and wanted to confirm the intended behavior.
After adding validation in LevelModel, invalid or non existent group IDs are correctly rejected, amd the backend exception described here no longer occurs. but, non-array inputs for rules still behave inconsistently because the field uses filter="intarray", which seems to normalize input before model validation.
Should the Web Services API strictly require rules to be an array and reject any non-array input (as you suggested in the “Missing array” case), or is this coercion via intarray considered acceptable behavior?
Also, are the 500 responses for certain invalid inputs something that should be addressed as part of this issue?
Hi @adarshdubey03, I viewed the API only from external as black box. Perhaps @alikon can explain how the API should work overall.
Regarding the 500 responses, it’s better to handle them in separate PRs rather than mixing too many changes together. Only include them in the same PR if they are directly related to the other changes.
Thanks a lot for working on this issue! I’m looking forward to testing your PR.
Hello mentainers,
I'm Dhanashri Jadhav, a GSOC aspirant.
Eager to contribute to GSoC projects & actively participate in Joomla.
Looking forward to collaborating & learing from all of you.
Thank you!