The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
studio: flip executeSql signature to SafeSqlFragment (7/7) (#46007)
Charis12869fcd9fbb
diff --git a/apps/studio/data/sql/execute-sql-query.ts b/apps/studio/data/sql/execute-sql-query.tsindex 337665f9dda..ebb91391401 100644--- a/apps/studio/data/sql/execute-sql-query.ts+++ b/apps/studio/data/sql/execute-sql-query.ts@@ -1,4 +1,8 @@-import { ROLE_IMPERSONATION_NO_RESULTS, ROLE_IMPERSONATION_SQL_LINE_COUNT } from '@supabase/pg-meta'+import {+ ROLE_IMPERSONATION_NO_RESULTS,+ ROLE_IMPERSONATION_SQL_LINE_COUNT,+ SafeSqlFragment,+} from '@supabase/pg-meta'import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'import { QueryKey, useQuery } from '@tanstack/react-query'@@ -24,7 +28,7 @@ export const COST_THRESHOLD_ERROR = 'Query cost exceeds threshold'export type ExecuteSqlVariables = {projectRef?: stringconnectionString?: string | null- sql: string+ sql: SafeSqlFragmentqueryKey?: QueryKeyhandleError?: (error: ResponseError) => { result: any }isRoleImpersonationEnabled?: booleandiff --git a/apps/studio/lib/ai/tools/studio-tools.ts b/apps/studio/lib/ai/tools/studio-tools.tsindex 8e7667b6428..1825636363a 100644--- a/apps/studio/lib/ai/tools/studio-tools.ts+++ b/apps/studio/lib/ai/tools/studio-tools.ts@@ -1,3 +1,4 @@+import { acceptUntrustedSql, untrustedSql } from '@supabase/pg-meta'import { tool } from 'ai'import { z } from 'zod'@@ -68,8 +69,11 @@ export const getStudioTools = (ctx: StudioToolsContext = {}) => {inputSchema: executeSqlInputSchema,needsApproval: true,execute: async ({ sql }) => {+ // The `needsApproval: true` gate on this tool means the user has+ // explicitly approved this AI-generated SQL before execute runs —+ // that approval is the user gesture that promotes untrusted to safe.const { result } = await executeSql(- { projectRef, connectionString, sql },+ { projectRef, connectionString, sql: acceptUntrustedSql(untrustedSql(sql)) },undefined,authHeaders)