Files
gabrielvidal b7ce5a42df fix(mcp): number matching for the phone approval, strict redirect URIs, atomic approve, per-address caps
An unsolicited approval push gave whoever parked the request an owner token on
one tap; `https://evil\@claude.ai/cb` read as claude.ai to the hub and went to
evil in the browser. Token lifecycle: a revoked refresh token ends its
connection, reuse after the grace too, 12 records per connection, a deleted
guest loses theirs.
Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-15 15:23:05 +01:00

41 lines
1.7 KiB
Python

"""Who an MCP connection's calls are, inside the hub.
The tools reach this backend's own API over loopback — the owner, to the
gate. A **guest's** connection adds :data:`AS_USER_HEADER`, and the gate
(``core/auth.py``) answers the call as that guest: a downgrade of a caller
already trusted, never an upgrade, exactly like the guest CLI's
``X-AIA-As-Session`` (``users/cli.py``). The routes are the CLI's
(:data:`users.cli.CLI_ROUTES`), and the handlers filter by ownership as for
their browser.
"""
from __future__ import annotations
from core.i18n import tr
from users.caller import OWNER, OWNER_ID, Caller, guest_from_record
from users.cli import Refused
AS_USER_HEADER = "x-aia-mcp-user"
def mcp_caller(deps, uid: str) -> Caller:
"""The caller a connection for ``uid`` is. :class:`Refused` when that
guest is gone, disabled, locked out, or no longer may use AI apps."""
uid = (uid or "").strip()
if uid == OWNER_ID:
return OWNER
if not uid: # a connection with nobody behind it is nobody's — never the owner's
raise Refused(403, "this connection has no user")
u = deps.users.active(uid)
if not u:
raise Refused(403, "this guest is disabled")
guest = guest_from_record(u)
if deps.security_state.guests_locked():
raise Refused(403, {"message": tr(guest.lang, "guest access is paused for now"),
"kind": "guests_locked"})
if not guest.mcp:
raise Refused(403, {"message": tr(guest.lang, "AI apps aren't open to you — "
"the owner can switch them on"),
"kind": "guest_mcp"})
return guest