From 352eabde3efcefe958f962ecf45f7e97870230cd Mon Sep 17 00:00:00 2001 From: rubenkalath Date: Sat, 28 Nov 2026 11:59:52 -0500 Subject: [PATCH] fix(studio): fetch identity services with redirect: 'manual' The Workers runtime refuses redirect: 'error' ("won't be implemented"), so OIDC discovery, JWKS and token fetches all failed as network errors and Google and OIDC sign-in could not complete. A 3xx answer is not ok, so it is still refused rather than followed. --- .../features/auth/providers/boundedFetch.ts | 4 ++- studio/test/boundedFetchRedirect.test.ts | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 studio/test/boundedFetchRedirect.test.ts diff --git a/studio/src/features/auth/providers/boundedFetch.ts b/studio/src/features/auth/providers/boundedFetch.ts index 60d5694ce..ffcdcd6ec 100644 --- a/studio/src/features/auth/providers/boundedFetch.ts +++ b/studio/src/features/auth/providers/boundedFetch.ts @@ -19,7 +19,9 @@ export const platformFetch: Fetcher = (input, init) => fetch(input, init); export async function fetchJson(fetcher: Fetcher, url: string, init: RequestInit): Promise> { let response: Response; try { - response = await fetcher(url, { ...init, redirect: 'error', signal: AbortSignal.timeout(FETCH_LIMITS.timeoutMs) }); + // `manual`, not `error`: the Workers runtime throws on `redirect: 'error'` ("won't be implemented"), which made + // every discovery, key and token fetch a network failure. A 3xx answer is not ok, so it is still refused below. + response = await fetcher(url, { ...init, redirect: 'manual', signal: AbortSignal.timeout(FETCH_LIMITS.timeoutMs) }); } catch { return err({ kind: 'network' }); } diff --git a/studio/test/boundedFetchRedirect.test.ts b/studio/test/boundedFetchRedirect.test.ts new file mode 100644 index 000000000..3d12a3da4 --- /dev/null +++ b/studio/test/boundedFetchRedirect.test.ts @@ -0,0 +1,27 @@ +// Goal: identity-service fetches work on the Workers runtime, which rejects `redirect: 'error'`, and still refuse +// redirects. Method: call fetchJson with a fetcher that records its init and answers a JSON body or a 302. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { fetchJson } from '../src/features/auth/providers/boundedFetch'; + +test('identity fetches ask for redirect: manual, which the Workers runtime accepts', async () => { + let seen: RequestInit | undefined; + const answer = await fetchJson( + async (_url, init) => { + seen = init; + return Response.json({ issuer: 'https://idp.example' }); + }, + 'https://idp.example/.well-known/openid-configuration', + {}, + ); + assert.equal(seen?.redirect, 'manual'); + assert.deepEqual(answer, { ok: true, value: { issuer: 'https://idp.example' } }); +}); +test('a redirect answer is refused as a status failure', async () => { + const answer = await fetchJson( + async () => new Response(null, { status: 302, headers: { Location: 'https://elsewhere.example/' } }), + 'https://idp.example/jwks', + {}, + ); + assert.deepEqual(answer, { ok: false, error: { kind: 'status', status: 302 } }); +});