You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
supabase db diff migration files does not include view with (security_invoker=on) clause #792
the diff tool does not add the with (security_invoker=on) clause for views created with this clause, this omission can cause security issues.
To Reproduce
in the supabase studio sql editor, create a table with RLS enabled, insert some data, and create a view with security invoker on:
createtabletest (
name text
);
altertable"test" enable row level security;
insert into test values ('test1');
insert into test values ('test2');
createviewview_with_security_invoker_on with (security_invoker=on) asselect
name from test
you get the following result when calling the view with an anon key:
[]
then run migration and reset:
supabase db diff -f create_ view_with_security_invoker_on
supabase db reset
insert back the data (deleted during the reset) in the sql editor:
insert into test values ('test1');
insert into test values ('test2');
you get the following result when calling again the view with an anon key:
[{"name":"test1"},
{"name":"test2"}]
the creation of the view in the migration file is done without the with (security_invoker=on) clause:
We have also encountered this and accidentally caught the problem while applying the auto-generated migration files to staging. Note that this is not only a bug, but a potentially serious security risk if a view gets into prod without security_invoker=on unintentionally 😞
Reacted by Gabriel Jones, Pourya Dashtegoli Pour, teamclouday, Burkhard Reffeling and Em Snook
We also encountered this. It's annoying as it means we have to replace all our views after migrations run. Please look into this as it's a high priority security issue.
It's hard to say... we are not really keen to fork and maintain our own version of migra, as it may end up being abandoned like pgadmin-schema-diff.
If anyone has the time, I'd recommend trying out and contributing to a new diff tool from stripe which is more actively maintained https://github.com/stripe/pg-schema-diff.
It takes a lot of work build a perfect schema diff tool. But if we can focus on one, I think it will be a huge win for the postgres community.
If you have large number of views to invoke the security on, running this script on your db will find all views with the schema 'public' and invoke the security.
DO $$
DECLARE
view_rec RECORD;
view_def TEXT;
BEGIN
-- Loop through all views in the 'public' schema
FOR view_rec IN
SELECT n.nspname as table_schema,
c.relname as table_name,
pg_get_viewdef(c.oid) as view_definition
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
JOIN pg_roles r ON r.oid = c.relowner
WHERE c.relkind = 'v' -- Only views
AND n.nspname = 'public' -- Only in the 'public' schema
AND r.rolname = current_user -- Only process views owned by the current user
LOOP
-- Recreate the view with security_invoker=on
EXECUTE format('
CREATE OR REPLACE VIEW %I.%I WITH (security_invoker=on) AS
%s',
view_rec.table_schema,
view_rec.table_name,
view_rec.view_definition);
END LOOP;
END $$;
This bug still exists. I think it would be helpful to add a warning about view not being fully supported. Like how it's currently doing for drop commands
I have run into this issue as well. I understand that the fix is to manually edit the generated migration file with with (security_invoker = on). However, if I apply that migration to the database and then run the diff tool again it is detecting a difference between the schema in my schemas folder and what's actually in the database and will generate another migration without with (security_invoker = on). This gets me into a place where I have to manually delete the create or replace view from every subsequent migration.
Is anybody else seeing this? What is the solution?
This raises serious concerns about Supabase's development priorities and makes me question whether it's safe to trust my production infrastructure to this platform.
Activity
gilbert commentedon May 11, 2023
Just ran into this. Glad I checked, this is a subtle security hazard.
SamuraiT commentedon Feb 2, 2024
The same thing happens to me
Palabola commentedon Feb 21, 2024
Same here. The update almost got live. Fix would be much appreciated.
daroczig commentedon Feb 21, 2024
We have also encountered this and accidentally caught the problem while applying the auto-generated migration files to staging. Note that this is not only a bug, but a potentially serious security risk if a view gets into prod without
security_invoker=onunintentionally 😞gabriel-jones commentedon May 14, 2024
We also encountered this. It's annoying as it means we have to replace all our views after migrations run. Please look into this as it's a high priority security issue.
yannis216 commentedon Jul 26, 2024
Also (still) running into this security risk :-/
tvogel commentedon Aug 7, 2024
As the supabase linter currently recommends
WITH (security_invoker = on)as a remedy for implicit SECURITY DEFINER views, see https://supabase.com/docs/guides/database/database-advisors?lint=0010_security_definer_view#how-to-resolve, I think,supabase db diffshould really support this now.What is the priority / timeline of this?
sweatybridge commentedon Aug 7, 2024
It's hard to say... we are not really keen to fork and maintain our own version of migra, as it may end up being abandoned like pgadmin-schema-diff.
If anyone has the time, I'd recommend trying out and contributing to a new diff tool from stripe which is more actively maintained https://github.com/stripe/pg-schema-diff.
It takes a lot of work build a perfect schema diff tool. But if we can focus on one, I think it will be a huge win for the postgres community.
How-Sustainable commentedon Aug 29, 2024
If you have large number of views to invoke the security on, running this script on your db will find all views with the schema 'public' and invoke the security.
alon-z commentedon May 18, 2025
Bug still exists
teamclouday commentedon Jun 18, 2025
This bug still exists. I think it would be helpful to add a warning about view not being fully supported. Like how it's currently doing for drop commands
peterHoburg commentedon Nov 17, 2025
We would really love a fix for this.
hardchor commentedon Nov 25, 2025
Weirdly, this just started resurfacing for me with an update to supabase CLI (thankfully we caught it in time).
@sweatybridge have you recently switched to
pg-schema-diff? Or what might've caused this?jstettner commentedon Dec 11, 2025
Does anyone have a workaround for this so that I don't have to continuously remove the drop / recreate incorrectly from the generated diffs?
jgaull commentedon Jan 10, 2026
I have run into this issue as well. I understand that the fix is to manually edit the generated migration file with
with (security_invoker = on). However, if I apply that migration to the database and then run thedifftool again it is detecting a difference between the schema in myschemasfolder and what's actually in the database and will generate another migration withoutwith (security_invoker = on). This gets me into a place where I have to manually delete thecreate or replace viewfrom every subsequent migration.Is anybody else seeing this? What is the solution?
sweatybridge commentedon Jan 10, 2026
The solution is to try using a different diff tool.
This newly added flag is highly experimental and only works with the local database at the moment.
jgaull commentedon Jan 13, 2026
Thank you @sweatybridge! This worked for me. I look forward to being a tester 🙂
sweatybridge commentedon Jan 13, 2026
Glad to hear that. If you run into any issues, feel free to report them on here https://github.com/supabase/pg-delta
Our team will look into them promptly.
2754github commentedon Feb 10, 2026
Honestly, this issue became the deciding factor for me to move away from Supabase, which I've loved for years. I'm deeply disappointed.
Despite your documentation recommending RLS and Views as a security pattern, this critical security issue remains unresolved.
This raises serious concerns about Supabase's development priorities and makes me question whether it's safe to trust my production infrastructure to this platform.
sweatybridge commentedon Feb 10, 2026
Hi @2754github, I'm sorry to hear about your experiences. We have actually shipped a new diff tool that captures RLS on views #792 (comment)
It is not the default option currently because we are still improving its stability. But eventually it will replace migra as the default option.
Have you given pg-delta a try? Let me know if the command works for you. We are committed to making your local development environment secure.