@devries-cameron20 / t3code-1 / commits / 6a510c4894
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): MCP OAuth rejects a resource with an empty fragment (#35808)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 14, 2026 at 20:49 UTC 6a510c48947b87edbe0a18186f2ca36ea369b86f
2 files changed +14 -1
apps/server/src/auth/McpOAuth.test.ts
+11
@@ -292,6 +292,17 @@ it.effect("registers loopback and https clients and never redirects for an unver
292 expect(unregistered.status).toBe(400);
293 expect(unregistered.headers.get("location")).toBeNull();
294
295 + for (const resource of [`${ORIGIN}/mcp#section`, `${ORIGIN}/mcp#`]) {
296 + const wrongTarget = yield* handler(
297 + at(
298 + `/oauth/mcp/authorize?${new URLSearchParams({ ...authorizeParams(clientId), resource })}`,
299 + ),
300 + );
301 + expect(wrongTarget.status).toBe(302);
302 + const location = new URL(wrongTarget.headers.get("location")!, ORIGIN);
303 + expect(location.searchParams.get("error"), resource).toBe("invalid_target");
304 + }
305 +
306 const query = new URLSearchParams(authorizeParams(clientId)).toString();
307 const handoff = yield* handler(at(`/oauth/mcp/authorize?${query}`));
308 expect(handoff.status).toBe(302);
apps/server/src/auth/McpOAuth.ts
+3 -1
@@ -134,9 +134,11 @@ export const redirectMatches = (registered: string, presented: string): boolean
134
135 const sameResource = (urls: McpOAuthUrls, presented: string | undefined): boolean => {
136 if (presented === undefined) return true;
137 + // URL.hash misses empty fragments, which RFC 8707 §2 also forbids.
138 + if (presented.includes("#")) return false;
139 try {
140 const url = new URL(presented);
139 - return url.hash === "" && `${url.origin}${url.pathname.replace(/\/+$/u, "")}` === urls.resource;
141 + return `${url.origin}${url.pathname.replace(/\/+$/u, "")}` === urls.resource;
142 } catch {
143 return false;
144 }