Enforce ActiveAdmin authorization on list_resources and query - #6
Merged
Conversation
The read tools ignored the resource namespace's authorization adapter, so any authenticated MCP user could list and Ransack-query every registered resource regardless of their admin abilities — only `update` was gated. Route `list_resources` and `query` through the same adapter as the admin UI (extracted into a shared `Authorization` wrapper that `RecordUpdater` now also uses): unreadable resources are hidden and refused, and query results are scoped via `scope_collection`. `query` also strips the same sensitive attributes that `list_resources` already omits. With ActiveAdmin's default adapter every check passes, so applications without an authorization adapter are unaffected. Co-Authored-By: Claude Opus 4.8 (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.
Problem
🤖 The read tools bypassed authorization entirely.
RequestHandler#tool_queryand#tool_list_resourcesnever consulted the resource namespace's ActiveAdmin authorization adapter — onlyupdate(viaRecordUpdater) did. So any authenticated MCP user could list every registered resource and Ransack-query every row, regardless of the abilities their admin role grants them (CanCanCan, Pundit, etc.).@current_userwas accepted by the constructor and then ignored on the read path.Two aggravating details, both addressed here:
ResourceRegistry.sensitive_attributes(encrypted_password,password_digest,reset_password_token,api_key,secret) was applied only to thelist_resourcesschema listing — not toquery'srecords.as_json, so those columns leaked through query.limitis capped at 100 per call, butqis arbitrary Ransack, so the whole table is reachable by paging through filters.Reported downstream as OLIOEX/api#14286 (from OLIOEX/api#14273).
Fix
ActiveadminMcp::Authorizationwrapper around ActiveAdmin's per-namespace authorization adapter.RecordUpdaternow uses it too (single source of truth).querynow:authorized?(:read, model)), andscope_collection, so the MCP user only sees records they could see in the UI, andlist_resourcesalready omits.list_resourcesnow hides resources the current user may not read.Driven entirely by
config.namespace.authorization_adapter, so this is generic across any ActiveAdmin project. With ActiveAdmin's default adapter every check passes and collections are returned unchanged — applications without an authorization adapter are unaffected. Projects wiring CanCanCan viaconfig.cancan_ability_class = "..."get their ability enforced on reads, scoping, and writes alike.Tests
spec/activeadmin_mcp/authorization_spec.rbfor the wrapper (build-from-class and build-from-string, delegation, default:readaction).request_handler_spec: query is refused when unauthorized, is scoped through the adapter before limiting, and strips sensitive attributes;list_resourcesreturns only authorized resources.resource_registry_spec: coverage for the new public.resources.record_updater_specunchanged and green (refactor preserves behaviour).Full suite green (71 examples, 0 failures).
Docs
README "How it works" + tools table and the in-code MCP tool descriptions updated to state reads are authorized/scoped;
CHANGELOG.mdgains a Security entry under[Unreleased].Released as
0.0.3; consumed downstream in OLIOEX/api#14289.🤖 Generated with Claude Code