Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: filter out unused keys when construct api request headers

phamhieub6ccc85956f0
diff --git a/studio/lib/api/apiHelpers.ts b/studio/lib/api/apiHelpers.ts
index f2689213b13..ba1b5f60525 100644
--- a/studio/lib/api/apiHelpers.ts
+++ b/studio/lib/api/apiHelpers.ts
@@ -3,10 +3,23 @@ import AES from 'crypto-js/aes'
import Utf8 from 'crypto-js/enc-utf8'
import { IS_PLATFORM } from 'lib/constants'
-export function constructHeaders(headers: any) {
+/**
+ * Construct headers for api request.
+ * For platform, it will include apiKey into the provided headers.
+ *
+ * To prevent relay frontend request headers like useragent, referrer... into the middleware requests.
+ * We will only keep the header keys that are in this list: Accept, Authorization, Content-Type, x-connection-encrypted
+ */
+export function constructHeaders(headers: { [prop: string]: any }) {
if (headers) {
+ const cleansedHeaders = {
+ Accept: headers.Accept,
+ Authorization: headers.Authorization,
+ 'Content-Type': headers['Content-Type'],
+ 'x-connection-encrypted': headers['x-connection-encrypted'],
+ }
return {
- ...headers,
+ ...cleansedHeaders,
...(IS_PLATFORM
? { apiKey: `${process.env.READ_ONLY_API_KEY}` }
: { apiKey: `${process.env.SUPABASE_SERVICE_KEY}` }),