Repository navigation
fix(db): grant the roles six core policies already name (#755) - #758
Merged
Merged
Conversation
A policy decides which rows a role may see. A GRANT decides whether it may touch
the table at all. Six core tables carry policies naming `anon` or
`authenticated` and issue no grant to those roles, so the policies are
unreachable and the tables answer:
permission denied for table review_pins
HINT: Grant the required privileges to the current role with:
GRANT SELECT ON core.review_pins TO authenticated;
Postgres names the fix, but only for whoever reads the raw error. Through the
API it is a 401 or a 500.
Found smoke-testing production: a public profile reads core.review_pins
directly and it failed for anonymous *and* signed-in visitors. Unlike the
service_role drift in #751 this is not an environment difference — local has the
same hole, so pinned reviews have never worked anywhere. The writes go through
the pin_review / unpin_review RPCs, which are SECURITY DEFINER and therefore
worked, so a user could pin a review and never see it pinned.
The sweep that found it found five more:
generic_invitations authenticated INSERT, SELECT, UPDATE
inquiry_audit_log authenticated INSERT
inquiry_reminders authenticated SELECT
invitation_rules authenticated SELECT
review_pins anon SELECT
review_pins authenticated DELETE, INSERT, SELECT, UPDATE
user_relationships authenticated INSERT, SELECT, UPDATE
Each grant is exactly the commands that table's policies already cover, so
nothing is opened that a policy author had not already decided to open. Same
class as #481 and #654, and migrations 332 / 335 / 347 / 352 / 355 — each of
which fixed one table, as each was found by something failing.
## core.user_skills is deliberately left alone
It has the same shape — user_skills_select_public names `anon` with no grant —
but a grant is the wrong fix. The predicate reads core.preferences to check
profile_visibility -> skills, and `anon` cannot read that either, so granting
user_skills alone only moves the error:
permission denied for table preferences
HINT: GRANT SELECT ON core.preferences TO anon;
and taking that hint would expose every user's preferences to anonymous
readers. It needs a SECURITY DEFINER helper for the visibility lookup — a design
change rather than a missing grant. I granted it, saw the error move, and backed
it out. The API path is unaffected: the public skills widget reads through the
service client behind an explicit visibility check (#732).
## The guard
The test asks the database the question a user's request asks — can this role
actually read this table — rather than reading the catalogue. That also catches
the user_skills case, where the grant would exist and the predicate still could
not be evaluated. user_skills is pinned as a known gap, so fixing the predicate
fails the test and the exception gets removed rather than rotting.
Verified against a live stack: anonymous and authenticated reads of review_pins
both 200; pin_review then reading the pin back anonymously returns it. Confirmed
non-vacuous — revoking the grant fails two of the three tests.
API suite 349 passed / 79 failed, the known pre-existing set; nothing in pins,
grants or skills.
Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
📊 Performance Benchmark Results |
This was referenced Sep 15, 2026
thinkclay
added a commit
that referenced
this pull request
Sep 15, 2026
…green again (#763) `Lint REST API Code` has been failing on `main` since #758 merged (d2f52ff, 2026-09-14T22:43Z). `deno fmt --check` in packages/supabase/functions/api finds one unformatted file — a three-line import that fits on one — and fails the whole job, so every PR opened since inherits a red check it did not cause. error: Found 1 not formatted file in 146 files `deno lint` is clean, and this is `deno fmt`'s own output, so there is nothing to decide about it. Co-authored-by: Claude Opus 5 <[email protected]>
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.
Closes #755.
A policy decides which rows a role may see. A GRANT decides whether it may touch the table at all. Six core tables carry policies naming
anonorauthenticatedand issue no grant to those roles, so the policies are unreachable:Postgres names the fix — but only for whoever reads the raw error. Through the API it's a 401 or a 500.
Found smoke-testing production: a public profile reads
core.review_pinsdirectly and it failed for anonymous and signed-in visitors. Unlike theservice_roledrift in #751 this isn't an environment difference — local has the same hole, so pinned reviews have never worked anywhere. The writes go throughpin_review/unpin_review, which are SECURITY DEFINER and therefore worked, so a user could pin a review and never see it pinned.The sweep found five more
generic_invitationsinquiry_audit_loginquiry_remindersinvitation_rulesreview_pinsreview_pinsuser_relationshipsEach grant is exactly the commands that table's policies already cover, so nothing is opened that a policy author hadn't already decided to open. Same class as #481/#654 and migrations 332/335/347/352/355 — each of which fixed one table, as each was found by something failing.
core.user_skillsis deliberately left aloneSame shape —
user_skills_select_publicnamesanonwith no grant — but a grant is the wrong fix. The predicate readscore.preferencesto checkprofile_visibility -> skills, andanoncan't read that either, so grantinguser_skillsalone only moves the error:Taking that hint would expose every user's preferences to anonymous readers. It needs a SECURITY DEFINER helper for the visibility lookup — a design change, not a missing grant. I granted it, watched the error move, and backed it out. The API path is unaffected: the public skills widget reads through the service client behind an explicit visibility check (#732).
The guard
Asks the database the question a user's request asks — can this role actually read this table — rather than reading the catalogue. That also catches the
user_skillscase, where the grant would exist and the predicate still couldn't be evaluated.user_skillsis pinned as a known gap, so fixing the predicate fails the test and the exception gets removed rather than rotting.Verified against a live stack
review_pinsread, anonymousreview_pinsread, authenticatedpin_review→ read the pin back anonymously[{"review_id":"…","position":1}]API suite 349 passed / 79 failed — the known pre-existing set; nothing in pins, grants or skills.
🤖 Generated with Claude Code