Skip to content

fix(contexts): keep the table list working when an application holds a node the member cannot read - #3482

Draft
rubenvdlinde wants to merge 4 commits into
mainfrom
fix/noid/unreadable-application-nodes
Draft

rubenvdlinde wants to merge 4 commits into
mainfrom
fix/noid/unreadable-application-nodes

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Fixes #3418

A table or view node with permissions 0 in an application took the table list away from every member of that application who is not its owner. TableService::findAll() loads each table node of the user's applications with find(), which throws a PermissionError for a node the member may not read, and nothing caught it, so the whole list failed: GET /apps/tables/table answered 403, GET /api/1/tables and GET /api/2/tables answered 500, and the member lost their own tables from the navigation. ViewService::findSharedViewsWithMe() had the same loop for views (GET /apps/tables/view answered 403).

Permissions 0 could get in although create and update refuse it: the scheme import passed the permissions of each node straight to ContextService::update(), the table import of the user migration stored a missing value as 0, and older rows can hold it.

This follows option (a) of the three questions in the issue:

  • The table and view lists check each application node with canAccessNodeById() before loading it. A node the user cannot read is left out and logged at debug level. Own tables, tables shared directly and readable application nodes are listed as before.
  • The scheme import runs the node permissions through the check of create and update (ContextNodeInput::toPermissions(), now public) before the first write, so permissions 0 or any other invalid value answers 400 with the same message as create and update, and nothing is written. A node without permissions is treated like it is in update: a new node gets read, a kept node keeps its permissions.
  • ContextService::importContext() stores read (1) for a node without permissions. A node with 0 (or a value that is not a number) from an old export also gets read, with a warning in the log, so the user migration does not abort.
  • A new repair step FixApplicationNodesWithoutPermissions (post-migration) sets every node with permissions 0 to read. It is idempotent. The app version moves to 3.0.0-dev.2 so that an instance on 3.0.0-dev.1 runs it on upgrade; it also runs with occ maintenance:repair.

Not changed here: Api1Controller::index() and ApiTablesController::index() still turn a PermissionError into 500 instead of 403, and the frontend still requests each application node one by one and logs "Could not load resource" for one it cannot read. Both are separate behaviours; with this change the lists no longer throw for these nodes.

How it was tested

Unit tests:

  • TableServiceFindAllTest: a member with an unreadable table node in an application gets their own table, a directly shared table and the readable node; the unreadable node is never loaded.
  • ViewServiceFindSharedViewsTest: the same for a view node.
  • ContextServiceTest: a scheme import with permissions 0, 2, 33, -1 or "all" is refused with the create and update message before any table, view or node is looked up or written; importContext() stores 1 for missing, 0 and non-numeric permissions (with a log entry for the last two) and keeps 1 and 7.
  • FixApplicationNodesWithoutPermissionsTest (against the database): table and view nodes with 0 become 1, 1 and 31 stay, a second run changes nothing.

The new tests fail on main. Full unit suite (797 tests) and psalm pass.

How it was tested on a live instance

Nextcloud 34.0.0, PHP 8.4, PostgreSQL. l3418manager owns tables "3418 readable" and "3418 hidden import", a view "3418 hidden view" and an application with all three, shared read-only with l3418reader, who has only the tutorial table. Permissions 0 were set with the scheme import (main) and in the database for the view node.

Request User main This branch
POST /api/2/contexts/{id}/scheme/import, table node with permissions 0 manager 200, row stored as 0 400 "Node permissions must include read (1) and may only combine 1, 2, 4, 8 and 16", nothing written
GET /index.php/apps/tables/table reader 403 "can not read table" 200: tutorial table, "3418 readable"
GET /index.php/apps/tables/api/1/tables reader 500 200: tutorial table, "3418 readable"
GET /ocs/v2.php/apps/tables/api/2/tables reader 500 200: tutorial table, "3418 readable"
GET /index.php/apps/tables/view reader 403 "can not read view" 200, without the view
occ maintenance:repair admin "2 application nodes without permissions now have read permissions", rows 0 to 1; second run: 0
the four lists after the repair reader 200 with "3418 hidden import" and "3418 hidden view" again
scheme import with permissions 3 manager 200, stored as 3

In the browser, on main the reader's navigation shows only "3418 readable"; on this branch it shows the tutorial table and "3418 readable".

🖼️ Screenshots

Main (left) and with this change (right), as the reader:

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔙 Backport requests are created or not needed: /backport to stableX.X
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

…e table and view lists

A table or view node that a member of an application may not read made
TableService::findAll() and ViewService::findSharedViewsWithMe() throw a
PermissionError, so the whole list failed and the member lost their own
tables as well. The node is now checked before it is loaded and skipped
with a debug log entry.

Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
The scheme import passed the permissions of each node straight to
ContextService::update(), past the check that create and update run, so
a manager could store permissions 0. The permissions now go through the
same check as create and update before the first write, and a node
without permissions is handled like it is there: a new node gets read,
a node that is already in the application keeps its permissions.

Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…ions

An application imported with a table, as the user migration does, stored
a node without permissions in the file as permissions 0. Such a node, and
one exported with permissions 0 before create and update refused them,
now gets read permissions; a value that is there but not usable is logged.

Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
A repair step gives every node of an application with permissions 0 read
permissions, as create and update refuse 0 but older rows and imports can
hold it. It runs after the migrations and changes nothing on a second
run. The app version moves to 3.0.0-dev.2 so that an instance on
3.0.0-dev.1 runs it on upgrade.

Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A table or view with permissions 0 in an application breaks the table list of every member

1 participant