nextcloud / nextcloud/tables

[Bug]: TypeError on unauthenticated calls against OCS routes, success error code

Open
#1,192 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop bug feature: api
Dominant language
JavaScript
Stars
214
Forks
52
Avg merge
1d 10h
Merged PRs (30d)
82

Description

Steps to reproduce
  1. Fire an unauthenticated GET request against e.g. ocs/v2.php/apps/tables/api/2/contexts
Expected behavior

The server responds with 401.

No (unnecessary) exceptions/errors are thrown or logged in nextcloud.log

Actual behavior

The ContextController and the AOCSController expect the $userId in their constructor as string. In an unauthenticated request it is null, and so the Controller class cannot be instantiated in lib/private/AppFramework/App::main() and a TypeError is logged like:

{
  "reqId": "5nXYwv9Cf4SX3EegzQSK",
  "level": 3,
  "time": "2024-07-12T10:21:03+00:00",
  "remoteAddr": "127.0.0.1",
  "user": "--",
  "app": "PHP",
  "method": "GET",
  "url": "/ocs/v2.php/apps/tables/api/2/contexts",
  "message": "TypeError: OCA\\Tables\\Controller\\ContextController::__construct(): Argument #4 ($userId) must be of type string, null given at /path/to/nextcloud/apps-repos/tables/lib/Controller/ContextController.php#31",
  "userAgent": "curl/8.8.0",
  "version": "30.0.0.1",
  "data": {
    "app": "PHP"
  }
}

However the server responds with 200:

# curl
$ ╚> curl -i -X GET -H 'OCS-ApiRequest: true'  https://cloud.example.com/ocs/v2.php/apps/tables/api/2/contexts
HTTP/1.1 200 OK
…

# access.log
127.0.0.1 - - [12/Jul/2024:12:21:03 +0200] "GET /ocs/v2.php/apps/tables/api/2/contexts HTTP/1.1" 200 3569 "-" "curl/8.8.0" 66900
Tables app version

main

Additional info

Both ContextController and AOCSController (and maybe other Controllers that extend AOCSController) need to lax the $userId parameter and accept null.

Authenticated checks are implemented in the Middleware, and authorized usage is the default. Logic should be checked to not have wrong assumption on $userId, i.e. might need to have a check for not being null for static analysis.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ContextController.php and AOCSController.php, then inspect their use from lib/private/AppFramework/App.php and the authentication middleware. Reproduce the unauthenticated OCS request and verify that it returns 401 without a TypeError or unnecessary log entry; review other controllers extending AOCSController for the same assumption.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.