Repository navigation
fix(api): review links were unreachable, and the org member list read a table that never existed (#654, #655) - #667
Merged
Conversation
… a table that never existed (#654, #655) ## #654 — core.review_links RLS enabled, grants only to postgres, and no policies at all. Every endpoint that touched it answered `permission denied for table review_links`, including GET /v1/reviews/links/by-token/{token} — the reviewer's entry point from a shared link, so review collection was dead end to end. That route already used the service client because it is anonymous. service_role bypasses RLS but still needs the table GRANT, which is why reaching for the service client did not save it. Same class as #481 and migrations 332/335. Migration 347 grants authenticated and service_role, and adds the four policies the table was missing, each scoped to subject_user_id = auth.uid(). Deliberately nothing for anon: a reviewer reaches a link through the service client, which checks expiry, revocation and use count first, and granting anon a direct SELECT would let anyone enumerate the table through PostgREST when the token is the only secret protecting it. Two things found while testing it: - GET /v1/reviews/links selected with no subject_user_id filter and leaned entirely on RLS to scope the result. With no policy that failed closed, but the policy was the only thing between a caller and every share link on the platform. Given an explicit filter as well. - Revoking another user's link answered 200 and did nothing. An UPDATE that matches no rows is not an error, and the handler never read back the row. Now 404 — not 403, so the response does not confirm the link exists. ## #655 — GET /v1/organizations/{id}/members Read core.organization_members, which exists in no schema, so it returned 500 for every organization. Membership is a role scoped to the org — core.role_assignments.scope_org_id — which is what lib/org-access.ts, /{id}/location-visibility and /{id}/projects-with-overrides have always used. Rewritten against role_assignments, gated by canReadOrgInternals (404 for a non-member, so it does not confirm which org ids exist), returning the OrganizationMember shape the SDK declares. Three things the rewrite had to get right, each verified against live data: - role_assignments carries one policy, `user_id = auth.uid()`, so reading it with the caller's own client returns a one-member organization. The seeded Unicorn org came back as 1 of 15. The access check above is what makes the service client safe here. - A person can hold several roles in one org, and some hold the same role twice. 15 assignments group to 11 people, deduplicated. - Search ran `ilike` against user_id, a uuid, so it could only ever match nothing. It now searches display_name and username, and roleNames — declared in the SDK's ListMembersParams and previously ignored — is honoured. firstOf was referenced by the new handler but defined privately in work-logs.ts. That typechecks under the current deno config and throws at runtime, which is how it reached a live probe; it is now lib/postgrest.ts, imported by both. Verified against a live stack: 11 members matching the database, search and roleNames filtering correctly, 404 for a non-member; review links list, create, by-token as an anonymous caller, 404 on a bad or revoked token, another user seeing none of them, and anon unable to enumerate the table directly. Schema guard baseline 33 -> 32 references. API suite 325 passed / 80 failed against 317 / 80; failure sets diffed by name, zero newly failing. Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Sep 10, 2026
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 #654. Closes #655.
#654 —
core.review_linksRLS enabled, grants only to
postgres, and no policies at all. Every endpoint touching it answeredpermission denied for table review_links— includingGET /v1/reviews/links/by-token/{token}, the reviewer's entry point from a shared link. Review collection was dead end to end.That route already used the service client because it's anonymous.
service_rolebypasses RLS but still needs the table GRANT, which is why reaching for the service client didn't save it. Same class as #481 and migrations 332/335.Migration 347 grants
authenticatedandservice_role, and adds the four missing policies, each scoped tosubject_user_id = auth.uid().Deliberately nothing for
anon: a reviewer reaches a link through the service client, which checks expiry, revocation and use count first. Grantinganona direct SELECT would let anyone enumerate the table through PostgREST, and the token is the only secret protecting it.Two things found while testing it
GET /v1/reviews/linksselected with nosubject_user_idand leaned entirely on RLS. With no policy that failed closed — but the policy was the only thing between a caller and every share link on the platform. Given an explicit filter too.by-tokenas an anonymous calleris_revokedunchangedanonhitting/rest/v1/review_linksdirectly#655 —
GET /v1/organizations/{id}/membersRead
core.organization_members, which exists in no schema, so it returned 500 for every organization. Membership is a role scoped to the org —core.role_assignments.scope_org_id— which is whatlib/org-access.ts,/{id}/location-visibilityand/{id}/projects-with-overrideshave always used. The members route was the odd one out.Rewritten against
role_assignments, gated bycanReadOrgInternals(404 for a non-member, so it doesn't confirm which org ids exist), returning theOrganizationMembershape the SDK declares.Three things the rewrite had to get right
RLS made the first attempt look fine.
role_assignmentscarries one policy —user_id = auth.uid()— so reading it with the caller's own client returns a one-member organization. The seeded Unicorn org came back as 1 of 15 and looked plausible. The access check above is what makes the service client safe here.A person can hold several roles, and some hold the same role twice. 15 assignments group to 11 people, deduplicated — matching
count(distinct user_id)exactly.Search filtered on a uuid. The old code ran
ilikeagainstuser_id, so it could only ever match nothing. Now searchesdisplay_nameandusername, androleNames— declared in the SDK'sListMembersParamsand previously ignored — is honoured.count(distinct user_id)admin,adminassignments?search=marc?roleNames=admin/=memberOne runtime-only bug this surfaced
firstOfwas referenced by the new handler but defined privately inwork-logs.ts. That typechecks under the current deno config and throws at runtime — it reached a live probe before anything caught it. Nowlib/postgrest.ts, imported by both, with the work-logs public feed re-probed for regression.Numbers
anon)Migration 347 is applied locally; it still needs applying to dev/preview/prod.
🤖 Generated with Claude Code