Skip to content

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

fix(studio): escape SQL identifiers in policy create query (#45181)

oniani191f1d95a02ba
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyEditorPanel/PolicyEditorPanel.utils.ts b/apps/studio/components/interfaces/Auth/Policies/PolicyEditorPanel/PolicyEditorPanel.utils.ts
index ba3c1e73b10..bd8b9c8cbd3 100644
--- a/apps/studio/components/interfaces/Auth/Policies/PolicyEditorPanel/PolicyEditorPanel.utils.ts
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyEditorPanel/PolicyEditorPanel.utils.ts
@@ -1,3 +1,4 @@
+import { ident } from '@supabase/pg-meta/src/pg-format'
import type { PostgresPolicy } from '@supabase/postgres-meta'
import { isEqual } from 'lodash'
@@ -65,7 +66,7 @@ export const generateCreatePolicyQuery = ({
using?: string
check?: string
}) => {
- const querySkeleton = `create policy "${name}" on "${schema}"."${table}" as ${behavior} for ${command} to ${roles}`
+ const querySkeleton = `create policy ${ident(name)} on ${ident(schema)}.${ident(table)} as ${behavior} for ${command} to ${roles}`
const query =
command === 'insert'
? `${querySkeleton} with check (${check});`