Repository navigation
fix(api): the admin operations need an admin with the session cookie too - #1068
Conversation
The security handler of the API checked the `admin` tag of an operation for an
access token only: any signed-in user could call the 26 admin operations from
the browser with the session cookie, e.g. read the access tokens of the admin
(GET /users/{email}/accessTokens returns their ids, the bearer secrets,
STF_TOKEN of the grid too), remove users and devices or change their status.
Both ways of the authentication now refuse a user (403) for them.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
❌ STF CI report5 failing · 6 test tiers (6 pass / 0 fail / 0 skip) · 10 Android versions (10 with a usable device in STF) · 6 iOS versions (1 passing) Test tiers
Android device matrix
Image = a system image is published for that API and arch. Boot = emulator reached iOS simulator matrix
WebDriverAgent on an iPhone simulator against the WDA client of the ios-device unit (test/zebrunner-ios). A red column: Simulator, the simulator did not boot · WDA, WebDriverAgent did not start · Session, no WDA session · Appium kept, the session of an Appium test was not kept · Size, wrong screen size · Orientation, no orientation or battery · Home, the home button did not work · Touch, tap or swipe failed · Screenshot, no screenshot · Settings, Settings did not open or the app was lost · Clipboard, the pasteboard was not written or read · URL, Safari did not open the address · Stream, no MJPEG frame · Stable, the unit would have stopped Failures
Logs, screenshots, logcat and Playwright traces are attached to the run as artifacts · full run · commit |
Problem
lib/units/api/helpers/securityHandlers.tschecks theadmintag of an operation only for an access token (Authorization: Bearer). The other branch, the session cookie of the app, setsreq.userwithout any check, and the controllers do not check the privilege either (onlymetrics). So any signed-in user can call the 26 admin operations from the browser, e.g.:GET /api/v1/users/<admin email>/accessTokens→ the ids of the tokens of the admin, which are the bearer secrets (STF_TOKENof mcloud-grid too);DELETE /users/{email},DELETE /devices,PUT /devices/{serial}(status), the origin groups of the devices.This is the upstream code (DeviceFarmer/stf).
Changes
forbidsUser()(fork lines): the same 403 for a user on anadminoperation with the cookie as with a token; an operation without tags is not admin.ZEBRUNNER.md: REST API.The UI of a user calls none of these operations (
GET /users,GET /users/{email},GET /users/alertMessageare not admin; the origin groups are managed by admins).Testing
test/units/zebrunner/api-admin.mts(7): every operation ofapi_v1.yamltaggedadmin(found there, so a new one is covered): 403 for a user with a session cookie and with an access token, an admin passes with both; a user passes every other operation with both. Without the fix the cookie test fails.npm run lint,npm run test:unit: 498 passing.