feat(plugins): writable_data requires_role + readonly_data current_user auto-injection#55
Merged
Conversation
…er auto-injection Two related Wave 2.1.x extensions to the plugin contract that close the last two gaps blocking endpoint-level RBAC for plugin authors (gap inventory in evonexus-plugin-nutri Step 3 RBAC decision). Changes - PluginWritableResource.requires_role: Optional[List[str]] — when set, the POST/PUT/DELETE handler returns 403 if current_user.role is not in the list. 'admin' role always passes (super-user override). Backwards compatible: resources without the field accept any authenticated user (legacy default). Validator enforces kebab-case role names (^[a-z][a-z0-9-]*$). - routes.plugins.writable_data: enforces requires_role at the endpoint, with a 403 message naming the required roles and the actor's current role. - routes.plugins.readonly_data: auto-injects :current_user_id and :current_user_role as bind params on every readonly query. Plugins can reference them directly in SQL for server-enforced scoping without an app-layer wrapper. The two parameter names are reserved — client requests carrying them in the query string get 400 (no identity spoofing). Tests - tests/backend/test_plugins_rbac_and_scoping.py — 13 cases covering Pydantic acceptance/rejection, 403/200 paths for writable, scoping/spoofing for readonly, backwards compat for resources without requires_role and queries without :current_user_id refs. Compat - Existing plugins (PM Essentials) continue to work unchanged — the new field defaults to None and the auto-injected bind params are silently ignored if the SQL doesn't reference them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Sorry @DavidsonGomes, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
This was referenced Apr 25, 2026
feat(plugins): public_pages content negotiation — HTML shell for browser, raw bundle for clients
#56
Merged
jbmendonca
pushed a commit
to jbmendonca/evo-nexus
that referenced
this pull request
May 15, 2026
…er auto-injection (evolution-foundation#55) Two related Wave 2.1.x extensions to the plugin contract that close the last two gaps blocking endpoint-level RBAC for plugin authors (gap inventory in evonexus-plugin-nutri Step 3 RBAC decision). Changes - PluginWritableResource.requires_role: Optional[List[str]] — when set, the POST/PUT/DELETE handler returns 403 if current_user.role is not in the list. 'admin' role always passes (super-user override). Backwards compatible: resources without the field accept any authenticated user (legacy default). Validator enforces kebab-case role names (^[a-z][a-z0-9-]*$). - routes.plugins.writable_data: enforces requires_role at the endpoint, with a 403 message naming the required roles and the actor's current role. - routes.plugins.readonly_data: auto-injects :current_user_id and :current_user_role as bind params on every readonly query. Plugins can reference them directly in SQL for server-enforced scoping without an app-layer wrapper. The two parameter names are reserved — client requests carrying them in the query string get 400 (no identity spoofing). Tests - tests/backend/test_plugins_rbac_and_scoping.py — 13 cases covering Pydantic acceptance/rejection, 403/200 paths for writable, scoping/spoofing for readonly, backwards compat for resources without requires_role and queries without :current_user_id refs. Compat - Existing plugins (PM Essentials) continue to work unchanged — the new field defaults to None and the auto-injected bind params are silently ignored if the SQL doesn't reference them. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Two related Wave 2.1.x extensions to the plugin contract closing the last two gaps blocking endpoint-level RBAC for plugin authors. Discovered during evonexus-plugin-nutri Step 3 RBAC decision (split
patients_adminvspatients_clinicalwas needed because the host had no role gate per endpoint).PluginWritableResource.requires_role: Optional[List[str]]field. Handler returns 403 whencurrent_user.roleis not in the list.'admin'always passes (super-user override).readonly_dataauto-injects:current_user_idand:current_user_roleas bind params on every query. Plugins reference them in SQL for server-enforced scoping. Both names are reserved — client requests carrying them in query string get 400 (no identity spoofing).Why
Before this PR, plugin authors had two unsafe options for role-based access:
evonexus-plugin-nutripatients_adminvspatients_clinical) — duplicates schema and still doesn't gate the endpoints themselvesFor
readonly_data, the only scoping option was to declare anutritionist_idparam and hope the UI supplies it correctly —curl ?gets the unfiltered set.This PR closes both with ~25 lines of host code.
Compat
requires_roledefaults toNone(any auth user passes). Auto-injected bind params are silently ignored if SQL doesn't reference them.current_user_idorcurrent_user_roleas a query-string param today.Test plan
tests/backend/test_plugins_rbac_and_scoping.py?current_user_id=2returns 400:current_user_idref still returns all rowstests/backend/suite: 91 passed (2 unrelated cache-test failures pre-existing —_compute_previewsignature drift intest_plugins_preview_endpoint.py)🤖 Generated with Claude Code