View Issue Details

This bug affects 2 person(s).
 14
IDProjectCategoryView StatusLast Update
17739Bug reportsUser / Groups / Rolespublic2022-05-02 10:33
ReporterMapache Assigned Togabrieljenik  
PrioritynoneSeverityblock 
Status closedResolutionfixed 
Product Version5.2.x 
Summary17739: list_surveys JSON-RPC API method does not obey $sUsername if set
Description

using a dedicated API-user-account like "api" does not return only those surveys that belong to a given user but all surveys.

Steps To Reproduce

Steps to reproduce

1) add a user account like "api"
2) grant "Use internal database authentication" permission
3) grant View/read permissions on "Surveys"
4) run {"method": "list_surveys", "params": ["TOKEN", null], "id": 1} and {"method": "list_surveys", "params": ["TOKEN", "SOMEEXISTINGUSER"], "id": 1} against the API

Expected result

{"method": "list_surveys", "params": ["TOKEN", null], "id": 1} => return all surveys for every user
{"method": "list_surveys", "params": ["TOKEN", "SOMEEXISTINGUSER"], "id": 1} => return surveys for SOMEEXISTINGUSER

Actual result

{"method": "list_surveys", "params": ["TOKEN", null], "id": 1} => returns all surveys for every user
{"method": "list_surveys", "params": ["TOKEN", "SOMEEXISTINGUSER"], "id": 1} => also returns all surveys for every user

Tagsapi
Bug heat14
Complete LimeSurvey version number (& build)5.2.2+211115 (starting from 4.3.34)
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMySQL 8.0
Server OS (if known)
Webserver software & version (if known)
PHP Version7.4.25

Users monitoring this issue

DarioRoig

Activities

gabrieljenik

gabrieljenik

2022-04-12 15:18

manager   ~69007

Hi,

3) grant View/read permissions on "Surveys"
Are you applying global read permission on surveys?
Or applying read on an individual survey?

{"method": "list_surveys", "params": ["TOKEN", "SOMEEXISTINGUSER"], "id": 1}
Are you using the remote control mehotd as expected?
Although finally, parameters are not named but they follow an order, seems the parameter name is not correct.
I would expect to be username but not TOKEN.
https://api.limesurvey.org/classes/remotecontrol_handle.html#method_list_surveys
Again, don't think this is the issue, but the permissions.

Mapache

Mapache

2022-04-12 15:22

reporter   ~69008

cannot follow you here...

I tried with global and without global permissions but anyhow: If a username is passed, i.e. not null, it should return users for that user only.

As for "Are you using the remote control mehotd as expected?" API doc says:

List the survey belonging to a user (RPC function)
list_surveys(string $sSessionKey,string|null $sUsername = null): array

"sSessionKey" === TOKEN in my example..

gabrieljenik

gabrieljenik

2022-04-12 15:28

manager   ~69009

If you apply read permissions on the global level, the user will be able to read all surveys.
Then the scenario that you should test it removing Global read permission and and allowing individual permissions on a specific survey.

{"method": "list_surveys", "params": ["TOKEN", "SOMEEXISTINGUSER"], "id": 1}
If token is the sessionKey, how are you sending the value for filtering username?

Mapache

Mapache

2022-04-12 15:31

reporter   ~69010

"If a username is passed, i.e. not null, it should return users for that user only."

correct: "If a username is passed, i.e. not null, it should return SURVEYS for that user only."

Mapache

Mapache

2022-04-12 15:44

reporter   ~69011

Get session key:

{ "method": "get_session_key", "params": ["someapiuser", "supersecret"], "id": 1 }
=> {"id":1,"result":"abf5BiVjqajsHJ4NhL0iF0hWNHsecI11","error":null}

{"method": "list_surveys", "params": ["abf5BiVjqajsHJ4NhL0iF0hWNHsecI11", "someuser"], "id": 1}
=> ALL SURVEYS (no matter if someapiuser has global permissions or not)

As mentioned before:

Doc says: list_surveys(string $sSessionKey,string|null $sUsername = null): array
=> There is always a session key; how would that work otherwise?!

As for your permission "hint": IF $sUsername != null in list_surveys(string $sSessionKey,string|null $sUsername = null): array IT MUST return only the surveys for the user otherwise that option would be useless.

Mapache

Mapache

2022-04-12 15:47

reporter   ~69012

If you apply read permissions on the global level, the user will be able to read all surveys.
Then the scenario that you should test it removing Global read permission and and allowing individual permissions on a specific survey.

=> This doesn't make sense. If I give a user permissions on a specific survey I would not need to pass the username param to list_surveys as it would / should then only return the users surveys anyways..

gabrieljenik

gabrieljenik

2022-04-12 15:56

manager   ~69013

{"method": "list_surveys", "params": ["TOKEN", "SOMEEXISTINGUSER"], "id": 1}
If token is the sessionKey, how are you sending the value for filtering username?

I am sorry, I confused the coma and read it like a full-colon.


If I give a user permissions on a specific survey I would not need to pass the username param to list_surveys as it would / should then only return the users surveys anyways..

Well, not always. I think you are assuming you are connecting with user A and want to get surveys for user A.
That's not always the case.


OK, let us review it and play around with it.

As to clarify:

  • You connect using a user called API, right?
  • If API user has global read permission and try to get surveys for a user with restricted access, you still get all surveys, right?.
Mapache

Mapache

2022-04-12 15:59

reporter   ~69014

  • You connect using a user called API, right?
    => correct

  • If API user has global read permission and try to get surveys for a user with restricted access, you still get all surveys, right?.
    => correct

As far as I remember it used to work (as expected) on 3.x LTS

gabrieljenik

gabrieljenik

2022-04-12 16:02

manager   ~69015

As far as I remember it used to work (as expected) on 3.x LTS

Yep. Me too. And from what I see, there hasn't been much changes around that.

gabrieljenik

gabrieljenik

2022-04-13 14:00

manager   ~69050

PR: https://github.com/LimeSurvey/LimeSurvey/pull/2346

gabrieljenik

gabrieljenik

2022-05-02 07:58

manager   ~69326

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=33455

LimeBot

LimeBot

2022-05-02 10:33

administrator   ~69340

Fixed in Release 5.3.12+220502

Related Changesets

LimeSurvey: master 64a45a78

2022-05-02 07:58:34

gabrieljenik


Committer: GitHub Details Diff
Fixed issue 17739: list_surveys JSON-RPC API method does not obey if set (#2346)

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
Affected Issues
17739
mod - application/models/Survey.php Diff File

Issue History

Date Modified Username Field Change
2021-11-18 23:30 Mapache New Issue
2021-11-18 23:32 Mapache Tag Attached: api
2021-11-19 09:19 galads Assigned To => galads
2021-11-19 09:19 galads Status new => acknowledged
2021-11-30 10:19 DarioRoig Bug heat 0 => 6
2021-11-30 10:20 DarioRoig Issue Monitored: DarioRoig
2021-11-30 10:20 DarioRoig Bug heat 6 => 8
2022-04-12 10:11 galads Assigned To galads => gabrieljenik
2022-04-12 15:18 gabrieljenik Note Added: 69007
2022-04-12 15:18 gabrieljenik Bug heat 8 => 10
2022-04-12 15:18 gabrieljenik Status acknowledged => feedback
2022-04-12 15:22 Mapache Note Added: 69008
2022-04-12 15:22 Mapache Bug heat 10 => 12
2022-04-12 15:22 Mapache Status feedback => assigned
2022-04-12 15:28 gabrieljenik Note Added: 69009
2022-04-12 15:31 Mapache Note Added: 69010
2022-04-12 15:44 Mapache Note Added: 69011
2022-04-12 15:47 Mapache Note Added: 69012
2022-04-12 15:56 gabrieljenik Note Added: 69013
2022-04-12 15:59 Mapache Note Added: 69014
2022-04-12 16:02 gabrieljenik Note Added: 69015
2022-04-13 14:00 gabrieljenik Note Added: 69050
2022-04-13 14:00 gabrieljenik Status assigned => ready for testing
2022-05-02 07:58 gabrieljenik Changeset attached => LimeSurvey master 64a45a78
2022-05-02 07:58 gabrieljenik Note Added: 69326
2022-05-02 07:58 gabrieljenik Resolution open => fixed
2022-05-02 10:33 LimeBot Note Added: 69340
2022-05-02 10:33 LimeBot Status ready for testing => closed
2022-05-02 10:33 LimeBot Bug heat 12 => 14