Skip to content

fix(mcp): gate chat ACL on admin role, not username "admin" - #4658

Merged
vybe merged 2 commits into
devfrom
feature/4654-mcp-chat-acl-role-check
Nov 19, 2026
Merged

vybe merged 2 commits into
devfrom
feature/4654-mcp-chat-acl-role-check

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Summary

  • chat.ts:checkAgentAccess previously bypassed ACL with callerOwner === "admin" || authContext.userId === "admin" — a string comparison against the literal username, not a role check
  • A renamed admin lost MCP chat tool access; any account named "admin" gained it regardless of role
  • /api/mcp/validate now returns user_role from the users table; McpAuthContext gets a userRole field; the bypass is now authContext.userRole === "admin"

Files changed

File Change
src/backend/db/mcp_keys.py add users.c.role to the validation query, return as user_role
src/backend/routers/mcp_keys.py pass user_role through the HTTP response
src/mcp-server/src/types.ts add userRole?: string to McpAuthContext
src/mcp-server/src/server.ts populate userRole from validation result
src/mcp-server/src/tools/chat.ts use userRole === "admin" for the bypass
src/mcp-server/src/tools/chat.admin-acl.test.ts regression test (2 cases)

Test plan

  • chat.admin-acl.test.ts — username "admin" with role "user" is denied; username "superadmin" with role "admin" is allowed (150/150 chat+access tests pass)

Closes #4654

🤖 Generated with Claude Code

Trinity Agent (trinity) and others added 2 commits November 19, 2026 14:46
…4654)

/api/mcp/validate now returns user_role alongside the existing fields.
McpAuthContext gains a userRole field populated at auth time.
checkAgentAccess in chat.ts uses authContext.userRole === "admin" instead
of the previous username string comparison, so a renamed admin retains
access and an account named "admin" without the role is refused.

Regression test: chat.admin-acl.test.ts (2 cases).

Closes #4654

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… assertion (#4654)

The validate response's user_role and the server's hand-off into the auth
context were unpinned: deleting either left every test green while every
admin lost the bypass. Also notes on the type that userRole is the owner's
role on every scope, and documents the field.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vybe
vybe force-pushed the feature/4654-mcp-chat-acl-role-check branch from 39433f7 to bf69e89 Compare November 19, 2026 14:50
@vybe

vybe commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-11-19): validated at 39433f75e. The check itself holds. Run against the real function for every scope with an admin-role owner: an agent-scoped key gains nothing (it returns through the permission-edge check before the changed line, as on dev), connector, ops, portal_delegate, unknown and missing scopes all get the uniform denial, and a user-role account named admin is refused. Two mechanical problems kept it from riding as it was, and both are fixed on the branch (force-pushed, now bf69e8928):

  1. The branch was stacked on feat(subscriptions): name the enforcing limit in the headroom payload (#4656) #4657's commit (b54c6dfb4), so three feat(subscriptions): name the enforcing limit in the subscription headroom payload #4656 files would have landed under this title. Rebased onto dev without it; the bug(mcp): MCP chat tools ACL checks the username "admin" instead of the admin role #4654 commit is unchanged in content and is now 59f94c868.
  2. Nothing pinned the role reaching the check. Deleting userRole: result.user_role in server.ts, or user_role in db/mcp_keys.py or routers/mcp_keys.py, left every test green while every admin lost the bypass. Added tests/unit/test_4654_mcp_validate_user_role.py (the db function and the /api/mcp/validate route, admin and user owners, user and agent keys, NULL role) and src/mcp-server/src/validate-user-role.test.ts (the real authenticate callback). Each goes red when its line is deleted.

Also in that commit: the denial assertion in chat.admin-acl.test.ts now checks the exact uniform reason and that the owner's name is absent; a comment on types.ts says userRole is the owner's role on every scope and must not be read before the scope check; and mcp-orchestration.md documents the field. Not run here: the new backend test's PostgreSQL branch.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train (2026-11-19): validated at bf69e89; batch green on #4667.

@vybe
vybe merged commit c9f6efe into dev Nov 19, 2026
28 checks passed
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.

2 participants