Repository navigation
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
Draft
fix(contexts): keep the table list working when an application holds a node the member cannot read#3482rubenvdlinde wants to merge 4 commits into
rubenvdlinde wants to merge 4 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withfind(), which throws aPermissionErrorfor a node the member may not read, and nothing caught it, so the whole list failed:GET /apps/tables/tableanswered 403,GET /api/1/tablesandGET /api/2/tablesanswered 500, and the member lost their own tables from the navigation.ViewService::findSharedViewsWithMe()had the same loop for views (GET /apps/tables/viewanswered 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:
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.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.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 withocc maintenance:repair.Not changed here:
Api1Controller::index()andApiTablesController::index()still turn aPermissionErrorinto 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.
l3418managerowns tables "3418 readable" and "3418 hidden import", a view "3418 hidden view" and an application with all three, shared read-only withl3418reader, who has only the tutorial table. Permissions 0 were set with the scheme import (main) and in the database for the view node.POST /api/2/contexts/{id}/scheme/import, table node with permissions 0GET /index.php/apps/tables/tableGET /index.php/apps/tables/api/1/tablesGET /ocs/v2.php/apps/tables/api/2/tablesGET /index.php/apps/tables/viewocc maintenance:repairIn 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
/backport to stableX.X🤖 AI (if applicable)