SecurityMulti-Tenancy

User Isolation

Strict tenant isolation through server-derived caller identity, per-grant guild allowlists, global blacklist checks, and injection-resistant database queries.

Server-derived caller identity (ctx.userId)

Every authenticated request to POST /mcp, GET /mcp, or DELETE /mcp runs through requireMcpBearerAuth before entering the MCP server dispatcher. The middleware hashes the Authorization Bearer token with SHA-256, retrieves the active McpAccessToken record from taicket_mcp, and binds ctx.userId exclusively from tokenRecord.userId.

No MCP tool schema accepts a callerUserId, actorId, or sessionToken argument. Even if a prompt instructs the model to pass another Discord user ID inside tool input, strict Zod schemas reject unknown keys and authorization checks always evaluate ctx.userId.

Immutable request context built by requireMcpBearerAuthtypescript
export interface VerifiedMcpContext {
  readonly userId: string;
  readonly grantId: string;
  readonly clientId: string;
  readonly clientName: string;
  readonly authKind: 'oauth' | 'pat';
  readonly scopes: readonly McpScope[];
  readonly allowedGuildIds: readonly string[] | null;
  readonly clientIp: string;
}

Per-grant guild allowlist enforcement

Both /oauth/consent and the /account PAT generator let the server manager restrict a client token to specific Discord servers (allowedGuildIds: string[]) or allow all servers they can currently manage (allowedGuildIds: null).

  • Pre-RBAC short-circuit:: When allowedGuildIds is an explicit array, any tool invocation targeting a guildId outside that array returns FORBIDDEN immediately, before querying Taicket databases or Discord REST APIs.
  • Discovery filtering:: get_discord_servers intersects the user live manageable servers with allowedGuildIds so out-of-scope servers are never leaked to a restricted client.
  • No scope widening on refresh:: Refreshing an OAuth token copies the exact scopes and allowedGuildIds from the parent grant. Adding another server requires a fresh user-approved authorization flow.

BotBlacklist and setup preview ownership

Before executing any guild-scoped or account-scoped tool, the security guard checks BotBlacklist in the main Taicket database for both ctx.userId and the target guildId. Globally blacklisted users and guilds are denied immediately with FORBIDDEN.

Multi-step setup previews stored in McpSetupPreview are bound to userId and guildId. Calling apply_setup or opening /oauth/approve-action?id=<planId> requires both preview.userId === ctx.userId (or session.userId) and preview.guildId within the caller allowedGuildIds. One user can never inspect, approve, or apply another user preview plan even if they guess a planId.

Query hygiene and zero cross-tenant leakage

  • Mandatory guildId predicate:: Every read and write across the 10 Taicket databases scopes queries explicitly to the validated Discord snowflake guildId (17 to 20 digits).
  • Zero MongoDB operator injection:: All tool parameters are parsed through strict Zod primitives and enums. Raw query objects or dollar-prefixed operators ($where, $ne, $regex, $gt) cannot pass validation.
  • User-scoped audit visibility:: The /account audit viewer and get_setup_status recent change summaries filter strictly by userId and authorized guildId so tokens cannot observe other administrators sessions.

Related documentation