Best practice for Security Advisor RLS warning on public.spatial_ref_sys with PostGIS #47526
Replies: 6 comments 1 reply
-
|
I would not enable RLS on
The safer hardening is privilege-based: revoke insert, update, delete, truncate, trigger
on table public.spatial_ref_sys
from anon, authenticated;I would keep For revoke references
on table public.spatial_ref_sys
from anon, authenticated;So my conservative approach would be:
For new projects, the cleaner long-term setup is enabling PostGIS in a dedicated schema such as |
Beta Was this translation helpful? Give feedback.
-
|
This is a known, benign advisor finding rather than something you need to "fix". Recommended options, roughly in order of preference:
I would not try to enable RLS directly on |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, that makes sense. I agree with this framing: treat it as a benign extension-managed table warning, not something to fix with RLS. The distinction around exposure through the auto-generated API is helpful too. If the app does not need client/API access to Either way, I agree the important part is not trying to force RLS onto the PostGIS-managed table. Installing PostGIS outside |
Beta Was this translation helpful? Give feedback.
-
|
Short version: don't enable RLS on
Note that forcing RLS usually fails anyway, since you don't own the extension's table: alter table public.spatial_ref_sys enable row level security;
-- ERROR: must be owner of table spatial_ref_sysSo pick one of these instead: 1) Reduce the write surface but keep it working (simplest): revoke insert, update, delete, truncate on table public.spatial_ref_sys
from anon, authenticated;
-- keep SELECT — PostGIS reads this table2) Cleanest long-term — keep PostGIS out of the exposed schema so it isn't in the Data API surface at all (Supabase only exposes the schemas you choose: https://supabase.com/docs/guides/api/using-custom-schemas). This has to be done when the extension is installed: drop extension if exists postgis; -- only if nothing depends on it yet
create extension postgis schema extensions;3) Just acknowledge the finding in the Advisor if the table isn't API-exposed in your project — it's informational, not a data leak, because the contents are static SRID definitions. References: Row Level Security — https://supabase.com/docs/guides/database/postgres/row-level-security · installing extensions in a dedicated schema — https://supabase.com/docs/guides/database/extensions |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, this is a useful clarification, especially the ownership point. The That makes the advisor finding much less scary: it is worth acknowledging/documenting, but it is not the same class of issue as an application table in |
Beta Was this translation helpful? Give feedback.
-
|
The Security Advisor warning on public.spatial_ref_sys is a false positive in the context of PostGIS. The table is a read-only reference table shipped by the PostGIS extension and contains coordinate system definitions. No user data lives in it. You have two practical options. Option 1. Add a permissive SELECT policy and enable RLS. This silences the advisor and is technically correct since the table is public reference data: ALTER TABLE public.spatial_ref_sys ENABLE ROW LEVEL SECURITY; Option 2. Move PostGIS to its own schema (recommended for new projects). Install the extension into an extensions schema so it is isolated from your application tables: CREATE SCHEMA IF NOT EXISTS extensions; Then reference geometries as extensions.geometry, etc. The advisor only flags tables in the public schema. For existing projects option 1 is simpler and carries no risk since the table is insert-protected by the extension itself. Neither option changes the behavior of your application. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Question: Best practice for Supabase Security Advisor warning on
public.spatial_ref_syswith PostGIS inpublicHi Supabase community,
I’m working on a Supabase project that uses PostGIS. PostGIS is installed in the
publicschema, and the Supabase Security Advisor reports:RLS Disabled in PublicThe remaining warning points to:
public.spatial_ref_sysI would like to understand the recommended Supabase/PostGIS best practice before applying any changes.
Current observations
PostGIS is installed in the
publicschema.public.spatial_ref_sysexists as part of the PostGIS installation.The application itself does not directly query
public.spatial_ref_sys.One application table uses a PostGIS geometry column:
public.route_constraints.geometrygeometry(Geometry, 4326)Application tables have RLS enabled.
The Security Advisor warning that remains is for
public.spatial_ref_sys.public.spatial_ref_syscurrently has RLS disabled.There are no application policies on
public.spatial_ref_sys.Current grants observed
For the
anonandauthenticatedroles, the table currently appears to have grants including:SELECTREFERENCESINSERTUPDATEDELETETRUNCATETRIGGERI am considering hardening this by revoking write/DDL-like privileges from
anonandauthenticated, specifically:INSERTUPDATEDELETETRUNCATETRIGGERI would likely leave
SELECTin place unless Supabase/PostGIS guidance says otherwise.REFERENCESis the main unclear permission. I do not see application foreign keys referencingspatial_ref_sys, but I do not want to break PostGIS behavior by revoking something that PostGIS expects.Questions
For Supabase projects using PostGIS in
public, ispublic.spatial_ref_sysexpected to trigger the Security Advisor warningRLS Disabled in Public?Is this warning considered acceptable for the PostGIS system table
spatial_ref_sys, or should it be fixed?Is it safe or recommended to enable RLS on
public.spatial_ref_sys?If RLS is enabled on
public.spatial_ref_sys, are there known risks for PostGIS behavior, geometry/geography type usage, SRID lookups, migrations, or Supabase tooling?Is revoking write/DDL-like grants from
anonandauthenticatedonpublic.spatial_ref_sysrecommended?Proposed revokes:
INSERTUPDATEDELETETRUNCATETRIGGERShould
SELECTremain granted toanonand/orauthenticatedforpublic.spatial_ref_sys?Should
REFERENCESremain granted toanonand/orauthenticated, or is it safe to revoke if the application has no foreign keys referencingspatial_ref_sys?What is the safest Supabase-compatible way to address this Advisor finding without breaking PostGIS?
What I want to avoid
I want to avoid applying a migration that makes the Security Advisor quieter but accidentally breaks PostGIS behavior.
I also want to avoid enabling RLS on a PostGIS-managed system table if Supabase or PostGIS expects it to remain unmanaged.
Current intended approach, not yet applied
My current conservative idea is:
public.spatial_ref_sysuntil confirmed safe.anonandauthenticated.SELECT.REFERENCESunchanged unless confirmed safe to revoke.Does this approach match Supabase/PostGIS best practice?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions