Sample alert How it works Coverage PENTEST METHODOLOGY DOCS PRICING FAQ MCP CONTACT LOG IN SCAN MY APP →

Supabase auth users exposed warning: how to fix it

FIX / AUTH USERS EXPOSED / 10 MIN READ

The “Auth Users Exposed” warning means that a view in your public schema reads the auth.users table. Replace that view with a profiles table that a trigger fills. Then drop or lock the old view. The auth.users table holds emails, phone numbers, and login data. A public view can hand this data to every caller of your API.

This guide shows how to confirm the problem, how to fix it in order, and how to check that nobody read the data.

What does the “Auth Users Exposed” warning mean?

It means that the Security Advisor found a view that references auth.users and that the API can reach. Supabase lists this check as lint 0002_auth_users_exposed in its Splinter linter. The level is WARN.

The reason is how Postgres views work. A view runs with the rights of its owner by default. The owner is usually the postgres role. This role skips row level security. So a caller reads the rows that the view selects, and the RLS rules of the base table do not apply. The Splinter page says that a public security definer view that references auth.users “exposes all user records to all API users.”

AI coding tools create this problem often. You ask for a user list or a “members” page. The tool wants the name and the email of each user. These values live in auth.users. The tool writes a view like this one:

create view public.user_profiles as
select id, email, raw_user_meta_data ->> 'full_name' as full_name, created_at
from auth.users;

The view works in the app. The warning appears in the Security Advisor. The view is also a real endpoint: the API serves every view in an exposed schema.

These are the usual causes:

  • A view that joins auth.users. The tool joins your profiles table to auth.users to add the email.
  • A view for an admin page. The view lists all users for a dashboard, but it has no access rule.
  • A view that the tool created for convenience. A name such as users, members, or user_list is common.
  • A copy from a tutorial. An old guide shows a view on auth.users as the way to read user data.

The security definer view guide covers the more general warning about views. The auth.users case is worse, because the data is personal data and the table holds login information.

How do I confirm that the view exposes users?

Test the view as a stranger. Use only the public key of your project. This is the same key that a visitor finds in your JavaScript bundle.

  1. Open the Supabase dashboard. Select Advisors, then Security Advisor.
  2. Find the entry with the title “Exposed Auth Users”. Note the name of each view in the list.
  3. Open Settings, then API Keys. Copy the publishable key. It starts with sb_publishable_. An older project can use the legacy anon key instead.
  4. Call the view with curl. Replace the project reference, the view name, and the key.
curl -s "https://YOUR-PROJECT-REF.supabase.co/rest/v1/user_profiles?select=*&limit=5" \
  -H "apikey: YOUR_PUBLISHABLE_KEY"

A list of rows with emails means that the view is open. An error with a code such as 42501 or a 404 status means that the API does not serve the view to this role.

  1. Repeat the call with a signed-in user token. Many views are closed to anon but open to authenticated. Any person can create an account, so this is almost as bad.
curl -s "https://YOUR-PROJECT-REF.supabase.co/rest/v1/user_profiles?select=*&limit=5" \
  -H "apikey: YOUR_PUBLISHABLE_KEY" \
  -H "Authorization: Bearer USER_ACCESS_TOKEN"
  1. Find all the views that reference auth.users. Run this query in the SQL editor:
select n.nspname as schema, c.relname as view_name
from pg_depend d
join pg_rewrite r on r.oid = d.objid
join pg_class c on c.oid = r.ev_class
join pg_namespace n on n.oid = c.relnamespace
where d.refobjid = 'auth.users'::regclass
  and c.relkind in ('v', 'm')
  and n.nspname = 'public'
group by 1, 2;

The query lists the views and the materialized views in the public schema that depend on auth.users. Fix each one.

Warning: Do not test with the service_role key or the sb_secret_ key. These keys skip RLS and show data that a visitor cannot see. The test then gives a false result.

Does security_invoker fix the problem?

Not in a simple way. The Splinter page lists security_invoker as the second option. It has a cost.

A view with security_invoker=on runs with the rights of the caller, not the owner. This option needs Postgres 15 or later. The caller must then be able to read auth.users. So the option needs these changes:

  1. Grant select on auth.users to the authenticated role.
  2. Enable RLS on auth.users.
  3. Add a policy that limits each user to the own row.

The auth.users table belongs to the Supabase Auth service. A grant and a policy on it change a table that you do not own. A mistake in the policy gives each signed-in user the data of all users. An update of Supabase can also conflict with your change.

Use this option only if you understand all three steps and you test them as a normal user. For most apps, the profiles table is the better answer. It keeps auth.users closed and gives your app only the columns that it needs.

How do I fix it now?

Do these steps in order. Step 1 closes the data at once. The other steps build the safe replacement.

Caution: The app can stop working after step 1, because a page can read the view. This is the correct trade. Fix the page in step 5.

  1. Close the view. Remove the rights of the API roles on the view. This keeps the view for now and stops the leak:
revoke all on public.user_profiles from anon, authenticated;
  1. Create a profiles table. Add only the columns that the app shows to other users. Do not copy the email unless the app must show it.
create table public.profiles (
  id uuid primary key references auth.users (id) on delete cascade,
  display_name text,
  avatar_url text,
  created_at timestamptz not null default now()
);

alter table public.profiles enable row level security;
  1. Add policies. Each user reads and updates only the own row:
create policy "read own profile"
on public.profiles for select to authenticated
using ((select auth.uid()) = id);

create policy "update own profile"
on public.profiles for update to authenticated
using ((select auth.uid()) = id)
with check ((select auth.uid()) = id);

If the app must show the name of other users, add a second read policy for the columns that are safe to share. Do this with care. The profiles table guide shows how to do this without a leak.

  1. Add a trigger that fills the table. The trigger copies a new user into profiles at sign-up:
create function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
  insert into public.profiles (id, display_name)
  values (new.id, new.raw_user_meta_data ->> 'full_name');
  return new;
end;
$$;

revoke execute on function public.handle_new_user() from public, anon, authenticated;

create trigger on_auth_user_created
after insert on auth.users
for each row execute function public.handle_new_user();

The function uses set search_path = ''. This stops a caller from changing which tables the function finds. The revoke line stops the API from offering the function as an RPC call.

  1. Copy the users that exist already. The trigger handles new users only:
insert into public.profiles (id, display_name)
select id, raw_user_meta_data ->> 'full_name'
from auth.users
on conflict (id) do nothing;
  1. Change the app. Replace each read of the view with a read of profiles. Search your code for the view name.
  2. Drop the old view. Do this after the app no longer uses it:
drop view public.user_profiles;
  1. Test again. Repeat the curl tests from the previous section. The old view must return an error. The profiles table must return only the own row for a signed-in user, and nothing for anon.

Warning: A trigger on auth.users runs in the same transaction as the sign-up. Supabase says that a bug in the trigger can block new signups. Create a test account after you add the trigger. Do this before you tell users that the fix is done.

What if the view must stay?

Sometimes the app needs a view, for example for a report that only your team reads. Use one of these options.

  1. Move the view out of public. The Data API serves only the schemas that you expose. Put the view in a private schema, such as private, and do not add this schema to the exposed list. Server code that connects to the database directly can still use the view.
  2. Use a function. A function with the check auth.uid() inside can return a limited set of data. Keep the function out of the exposed schema, or revoke execute from anon.

Caution: Do not give the service_role key to the browser so that the view works. The key skips RLS for every table. The service role key guide explains the risk.

How do I check that the Security Advisor is clean?

Run the advisor again after each change. You have two ways.

  1. Open Advisors, then Security Advisor in the dashboard. Select Refresh and read the list.
  2. Run the CLI. The command supabase db advisors reads the lints from your database:
supabase db advisors --type security --remote

The --remote flag targets the linked project. Without the flag, the command checks your local database. Add --level warn to show only the warnings and the errors. Add --fail-on warn to make the command return an error code in a CI job.

The entry “Exposed Auth Users” must not appear. If it still appears, run the query from the confirm section again. A second view can still reference auth.users. A materialized view also counts.

Do not stop at the advisor. The advisor checks the structure and not your data. Run the curl tests again. The Supabase RLS checker tests the tables and the views of your project from outside with the public key.

How do I check if someone read the user data?

The data was open to every caller of your API. Check if someone used the view.

  1. Open the API logs. In the dashboard, select Logs, then API Gateway or Edge Logs. Search for the name of the view in the request path.
  2. Look at the callers. Requests from your own app and your own IP address are normal. Many requests from unknown addresses, or one request with a large limit, are a warning.
  3. Check the retention. The log retention depends on your plan. If the logs do not go back to the day that you created the view, you cannot prove that nobody read the data.

If the view showed emails or phone numbers, treat the case as a possible data breach. Ask a lawyer about your duty to tell the users in your region. Also tell the users to watch for phishing emails.

If the logs show that a stranger read the view, the leak is probably not limited to the view. Check the other tables too. Read the Supabase app hacked guide for the full list of steps.

How do I stop this problem in the future?

Use these controls so that no new view reads auth.users by accident.

  1. Never query auth.users from the browser. Read the profile of a user from your own profiles table. Use supabase.auth.getUser() for the email of the signed-in user.
  2. Put a rule in your AI prompt. Add this line to the rules file of your coding tool: “Never create a view or a function that reads auth.users in the public schema. Use public.profiles.”
  3. Review each view in a migration. Search the migration files for create view and for auth.users. Ask who can call the view.
  4. Use security invoker for new views. Write create view ... with (security_invoker = on) for each new view in public. The view then respects the RLS rules of the base tables. The security definer view guide shows the details.
  5. Run the advisor in CI. The command supabase db advisors --type security --fail-on warn stops a build when a new warning appears.
  6. Check the live project after each release. A scan of the live API finds views that you forgot, and views that a tool added without a note.

When should I get help?

Get help in these cases:

  • The API logs show many reads of the view from unknown addresses.
  • The view showed phone numbers, payment data, or other sensitive data, and you do not know who read it.
  • You cannot change the app to use profiles, because many pages depend on the view.
  • You do not know how to write safe RLS policies for your data model.
  • A trigger error blocks sign-ups, and you cannot find the cause.

After the fix, run the curl tests again. The old view must return an error. The profiles table must show a user only the own row. The Security Advisor must show no “Exposed Auth Users” entry.

Common questions

Is the Auth Users Exposed warning a real problem?
It can be. If the view runs with the rights of its owner, any caller of the Data API can read the data in it. Test the view with the public key to find out.
Can I keep the view and add security_invoker?
Supabase lists this as a second option. It needs extra grants and RLS on auth.users. A profiles table is simpler and safer, so use it.
Why must I not grant select on auth.users to the anon role?
The auth.users table holds emails, phone numbers, and login data. A grant to anon or authenticated makes this data reachable from the browser.
Can the trigger block new sign-ups?
Yes. The trigger runs in the same transaction as the insert into auth.users. An error in the trigger makes the sign-up fail. Test sign-up after each change.
Does the warning go away if I drop the view?
Yes. The lint checks for views that reference auth.users. After you drop the view and run the advisor again, the warning must not appear.

Test your views as anon

A VibeEval scan calls the REST endpoints of your Supabase project with the public key and reports the views and tables that return user data.

14-day free trial · Cancel anytime

SCAN YOUR APP →