test(supabase): avatar e2e clients refuse HTTP redirects
The suite's supabase-js clients followed redirects by default, so a 3xx from the sandbox gateway would have carried the apikey header to another origin. `noRedirectFetch` (`redirect: 'error'`) is passed as `global.fetch` of both client factories; a regression test with two loopback servers proves REST, auth and Storage calls stop at the 302. Live proof j and a second 5/5 run are in the audit log; no production client changes.
This commit is contained in:
1 parent
e8da0d96d9
commit
d3dfd03213
7 files changed
+147
-16
No files matched your search
@@ -15,6 +15,7 @@ import { createHash, randomBytes } from 'node:crypto'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { deflateSync } from 'node:zlib'
|
||||
import { createClient, type SupabaseClient } from '@supabase/supabase-js'
|
||||
import { noRedirectFetch } from './noRedirectFetch'
|
||||
import {
|
||||
beginAvatarUpload,
|
||||
confirmAssetUpload,
|
||||
@@ -52,6 +53,7 @@ type Client = SupabaseClient<Database>
|
||||
function anonClient(): Client {
|
||||
return createClient<Database>(SANDBOX_URL, ANON ?? '', {
|
||||
auth: { persistSession: false, autoRefreshToken: false },
|
||||
global: { fetch: noRedirectFetch },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -65,6 +67,7 @@ async function signedIn(email: string): Promise<Client> {
|
||||
function serviceClient(): Client {
|
||||
return createClient<Database>(SANDBOX_URL, SERVICE ?? '', {
|
||||
auth: { persistSession: false, autoRefreshToken: false },
|
||||
global: { fetch: noRedirectFetch },
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* The suite's fetch: a 3xx answer is an error, never a request to another
|
||||
* origin (owner decision 2026-11-02). supabase-js hands `global.fetch` to its
|
||||
* auth, REST and Storage calls and spreads the caller's init before ours runs,
|
||||
* so `redirect` set here is final: nothing restores `follow`.
|
||||
*/
|
||||
export const noRedirectFetch: typeof fetch = (input, init) =>
|
||||
fetch(input, { ...init, redirect: 'error' })
|
||||
Reference in new issue
Block a user