fix(policies): fall back to public when roles is an empty array - #1107
Open
rezimeshvelashvili wants to merge 1 commit into
Open
fix(policies): fall back to public when roles is an empty array#1107rezimeshvelashvili wants to merge 1 commit into
rezimeshvelashvili wants to merge 1 commit into
Conversation
rezimeshvelashvili
requested review from
a team,
avallete and
soedirgo
as code owners
August 17, 2026 20:10
`policies.update()` built the role list with `roles.map(ident).join(',')`,
so an empty array produced `ALTER POLICY ... TO ;` and Postgres rejected
it with `syntax error at or near ";"`.
An empty array is the natural way to express "all roles", and it is what
`policies.create()` already defaults to. Studio sidesteps the bug by
substituting `['public']` client-side before calling the API, so it only
surfaces for direct REST and library consumers.
Fixes supabase#361
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
policies.update()builds theTOclause withroles.map(ident).join(','), which returns an empty string for[]. The generated statement becomes:and Postgres rejects it with
syntax error at or near ";".An empty array is the natural way for a client to express "all roles", and it is what
policies.create()already defaults to (roles = ['public']). The update path only handledundefined("leave roles alone") and never considered[].Why this hasn't been hit recently
Studio applies the same fallback client-side before calling the API, in
apps/studio/components/interfaces/Database/Policies/PolicyEditorPanel/index.tsx:so the dashboard never sends
[]. The original dashboard report (supabase/supabase#7740) was resolved by that client-side change, which is why the symptom disappeared while the server-side cause stayed open as #361.The bug is still reachable for anyone calling the REST API directly or using the published
@supabase/postgres-metapackage. If this lands, Studio's workaround becomes redundant.Fix
Treat
[]as['public'], matchingcreate():rolesundefined[]... TO public;['anon']... TO anon;Test
test/lib/policies.tscreates a policy with['postgres'], updates it with[], and expects['public']. It fails onmasterwith the syntax error above and passes with the change. Full suite: 200/200.One note on the test: it casts the payload because
update()typesnameas required, even though the implementation branches onname === undefinedand the route passesrequest.body as any. Passing the current name isn't a workaround either, since renaming a policy to its own name errors withpolicy ... already exists. I left the type alone to keep this PR to a single change, but happy to follow up withname?: stringif you'd like it.Fixes #361