Static check for the risky 42501 fix: schema-wide GRANTs and tables without RLS in your migrations (offline, MIT) #53408
Replies: 2 comments 1 reply
|
Useful tool — the static layer is where this catches people, and the blind spot list it flags (RLS-disabled-with-grants, 1. Always-true policies for 2. Grants vs policies vs actual access are three different answers. The checker can flag 3. Migrations that pass in the repo and behave differently on the project. The If a runtime harness is interesting to you separately: the smallest version that covers #1 and #2 is a PGlite fixture (no Supabase project, no credentials) that builds the insecure state from a migration, runs your |
|
@dexi — thanks for running all three through the checker, that's a much more useful answer than "covered". On the limits you drew. They're the right lines, and they match what the fixture taught me while I was building it: a predicate like Default privileges. Confirming on 16.15 is exactly what I would have asked for — the case I flagged was reading, your reproduction is now data. An open issue for the per-schema no-op form with credit attached is the right outcome; I didn't expect the checker to grow a rule from a comment. The fixture is real and it runs. Two users, their JWTs' claims set the way PostgREST sets them per transaction (both Five Postgres behaviours it encodes that cost me a wrong run each, in case they save you the same: I'll send it as a PR against the repo — insecure state, the cross-user read as the fail-on-purpose test, then the same read clean. If you'd rather have it as an issue first, say so and I'll open that instead. |
Uh oh!
There was an error while loading. Please reload this page.
Since the grants change (#45329) reached existing projects on 30 Oct, new tables answer
permission denied for table(42501) until they are granted. The quickest fix people paste, and AI coding tools suggest, is:On a table without RLS that opens every row through the Data API. The live-database checks posted here (for example the read-only test in #52185) catch this after deploy. We wanted the same check on the repo, before it ships.
rls_check.pyis one Python file (3.10+, standard library only, no network calls, no credentials) that readssupabase/migrationsand your app source and flags 13 known patterns: tables without RLS,using (true)policies, policies that only check "logged in", RLS switched off in a later migration, SECURITY DEFINER functions without a fixedsearch_path, views withoutsecurity_invoker, public buckets, grants toanon, schema-wide grants and default privileges, and service-role keys in client code. It exits non-zero for CI.A reproducible example from the repo (output trimmed; the full run is in the README):
examples/grant-fix-fixedadds one migration (revoke the schema-wide grant, enable RLS, an owner-onlyselectpolicy,grant select on public.invoices to authenticated) and the same command prints0 critical, 0 high, 0 medium, 0 low -> PASS.Limits: it reads files only. Changes made in the dashboard that never reached a migration are invisible to it, it does not run your policies against a database, and a pass means no known pattern matched, not that the app is secure. It works best next to a live check like #52185 and the Security Advisor.
Repo (MIT): https://github.com/dobravaza/proofmerge-rls-check
Disclosure: I run Proofmerge, which sells human security reviews of AI-built apps. This checker is our free open-source tool, not a Supabase product. False-positive reports are very welcome as GitHub issues.
All reactions