diff --git a/src/platform/cloudflare/auth.server.ts b/src/platform/cloudflare/auth.server.ts index ac02e63..b5636df 100644 --- a/src/platform/cloudflare/auth.server.ts +++ b/src/platform/cloudflare/auth.server.ts @@ -9,15 +9,18 @@ export const authPlatform: AuthPlatform = { // reach a private network. A Worker has no private network to reach: its // fetches leave through Cloudflare to the public internet. The rest of the // contract (HTTPS, GET or HEAD, redirects returned unfollowed) holds here. + // CIMD asks for `redirect: 'error'`, which workerd's Request rejects, so + // the redirect is replaced by `manual`: a 3xx comes back as a non-200 that + // CIMD refuses. fetchClientMetadataResource: (input, init) => { - const request = new Request(input, init) + const request = new Request(input, { ...init, redirect: 'manual' }) if (new URL(request.url).protocol !== 'https:') { throw new TypeError('CIMD metadata must be fetched over HTTPS') } if (request.method !== 'GET' && request.method !== 'HEAD') { throw new TypeError('CIMD metadata is fetched with GET or HEAD only') } - return fetch(request, { redirect: 'manual' }) + return fetch(request) }, // Comparing the schema takes four D1 round trips, and every new isolate // would pay them before reading a session. The configuration only changes