The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: update postgres hooks security model (#28681)
Kang Mingd18bef8b9cd9
diff --git a/apps/docs/content/guides/auth/auth-hooks.mdx b/apps/docs/content/guides/auth/auth-hooks.mdxindex 1e69e97c323..5ca24eb75b9 100644--- a/apps/docs/content/guides/auth/auth-hooks.mdx+++ b/apps/docs/content/guides/auth/auth-hooks.mdx@@ -59,35 +59,31 @@ Sign the payload and grant permissions selectively in order to guard the integri><TabPanel id="sql" label="SQL">-You will need to assign additional permissions so that Supabase Auth can access the hook as well as the tables it interacts with.+When you configure a postgres function as a hook, Supabase will automatically apply the following grants to the function for these reasons:-The `supabase_auth_admin` role does not have permissions to the `public` schema. You need to grant the role permission to execute your hook function:+- Allow the `supabase_auth_admin` role to execute the function. The `supabase_auth_admin` role is the postgres role that is used by Supabase Auth to make requests to your database.+- Revoke permissions from other roles (e.g. `anon`, `authenticated`, `public`) to ensure the function is not accessible by Supabase Data APIs.```sql+-- Grant access to function to supabase_auth_admingrant executeon function public.custom_access_token_hookto supabase_auth_admin;-```--You also need to grant usage to `supabase_auth_admin`:-```sql+-- Grant access to schema to supabase_auth_admingrant usage on schema public to supabase_auth_admin;-```-Also revoke permissions from the `authenticated`, `public`, and `anon` roles to ensure the function is not accessible by Supabase Serverless APIs. The `public` role has access to functions created on `public.*` by default and `anon` and `authenticated` inherit permissions from the `public` role. Permission is revoked from the `public` role in order to prevent the `anon` and `authenticated` roles from inheriting permissions to invoke the Postgres Hook.--```sql+-- Revoke function permissions from authenticated, anon and publicrevoke executeon function public.custom_access_token_hookfrom authenticated, anon, public;```-For security, we recommend against the use of the `security definer` tag. The `security definer` tag specifies that the function is to be executed with the privileges of the user that owns it. When a function is created via the Supabase dashboard with the tag, it will have the extensive permissions of the `postgres` role which make it easier for undesirable actions to occur.+<Admonition type="caution" label="Create postgres functions with security invoker">-We recommend that you do not use any tag and explicitly grant permissions to `supabase_auth_admin` as described above.+We do not recommend creating postgres functions with the `security definer` tag. The `security definer` tag specifies that the function is to be executed with the privileges of the user that owns it. Read more about the `security definer` tag [in our database guide](/docs/guides/database/functions#security-definer-vs-invoker).-Read more about the `security definer` tag [in our database guide](/docs/guides/database/functions#security-definer-vs-invoker).+</Admonition></TabPanel><TabPanel id="http" label="HTTP">diff --git a/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdxindex e563dec6cca..70f151d9f52 100644--- a/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdx+++ b/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdx@@ -256,14 +256,6 @@ as $$end;$$;-grant execute- on function public.custom_access_token_hook- to supabase_auth_admin;--revoke execute- on function public.custom_access_token_hook- from authenticated, anon, public;-grant allon table public.profilesto supabase_auth_admin;diff --git a/apps/docs/content/guides/auth/auth-hooks/mfa-verification-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/mfa-verification-hook.mdxindex ca298e4670f..bbaf4cc924b 100644--- a/apps/docs/content/guides/auth/auth-hooks/mfa-verification-hook.mdx+++ b/apps/docs/content/guides/auth/auth-hooks/mfa-verification-hook.mdx@@ -159,18 +159,10 @@ as $$$$;-- Assign appropriate permissions and revoke access-grant execute- on function public.hook_mfa_verification_attempt- to supabase_auth_admin;-grant allon table public.mfa_failed_verification_attemptsto supabase_auth_admin;-revoke execute- on function public.hook_mfa_verification_attempt- from authenticated, anon, public;-revoke allon table public.mfa_failed_verification_attemptsfrom authenticated, anon, public;diff --git a/apps/docs/content/guides/auth/auth-hooks/password-verification-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/password-verification-hook.mdxindex 26d007d5c58..b1d262b6f3d 100644--- a/apps/docs/content/guides/auth/auth-hooks/password-verification-hook.mdx+++ b/apps/docs/content/guides/auth/auth-hooks/password-verification-hook.mdx@@ -149,18 +149,10 @@ as $$$$;-- Assign appropriate permissions-grant execute- on function public.hook_password_verification_attempt- to supabase_auth_admin;-grant allon table public.password_failed_verification_attemptsto supabase_auth_admin;-revoke execute- on function public.hook_password_verification_attempt- from authenticated, anon, public;-revoke allon table public.password_failed_verification_attemptsfrom authenticated, anon, public;diff --git a/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdxindex b91fb1d9c9c..1b3043d3dab 100644--- a/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx+++ b/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx@@ -376,14 +376,6 @@ beginend;$$ language plpgsql;-grant execute- on function public.send_email- to supabase_auth_admin;--revoke execute- on function public.send_email- from authenticated, anon;-grant allon table public.job_queueto supabase_auth_admin;diff --git a/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdxindex 96439bd6452..3a9a27cc63f 100644--- a/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdx+++ b/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdx@@ -337,14 +337,6 @@ beginend;$$ language plpgsql;-grant execute- on function public.send_sms- to supabase_auth_admin;--revoke execute- on function public.send_sms- from authenticated, anon;-grant allon table public.job_queueto supabase_auth_admin;