Serve MCP and hooks with a secret through the portal tunnel
The connector now serves /mcp, its OAuth documents and /hooks/ besides /api/v1/, refuses any dot segment (httpx resolves them, which carried /api/v1/../../mcp onto the MCP mount), addresses calls to the hub's host, and bridges served sockets by calling the app with a websocket scope. A hook without a secret answers the tunnel with the 404 (or 1008) of a wrong secret. Requests through the hub get the hub's issuer, resource and consent page in the OAuth metadata and the 401, and the MCP host check admits the hub while enrolled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgBfkm4rCmtd1T4vHWjEPx
This commit is contained in:
@@ -42,6 +42,7 @@ from fluksio.api.deps import (
|
||||
get_current_active_superuser,
|
||||
get_current_user,
|
||||
)
|
||||
from fluksio.cloud import config as cloud_config
|
||||
from fluksio.core import security
|
||||
from fluksio.core.config import settings
|
||||
from fluksio.models import (
|
||||
@@ -301,13 +302,22 @@ def authorize_validate(
|
||||
|
||||
@router.post("/authorize", response_model=OAuthAuthorizeResponse)
|
||||
def authorize(
|
||||
request: Request,
|
||||
body: OAuthAuthorizeRequest,
|
||||
current_user: CurrentUser,
|
||||
session: SessionDep,
|
||||
) -> Any:
|
||||
"""Approve a client, on behalf of the signed-in user."""
|
||||
"""Approve a client, on behalf of the signed-in user.
|
||||
|
||||
Through the hub the endpoint is the one there, which is the resource an
|
||||
agent that came that way asks for.
|
||||
"""
|
||||
if not settings.MCP_ENABLED:
|
||||
return _error("access_denied", "The MCP endpoint is switched off.", 403)
|
||||
resources = {settings.mcp_resource}
|
||||
base = cloud_config.portal_base(request.headers)
|
||||
if base is not None:
|
||||
resources.add(f"{base}/mcp")
|
||||
|
||||
client = _load_client(session, body.client_id)
|
||||
if client is None:
|
||||
@@ -318,7 +328,7 @@ def authorize(
|
||||
return _error("invalid_request", "PKCE must use S256.")
|
||||
if not _PKCE_RE.match(body.code_challenge):
|
||||
return _error("invalid_request", "Malformed code challenge.")
|
||||
if body.resource and body.resource.rstrip("/") != settings.mcp_resource:
|
||||
if body.resource and body.resource.rstrip("/") not in resources:
|
||||
return _error("invalid_target", "Unknown resource.")
|
||||
|
||||
code = secrets.token_urlsafe(32)
|
||||
|
||||
Reference in New Issue
Block a user