TL;DR
Supabase Vault stores secrets encrypted and decrypts them through the view vault.decrypted_secrets. By default only service_role and postgres can read it; on my local stack anon and authenticated had no access to the vault schema at all. Secrets leak in two ways: a grant on Vault to a client role, or a SECURITY DEFINER function in an exposed schema that returns a decrypted value. My test function returned a fake secret to the public key with 200; after revoking EXECUTE it answered 42501.
My free Supabase security checker has a rule for each leak path: “Vault secrets readable by API roles”, rated critical when anon can read them, and “Security definer functions callable from the API”. This note shows why the second one matters for Vault.
What does Supabase Vault protect?
Supabase’s Vault guide describes it as a table of secrets stored with authenticated encryption, readable in decrypted form through a view. The secret stays encrypted on disk, in backups and in replication. The guide also gives the condition everything rests on: anyone with access to the view has access to the decrypted secrets, so access to it must be limited by SQL privileges at all times.
Who can read it by default?
On a local Supabase stack (CLI 2.109.1, Postgres 17.6) I stored a fake value with vault.create_secret and checked each role:
| Role | Usage on schema vault |
Select on vault.decrypted_secrets |
|---|---|---|
anon |
no | no |
authenticated |
no | no |
service_role |
yes | yes |
The vault schema is also not in the Data API’s exposed schemas by default. So out of the box, the public key cannot reach Vault.
How does a secret leak anyway?
The usual reason is an app that needs the secret. A function is the shortest way to give it one:
create function public.get_api_key() returns text
language sql security definer set search_path = ''
as $$ select decrypted_secret from vault.decrypted_secrets where name = 'demo_api_key' $$;
SECURITY DEFINER runs it with the owner’s rights, so it can read Vault. On existing projects, functions in public are granted EXECUTE to anon and authenticated by default, and public is exposed, so the Data API serves it as /rest/v1/rpc/get_api_key:
| Request with the publishable key | Result |
|---|---|
POST /rest/v1/rpc/get_api_key |
200, the decrypted fake value |
same, after revoke execute … from public, anon, authenticated |
401, 42501 “permission denied for function get_api_key” |
The second leak path is a grant: someone adds vault to the exposed schemas or grants a client role usage and select to make a query work. That is the case the checker rates critical.
How do you use Vault safely?
- Read secrets only on the server side: in database functions that never return them, in triggers and webhooks, or in Edge Functions that use the secret key.
- If a function must read a secret, keep it in a schema that is not exposed, or revoke
EXECUTEfrompublic,anonandauthenticatedand grant it only to the role that needs it. - Never return a decrypted value from a function the client can call. Return the result of using the secret, such as the response of an API call, instead.
- Never add
vaultto the exposed schemas; I explained what that list opens in Supabase exposed schemas.
Functions are an API too, and the rest of that rule, including search_path and NULL handling, is in my Lovable app security checklist.
If you want a person to go through the whole app rather than one setting, I do a Supabase security audit with a keep, fix or rewrite verdict for each part.
My similar case
A company I built for was paying thousands of dollars a month for an enterprise document product. Its own platform now costs hundreds a month, with roles for documents, forms, reports and a client portal, and only the features the team uses. See the construction document platform case.
Not sure where your secrets are stored? Write to me and we’ll check them.
Where are your secrets stored?
Tell me what you have now and what you need. I'll reply with the option I'd pick.
Write to me