Skip to content

Commit 3cf17f4

Browse files
committed
fix: sanitize Authorization and apikey headers from supabaseOptions
User-provided supabaseOptions.global.headers could include Authorization or apikey, bypassing verified credentials. Strip both before spreading user headers into the client options.
1 parent 629168d commit 3cf17f4

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/core/create-admin-client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ export function createAdminClient<Database = unknown>(
4141
: Errors[MissingSecretKeyError](name)
4242
}
4343

44+
// Sanitize auth headers — only the service-role key controls Authorization and apikey.
45+
const safeHeaders = { ...supabaseOptions?.global?.headers }
46+
delete safeHeaders.Authorization
47+
delete safeHeaders.apikey
48+
4449
// supabaseOptions uses `string` for schema; createClient<Database> expects a narrower type.
4550
return createClient<Database>(resolved.url, secretKey, {
4651
...supabaseOptions,
4752
// Stripped — token injection is managed via the service-role key.
4853
accessToken: undefined,
4954
global: {
5055
...supabaseOptions?.global,
56+
headers: safeHeaders,
5157
},
5258
auth: {
5359
...supabaseOptions?.auth,

src/core/create-context-client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export function createContextClient<Database = unknown>(
4545
: Errors[MissingPublishableKeyError](name)
4646
}
4747

48+
// Sanitize auth headers — only verified credentials control Authorization and apikey.
49+
const safeHeaders = { ...supabaseOptions?.global?.headers }
50+
delete safeHeaders.Authorization
51+
delete safeHeaders.apikey
52+
4853
// supabaseOptions uses `string` for schema; createClient<Database> expects a narrower type.
4954
return createClient<Database>(resolved.url, anonKey, {
5055
...supabaseOptions,
@@ -53,7 +58,7 @@ export function createContextClient<Database = unknown>(
5358
global: {
5459
...supabaseOptions?.global,
5560
headers: {
56-
...supabaseOptions?.global?.headers,
61+
...safeHeaders,
5762
...(token ? { Authorization: `Bearer ${token}` } : {}),
5863
},
5964
},

0 commit comments

Comments
 (0)