From c6862f6c2926d5018f8429d2f2ebee46f878695c Mon Sep 17 00:00:00 2001 From: geoffg-sentry <165922362+geoffg-sentry@users.noreply.github.com> Date: Thu, 30 Oct 2025 13:20:19 -0400 Subject: [PATCH 1/6] fix(oauth): RFC8707 resource param validation --- .../src/server/oauth/authorize.test.ts | 220 +++++++++++++++ .../src/server/oauth/callback.test.ts | 265 ++++++++++++++++++ .../src/server/oauth/helpers.test.ts | 257 ++++++++++++++++- .../src/server/oauth/helpers.ts | 61 ++++ .../src/server/oauth/routes/authorize.ts | 54 +++- .../src/server/oauth/routes/callback.ts | 28 +- 6 files changed, 879 insertions(+), 6 deletions(-) diff --git a/packages/mcp-cloudflare/src/server/oauth/authorize.test.ts b/packages/mcp-cloudflare/src/server/oauth/authorize.test.ts index e9dfe788..19dc7e07 100644 --- a/packages/mcp-cloudflare/src/server/oauth/authorize.test.ts +++ b/packages/mcp-cloudflare/src/server/oauth/authorize.test.ts @@ -196,4 +196,224 @@ describe("oauth authorize routes", () => { expect(text).toBe("Invalid request"); }); }); + + describe("Resource parameter validation (RFC 8707)", () => { + describe("GET /oauth/authorize", () => { + it("should allow request without resource parameter (backward compatibility)", async () => { + mockOAuthProvider.parseAuthRequest.mockResolvedValueOnce({ + clientId: "test-client", + redirectUri: "https://example.com/callback", + scope: ["read"], + }); + mockOAuthProvider.lookupClient.mockResolvedValueOnce({ + clientId: "test-client", + clientName: "Test Client", + redirectUris: ["https://example.com/callback"], + }); + + const request = new Request("http://localhost/oauth/authorize", { + method: "GET", + }); + const response = await app.fetch(request, testEnv as Env); + + // Should proceed normally (render approval dialog) + expect(response.status).toBe(200); + const html = await response.text(); + expect(html).toContain("