← All posts
·8 min read·GuardLayer·how we write

Supabase audit logs: what they show after an incident, and what they can't

#supabase#auth#logging#incident-response#security

Supabase has three kinds of audit logs, and none of them on its own tells you whether someone read or changed your data. Auth audit logs record authentication events: sign-ups, sign-ins, token refreshes, password changes. API Gateway logs record each HTTP request with its path, status, IP and the JWT's user id, but not the rows it returned or changed. Platform audit logs record what your team did in the dashboard. To see row-level changes you need pgAudit or an audit trigger, and both only record what happens after you turn them on. Logs last 1 day on the Free plan and 7 on Pro, so after a security report, look first and fix second.

This post is for the moment after someone tells you about a hole: a function anyone could call, a policy that let users write each other's rows. Fixing it is the easy part. The harder question is whether anyone used it before you did. In one of our case studies the honest answer was that the available data couldn't say, which is common. Here is what each log can tell you, and what to set up so the answer is better next time.

What do Supabase Auth audit logs record?

Authentication events, according to Supabase's Auth audit logs guide: sign-ups and sign-ins, password changes and resets, email verification, token refreshes and sign-outs, plus MFA and identity-linking events. Each entry has a timestamp, the user id, an action such as login, user_signedup, user_modified, token_refreshed or user_deleted, and some metadata.

They're stored in two places:

  • Supabase's log storage, which you search in the dashboard under Logs with the Auth log type.
  • The auth.audit_log_entries table, optionally. The toggle is Write audit logs to the database under Authentication > Audit Logs. It costs database storage, but it's the only copy you can query with SQL and that isn't subject to log retention.

Two limits matter for incident response:

  • IP addresses are mostly missing. The guide says ip_address is recorded only for some events, such as MFA, passkeys, identity linking and recovery codes, and is "empty for most sign-up, sign-in, sign-out, and token events." For a session's IP, Supabase points you at the ip column in auth.sessions.
  • They stop at authentication. A signed-in user reading every row of a table through a too-broad policy produces no Auth event at all after the sign-in. Neither does a call to an RPC function.

Which log shows what someone did with the API?

The API Gateway logs. Every request to /rest/v1/, /graphql/v1/, Storage and Auth passes through the gateway, and Supabase logs the method, path, status code and a fixed set of headers, including cf-connecting-ip, x-real-ip and user-agent. The Logs page can filter on the JWT's subject, so you can list every request a given user id made.

For an investigation, that's usually the most useful source. After a report about an open function, filter the API Gateway logs on:

  • Pathname /rest/v1/rpc/<function name> (or the table's path),
  • Method POST for an RPC, PATCH or DELETE for table writes,
  • Status 2xx, to see calls that succeeded.

Then look at who made them: the JWT subject and the IP. Calls from your own server, at the rate your app makes them, are normal. Calls from an unfamiliar IP, from a user id that signed up minutes earlier, or with no user id at all on a function only your server should call, are what you're looking for.

What the gateway can't tell you is what changed. It records that PATCH /rest/v1/prices?id=eq.42 succeeded, not the old price or the new one.

How long are Supabase logs kept?

Per Supabase's logs guide, retention for API and database logs depends on the plan:

PlanLog retention
Free1 day
Pro7 days
Team28 days
Enterprise90 days

On the Free plan, yesterday's requests are gone by tomorrow. That's why the order after a report matters: search the logs before you deploy the fix, and save what you find, because the evidence for anything older than your retention window doesn't exist anymore.

To keep logs longer, use a log drain to send them to your own storage. Log drains are available on Pro, Team and Enterprise. For Auth events specifically, turning on the auth.audit_log_entries table keeps them in your database for as long as you keep the rows.

How do I see which rows were read or changed?

Nothing records this by default. You have two options, and both only cover events after you turn them on. Supabase's own guide to configuring logging says it plainly: logging changes "cannot recover past activity."

pgAudit logs SQL statements to the Postgres logs. Supabase's pgAudit guide covers session, role and object logging. Two details make it useful for API traffic:

  • API requests reach Postgres through PostgREST as the authenticator role, so role-scoped logging on that role covers them.
  • Object logging records every statement that touches the tables you choose, regardless of who ran it. Create a role that exists only to define the scope, grant it the privileges you want logged, and point pgaudit.role at it.

pgAudit's entries land in the Postgres logs, so the retention table above applies to them too, and they can contain sensitive values from the statements. Scope it to the tables you care about.

An audit trigger keeps a permanent, queryable history of changes in a table you own:

create schema if not exists private;

create table private.audit_log (
  id bigint generated always as identity primary key,
  at timestamptz not null default now(),
  table_name text not null,
  op text not null,
  actor uuid default auth.uid(),
  actor_role text default (current_setting('request.jwt.claims', true)::jsonb ->> 'role'),
  old_row jsonb,
  new_row jsonb
);

create or replace function private.audit_row()
returns trigger
language plpgsql security definer set search_path = ''
as $$
begin
  insert into private.audit_log (table_name, op, old_row, new_row)
  values (
    tg_table_name,
    tg_op,
    case when tg_op <> 'INSERT' then to_jsonb(old) end,
    case when tg_op <> 'DELETE' then to_jsonb(new) end
  );
  return coalesce(new, old);
end;
$$;

create trigger audit_prices
  after insert or update or delete on public.prices
  for each row execute function private.audit_row();

auth.uid() and the role claim are filled in for requests through the API, so each row records which user, or which key, made the change. Keep the table in a schema the Data API doesn't expose, like private here, so users can't read or rewrite their own history. Add the trigger to the tables where a silent overwrite would hurt: prices, roles, balances, anything a payment decides. It records writes only. For reads, pgAudit is the only option.

What about the dashboard and the team?

Platform audit logs record what members of your Supabase organization did: creating projects, inviting members, changing settings, deploying Edge Functions. They're useful when the question is whether a teammate's account changed something, and they're only available on the Team and Enterprise plans. They don't cover your app's users.

After a report: a short checklist

  1. Before you fix anything, search the API Gateway logs for the affected path, method and status, and save the results. On Free, you have about a day.
  2. Check Auth for accounts that appeared around the suspicious calls: recent user_signedup events, and sign-ins for the user ids you found in step 1.
  3. Check what the data looks like now for the rows the hole could reach: prices, roles, owner columns. Without an audit trigger this is the only "after" picture you'll get.
  4. Fix the hole, then rotate anything it could have exposed, such as keys stored in a table that was readable.
  5. Turn on what you were missing, so the next investigation has more to work with: the auth.audit_log_entries table, an audit trigger on sensitive tables, and a log drain if you're on Pro or above.

Does GuardLayer help with this?

Not with the logs. GuardLayer is a static scanner: it reads your code and migrations and never sees your project's logs or traffic. Where it fits is before step 1: it flags the holes that lead to these investigations, such as an RPC function anyone can call, a table without RLS or a role users can change themselves, on every push, before they reach production.

FAQ

Where are Supabase auth audit logs stored? In Supabase's log storage, searchable under Logs with the Auth log type, and optionally in the auth.audit_log_entries table if you turn on Write audit logs to the database under Authentication > Audit Logs.

Why is ip_address empty in auth.audit_log_entries? Supabase records it only for some events, such as MFA, passkeys, identity linking and recovery codes. For most sign-ins, sign-ups and token events it's empty. Check the ip column in auth.sessions instead.

Do Supabase logs show which rows a user read? No. API Gateway logs show the request (path, method, status, IP, user id), not the rows returned. To log reads you need pgAudit, and it only records reads after you enable it.

Can I recover logs older than my plan's retention? No. Once logs pass the retention window they're gone. A log drain or the auth.audit_log_entries table only keeps what's recorded after you set them up.

Is there a built-in audit trail for table changes? Not by default. Add an audit trigger like the one above to the tables that matter, or use pgAudit to log the statements.

live check · read-only

Check your Supabase Auth settings and tables, free

Connect your Supabase project read-only. GuardLayer checks your Auth settings (leaked passwords, email confirmation, secure email change, token rotation, CAPTCHA, MFA) and your RLS, policies and grants, and says how to fix each problem. It never reads your rows and can't change anything.

Check my Supabase project

Prefer to check code instead? Scan your repo, no signup.

Keep reading