⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(mcp): accept opaque OAuth state within URL bounds
Tina491a93f2fa7
diff --git a/apps/api/src/mcp/schemas.ts b/apps/api/src/mcp/schemas.tsindex 41a5020a2..79ec6d9e2 100644--- a/apps/api/src/mcp/schemas.ts+++ b/apps/api/src/mcp/schemas.ts@@ -55,7 +55,10 @@ export const authorizationQuerySchema = z.object({description: "PKCE challenge; only S256 is accepted.",}),code_challenge_method: z.literal("S256"),- state: z.string().max(1024).optional(),+ state: z.string().optional().openapi({+ description:+ "Opaque client state, returned unchanged. The complete authorization URL is limited to 8 KiB.",+ }),});export const authorizationRequestParamSchema = z.object({diff --git a/apps/docs/openapi.json b/apps/docs/openapi.jsonindex 8907e27be..a31e123d7 100644--- a/apps/docs/openapi.json+++ b/apps/docs/openapi.json@@ -8599,9 +8599,10 @@{"schema": {"type": "string",- "maxLength": 1024+ "description": "Opaque client state, returned unchanged. The complete authorization URL is limited to 8 KiB."},"required": false,+ "description": "Opaque client state, returned unchanged. The complete authorization URL is limited to 8 KiB.","name": "state","in": "query"}diff --git a/tests/api-integration/mcp-oauth-bounds.test.ts b/tests/api-integration/mcp-oauth-bounds.test.tsindex e1f27259c..c2a11df70 100644--- a/tests/api-integration/mcp-oauth-bounds.test.ts+++ b/tests/api-integration/mcp-oauth-bounds.test.ts@@ -66,7 +66,6 @@ describe("MCP OAuth HTTP resource bounds", () => {it("bounds authorization fields and the raw URL before any request row is created", async () => {const client = await registerClient({ redirectUris: [redirectUri] });for (const [field, value, status] of [- ["state", "s".repeat(1025), 400],["state", "s".repeat(9000), 414],["code_challenge", "x".repeat(44), 400],["client_id", "x".repeat(129), 400],@@ -90,12 +89,50 @@ describe("MCP OAuth HTTP resource bounds", () => {redirect_uri: redirectUri,code_challenge: challenge,code_challenge_method: "S256",- state: "s".repeat(1024),+ state: "s".repeat(6000),});expect((await mcp.request(`/mcp/authorize?${query}`)).status).toBe(302);expect(await total("request")).toBe(1);});+ it.each([true, false])(+ "returns long opaque state unchanged after consent (approved=%s)",+ async (approved) => {+ const { user } = await createWorkspaceMember();+ mockAuthenticatedSession(user);+ const client = await registerClient({ redirectUris: [redirectUri] });+ const state = `${"s".repeat(2048)}+/%=& ü`;+ const query = new URLSearchParams({+ response_type: "code",+ client_id: client.clientId,+ redirect_uri: redirectUri,+ code_challenge: challenge,+ code_challenge_method: "S256",+ state,+ });+ const response = await mcp.request(`/mcp/authorize?${query}`);+ expect(response.status).toBe(302);+ const consentUrl = new URL(response.headers.get("location")!);+ const id = consentUrl.searchParams.get("request_id");+ expect(await getAuthorizationRequest(id!)).toHaveProperty("state", state);++ const decision = await post(+ `/mcp/authorize/request/${id}`,+ { approved },+ { origin: "http://localhost:5173" },+ );+ expect(decision.status).toBe(200);+ const result = await decision.json();+ const redirect = new URL(result.redirect);+ expect(redirect.searchParams.get("state")).toBe(state);+ expect(redirect.searchParams.has("code")).toBe(approved);+ expect(redirect.searchParams.get("error")).toBe(+ approved ? null : "access_denied",+ );+ expect(await getAuthorizationRequest(id!)).toBeNull();+ },+ );+it("returns a retryable JSON error at the durable registration limit", async () => {await db.insert(mcpOauthStateTable).values({kind: "rate",