Authenticated INSERT always rejected by RLS, even with with check (true)
#50483
SummaryAny This happens even when the table's only INSERT policy is Environment
Minimal reproductioncreate table public.repro (
id uuid primary key default gen_random_uuid(),
owner_id uuid not null
);
alter table public.repro enable row level security;
create policy "always_allow" on public.repro for insert with check (true);
notify pgrst, 'reload schema';Then, authenticated as a real confirmed user (password sign-in, valid JWT verified via const authRes = await fetch(`${SUPABASE_URL}/auth/v1/token?grant_type=password`, {
method: 'POST',
headers: { apikey: ANON_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
const { access_token, user } = await authRes.json();
const res = await fetch(`${SUPABASE_URL}/rest/v1/repro`, {
method: 'POST',
headers: {
apikey: ANON_KEY,
Authorization: `Bearer ${access_token}`,
'Content-Type': 'application/json',
Prefer: 'return=representation',
},
body: JSON.stringify({ owner_id: user.id }),
});
// res.status === 403
// body: {"code":"42501","details":null,"hint":null,"message":"new row violates row-level security policy for table \"repro\""}Expected: insert succeeds (HTTP 201), since the policy is What we've already ruled out
QuestionGiven the above, this looks like a platform-level regression in PostgREST's RLS enforcement for INSERT (possibly tied to the PostgreSQL 17.6 rollout, since that's the one constant across both affected projects), rather than anything in our schema/policies/grants. Is this a known issue, and is there a workaround in the meantime? Happy to share direct project access / logs if useful. Project refs: |
Replies: 1 comment 1 reply
|
You need to have a Select policy as you are returning data from the insert. |
You need to have a Select policy as you are returning data from the insert.