Skip to content

core.review_links grants only postgres — both review-link endpoints 500 #654

Closed

Description

@thinkclay

Reproduce

GET /v1/reviews/links
{"error":"Failed to fetch review links","message":"permission denied for table review_links"}

GET /v1/reviews/links/by-token/{token}
{"error":"Lookup failed","message":"permission denied for table review_links"}

Verified against a live local stack.

Cause

select grantee, string_agg(privilege_type, ',')
from information_schema.role_table_grants
where table_schema='core' and table_name='review_links' group by 1;

 postgres | INSERT,SELECT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER

No authenticated, no service_role. Compare core.reviews, which has both.

Same class as #481 and migrations 332/335: the table is created with RLS and a policy, and the GRANT that makes the policy reachable is forgotten, so it surfaces as a server error rather than a permission one.

by-token is the path a reviewer follows from an emailed link, so this breaks review collection end to end.

Acceptance

  • A migration grants service_role and the appropriate authenticated privileges on core.review_links
  • Both endpoints return 200 against a live stack
  • by-token still refuses a token that is not the caller's to use — check the policy, not only the grant

Found by the runtime sweep behind #651.

Activity

  1. added
    bug
    agent-ready
    on Aug 27, 2026
  2. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    Correction to how this was diagnosed, now fixed in #723.

    I wrote that core.review_links had no policies at all. It had four — review_links_owner_{select,insert,update,delete}, created by migration 326 alongside ENABLE ROW LEVEL SECURITY, with exactly the predicate I then re-added under different names.

    The fix was still right. 326 wrote the policies but never issued a GRANT, so authenticated and service_role had no privileges and every endpoint answered permission denied. The GRANTs in 347 are what resolved it — this is the #481 / 332 / 335 pattern, as filed. Only the policy half was redundant, and #723 drops it.

    The bad reading came from:

    select polname||' | '||polcmd from pg_policy where polrelid=...
    ERROR:  operator is not unique: text || "char"
    

    run with 2>/dev/null. The error printed nothing, an empty result looked like a finding, and it went into the migration comment, the PR and this issue. pg_policies shows them plainly — which is what I used for role_assignments in the same PR, and why that half was correct.

    Nothing was widened at any point: the duplicate predicates were identical, and permissive policies for the same command OR together.

  3. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    Deployed. Migrations 347 + 351 applied and recorded in all three environments.

    Before, identically in dev, preview and prod:

    grants:   postgres only
    policies: review_links_owner_{select,insert,update,delete}   (from 326)
    

    which confirms the correction on this issue — the policies were always there; only the GRANTs were missing. 351 was therefore a clean no-op remotely, since 347 had never been applied to create the redundant set.

    After, identically in all three:

    grants:   authenticated=SELECT/INSERT/UPDATE/DELETE, service_role=..., postgres=...
    policies: review_links_owner_*   (unchanged)
    

    Verified functionally rather than by inspection — querying as the authenticated role, before and after:

    before after
    dev / preview / prod ERROR: 42501: permission denied for table review_links 0 rows, RLS scoping correctly

    That error is the exact production symptom this issue reported, so the fix is confirmed against the real databases and not just locally.

    Note for anyone tracking rollout: this endpoint's repair needed only the schema change, so it is live now. The route hardening from #667 (the explicit subject_user_id filter, and 404 instead of 200 when revoking someone else's link) ships with the api edge function, which has not been deployed since 2026-08-12.

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