Skip to content

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

Fix impersonation and searching users escape single quote (#32603)

Joshen Lim394e8302f8c3
diff --git a/apps/studio/components/ui/AlertError.tsx b/apps/studio/components/ui/AlertError.tsx
index 95abda1deb3..6c073228b10 100644
--- a/apps/studio/components/ui/AlertError.tsx
+++ b/apps/studio/components/ui/AlertError.tsx
@@ -1,8 +1,13 @@
import Link from 'next/link'
import type { ResponseError } from 'types'
-import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'
-import { WarningIcon } from 'ui'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ WarningIcon,
+} from 'ui'
export interface AlertErrorProps {
projectRef?: string
@@ -35,7 +40,7 @@ const AlertError = ({
return (
<Alert_Shadcn_ className={className} variant="warning" title={subject}>
{showIcon && <WarningIcon className="h-4 w-4" strokeWidth={2} />}
- <AlertTitle_Shadcn_>{subject}</AlertTitle_Shadcn_>
+ <AlertTitle_Shadcn_ className="text-foreground">{subject}</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_ className="flex flex-col gap-3 break-words">
<div>
{error?.message && <p className="text-left">Error: {formattedErrorMessage}</p>}
diff --git a/apps/studio/data/auth/users-count-query.ts b/apps/studio/data/auth/users-count-query.ts
index 927bb95ad2b..165ee970800 100644
--- a/apps/studio/data/auth/users-count-query.ts
+++ b/apps/studio/data/auth/users-count-query.ts
@@ -27,8 +27,10 @@ const getUsersCountSql = ({
const baseQueryCount = `select count(*) from auth.users`
if (hasValidKeywords) {
+ // [Joshen] Escape single quotes properly
+ const formattedKeywords = keywords.replaceAll("'", "''")
conditions.push(
- `id::text ilike '%${keywords}%' or email ilike '%${keywords}%' or phone ilike '%${keywords}%'`
+ `id::text ilike '%${formattedKeywords}%' or email ilike '%${formattedKeywords}%' or phone ilike '%${formattedKeywords}%'`
)
}
diff --git a/apps/studio/data/auth/users-infinite-query.ts b/apps/studio/data/auth/users-infinite-query.ts
index dfba22c23a4..04649cbb885 100644
--- a/apps/studio/data/auth/users-infinite-query.ts
+++ b/apps/studio/data/auth/users-infinite-query.ts
@@ -44,8 +44,10 @@ export const getUsersSQL = ({
const baseQueryUsers = `select * from auth.users`
if (hasValidKeywords) {
+ // [Joshen] Escape single quotes properly
+ const formattedKeywords = keywords.replaceAll("'", "''")
conditions.push(
- `id::text like '%${keywords}%' or email like '%${keywords}%' or phone like '%${keywords}%'`
+ `id::text like '%${formattedKeywords}%' or email like '%${formattedKeywords}%' or phone like '%${formattedKeywords}%'`
)
}
diff --git a/apps/studio/lib/role-impersonation.ts b/apps/studio/lib/role-impersonation.ts
index f213cc5d0b7..23f0eeb0c3a 100644
--- a/apps/studio/lib/role-impersonation.ts
+++ b/apps/studio/lib/role-impersonation.ts
@@ -68,7 +68,7 @@ function getPostgrestRoleImpersonationSql(projectRef: string, role: PostgrestImp
return /* SQL */ `
select set_config('role', '${role.role}', true),
- set_config('request.jwt.claims', '${JSON.stringify(claims)}', true),
+ set_config('request.jwt.claims', '${JSON.stringify(claims).replaceAll("'", "''")}', true),
set_config('request.method', 'POST', true),
set_config('request.path', '/impersonation-example-request-path', true),
set_config('request.headers', '{"accept": "*/*"}', true);
diff --git a/apps/studio/pages/project/[ref]/index.tsx b/apps/studio/pages/project/[ref]/index.tsx
index a1ec371cf56..0f152c826f5 100644
--- a/apps/studio/pages/project/[ref]/index.tsx
+++ b/apps/studio/pages/project/[ref]/index.tsx
@@ -10,6 +10,7 @@ import ServiceStatus from 'components/interfaces/Home/ServiceStatus'
import { ProjectPausedState } from 'components/layouts/ProjectLayout/PausedState/ProjectPausedState'
import { ProjectLayoutWithAuth } from 'components/layouts/ProjectLayout/ProjectLayout'
import { ComputeBadgeWrapper } from 'components/ui/ComputeBadgeWrapper'
+import { InlineLink } from 'components/ui/InlineLink'
import ProjectUpgradeFailedBanner from 'components/ui/ProjectUpgradeFailedBanner'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useIsOrioleDb, useSelectedProject } from 'hooks/misc/useSelectedProject'
@@ -27,7 +28,6 @@ import {
TooltipContent_Shadcn_,
TooltipTrigger_Shadcn_,
} from 'ui'
-import { InlineLink } from 'components/ui/InlineLink'
const Home: NextPageWithLayout = () => {
const connectDialogUpdate = useFlag('connectDialogUpdate')