Database / Supabase Intermediate to Advanced Interview Questions
What is the difference between a SECURITY DEFINER and a SECURITY INVOKER Postgres function?
A SECURITY INVOKER function (the default) runs with the privileges of the role that calls it, so any Row Level Security policies on tables it touches still apply exactly as if the caller ran the query directly. A SECURITY DEFINER function instead runs with the privileges of the role that created it, regardless of who calls it.
| SECURITY INVOKER | SECURITY DEFINER |
| Runs as the calling role | Runs as the function's owner |
| RLS applies normally | Can bypass RLS if owner has that privilege |
This makes DEFINER functions useful for controlled privilege escalation — letting an authenticated user trigger an action (like inserting an audit log row) that their own RLS policy wouldn't otherwise permit — but they need careful review since a bug in one effectively grants elevated access to anyone who can call it.
More Related questions...