Skip to content

core.review_pins has four policies and no grants, so pinned reviews are unreadable for everyone #755

Closed

Description

@thinkclay

Found smoke-testing production. A public profile makes a direct PostgREST call to core.review_pins that fails.

Not just anonymous — everyone

anonymous      GET /rest/v1/review_pins  ->  401
authenticated  GET /rest/v1/review_pins  ->  403
{"code":"42501","message":"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 in the error.

The policies are right; the grant was never issued

review_pins_public_select  SELECT  {anon,authenticated}
review_pins_owner_insert   INSERT  {authenticated}
review_pins_owner_update   UPDATE  {authenticated}
review_pins_owner_delete   DELETE  {authenticated}

grants: postgres only

Four policies were written, including one deliberately opening SELECT to anon — so public reads are clearly intended — and no GRANT was issued to make any of them reachable. Same defect as #481, #654 and migrations 332 / 335 / 347 / 352.

This one is not prod-only drift. Local grants are postgres, service_role, so authenticated cannot read there either. It has never worked in any environment.

What that looks like in the product

packages/scf-core/features/reviews/hooks/useReviewPins.ts reads the table directly:

supabase.schema('core').from('review_pins').select(...)

while pin_review and unpin_review are RPCs, which run as definer and therefore work. So a user can pin a review and then never see that it is pinned. ReviewsWidget renders on profile pages, so the failure is on every profile that loads it.

Acceptance

  • A migration granting SELECT to anon and authenticated, and INSERT/UPDATE/DELETE to authenticated, matching what the four policies already assume
  • GET /rest/v1/review_pins returns rows for an anonymous caller and for a signed-in one, in dev, preview and prod
  • A pinned review is visibly pinned after pin_review — the round trip, not just the write
  • Consider whether the read should go through an RPC like the writes do, rather than a direct table select from the client

Related: #751 lists twenty core tables missing service_role grants; review_pins is on that list too, but this is a different hole in the same table — anon and authenticated are missing as well, and those are the ones the feature actually needs.

Activity

  1. added
    bug
    agent-ready
    on Sep 14, 2026
  2. thinkclay commented on Sep 14, 2026

    @thinkclay
    ContributorAuthor

    Fixed and deployed. #758 (merged), migration 356 applied to dev, preview and prod — all three ledgers read unrecorded: 0.

    anonymous read of core.review_pins
      DEV      200   (was 401)
      PREVIEW  200
      PROD     200
    

    Round trip verified against a live stack: pin_review via RPC, then reading the pin back anonymously returns [{"review_id":"…","position":1}]. That is the acceptance criterion this issue asked for — the write already worked, since the RPCs are SECURITY DEFINER; it was the read that never did.

    It was six tables, not one

    The sweep that found review_pins found five siblings with the same shape:

    table role policy commands
    generic_invitations authenticated INSERT, SELECT, UPDATE
    inquiry_audit_log authenticated INSERT
    inquiry_reminders authenticated SELECT
    invitation_rules authenticated SELECT
    review_pins anon / authenticated SELECT / DELETE, INSERT, SELECT, UPDATE
    user_relationships authenticated INSERT, SELECT, UPDATE

    Each grant is exactly the commands that table's policies already cover, so nothing was opened that a policy author had not already decided to open.

    One I deliberately did not fix

    core.user_skills has the same shape, and a grant is the wrong fix. Its user_skills_select_public 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;
    

    Taking that hint would expose every user's preference row to anonymous readers. It needs a SECURITY DEFINER helper for the visibility lookup, which is a design change rather than a missing grant. I granted it, watched the error move, and backed it out. Filed as its own thing rather than papered over; the API path is unaffected, since the public skills widget reads through the service client behind an explicit visibility check (#732).

    The recurrence

    This is the sixth time this defect has been fixed — migrations 332, 335, 347, 352, 355, now 356 — each found by something failing where a person happened to look. The new guard asks the database the question a request asks (can this role actually read this table) rather than reading the catalogue, which also catches the user_skills case where a grant exists and the predicate still cannot be evaluated. Confirmed non-vacuous: revoking the grant fails two of its three tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions