diff --git a/packages/core/supabase-js/src/cors.ts b/packages/core/supabase-js/src/cors.ts index 7b8d02025ce..ed4e99a4571 100644 --- a/packages/core/supabase-js/src/cors.ts +++ b/packages/core/supabase-js/src/cors.ts @@ -1,9 +1,10 @@ /** * Canonical CORS configuration for Supabase Edge Functions * - * This module exports CORS headers that stay synchronized with the Supabase SDK. - * When new headers are added to the SDK, they are automatically included here, - * preventing CORS errors in Edge Functions. + * This module exports CORS headers kept in sync with the headers the Supabase + * SDK sends. Using it in Edge Functions prevents CORS preflight errors when the + * SDK adds new headers — update SUPABASE_HEADERS whenever the SDK starts + * sending one (enforced by the unit tests). * * @example Basic usage * ```typescript @@ -34,6 +35,9 @@ * - apikey: Project API key * - content-type: Standard HTTP content type * - x-retry-count: Retry attempt number sent by postgrest-js on retried requests + * - traceparent: W3C trace context sent when `tracePropagation` is enabled + * - tracestate: Vendor-specific trace data sent alongside traceparent + * - baggage: W3C baggage sent alongside traceparent */ const SUPABASE_HEADERS = [ 'authorization', @@ -41,6 +45,9 @@ const SUPABASE_HEADERS = [ 'apikey', 'content-type', 'x-retry-count', + 'traceparent', + 'tracestate', + 'baggage', ].join(', ') /** diff --git a/packages/core/supabase-js/test/unit/cors.test.ts b/packages/core/supabase-js/test/unit/cors.test.ts index 3a923c824cb..9980debdbca 100644 --- a/packages/core/supabase-js/test/unit/cors.test.ts +++ b/packages/core/supabase-js/test/unit/cors.test.ts @@ -16,12 +16,29 @@ describe('CORS Module', () => { it('should include all Supabase custom headers', () => { const allowedHeaders = corsHeaders['Access-Control-Allow-Headers'] - // All 10 Supabase headers must be present - expect(allowedHeaders).toContain('authorization') - expect(allowedHeaders).toContain('x-client-info') - expect(allowedHeaders).toContain('apikey') - expect(allowedHeaders).toContain('content-type') - expect(allowedHeaders).toContain('x-retry-count') + // Pin the exact list: when the SDK starts sending a new header, this + // test must fail until the header is added to SUPABASE_HEADERS — + // otherwise browser preflights break for Edge Functions using corsHeaders. + expect(allowedHeaders.split(', ').sort()).toEqual( + [ + 'authorization', + 'x-client-info', + 'apikey', + 'content-type', + 'x-retry-count', + 'traceparent', + 'tracestate', + 'baggage', + ].sort() + ) + }) + + it('should include the trace context headers sent when tracePropagation is enabled', () => { + const allowedHeaders = corsHeaders['Access-Control-Allow-Headers'] + + expect(allowedHeaders).toContain('traceparent') + expect(allowedHeaders).toContain('tracestate') + expect(allowedHeaders).toContain('baggage') }) it('should include all HTTP methods including OPTIONS', () => {