Skip to content

Sign the proxy token (x-mesh-token / x-studio-token) with a public key and publish a JWKS #8440

Open

Description

@JonasJesus42

Problem

Downstream MCP apps can't verify the per-user proxy token that Studio sends (x-mesh-token / x-studio-token).

  • issueStudioToken (apps/api/src/auth/jwt.ts) signs it with HS256 and the shared STUDIO_JWT_SECRET. Only the holder of that secret can verify the token, and the holder can also mint tokens for any user. Studio can't hand that secret to apps.
  • @decocms/runtime builds ensureAuthenticated() from decodeJwt, without checking the signature (packages/runtime/src/index.ts, withBindings).

So the only thing keeping a caller from claiming to be someone else is the app's bearer. Anyone who holds a connection's bearer can send an unsigned token with any user.email and the app accepts it as that user.

How we work around it today (decocms/ops-control-plane#319)

Our Workers send the token back to Studio as a bearer on GET /api/_me/organizations. A 401 means the token is forged or expired. A JSON response listing the token's org means it's genuine. Yeses are cached for up to 5 minutes.

This works, but it costs:

  • an extra round trip to Studio for every new token;
  • an outage for us whenever Studio is down (we fail closed);
  • a dependency on an endpoint that wasn't built for this.

Ask

  1. Sign the proxy token with an asymmetric key (EdDSA or RS256), with a kid in the header and iss/aud claims. aud should be the connectionId, so a token minted for one app can't be replayed against another.
  2. Publish the public keys at a stable JWKS URL, e.g. https://studio.decocms.com/.well-known/jwks.json, and keep old keys there during rotation.
  3. In @decocms/runtime, verify the token with jwtVerify + createRemoteJWKSet before populating MESH_REQUEST_CONTEXT. Every MCP app then gets verified identity for free.

The AI Gateway token (mintGatewayJwt) can keep using HS256. This ask is only about the token that goes to downstream apps.

Once this ships, our withVerifiedCaller becomes a local jwtVerify that also checks aud = our connection.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions