Skip to content

fix(db): 8 core tables grant SELECT to authenticated but not service_role #481

Closed

Description

@thinkclay

Eight core.* tables are readable by authenticated (and mostly anon) but not by service_role. Any edge-function code that reaches for the service client — the normal way to bypass RLS — gets permission denied instead.

Reproduce

select c.relnamespace::regnamespace||'.'||c.relname as tbl
from pg_class c
where c.relkind='r'
  and c.relnamespace::regnamespace::text in ('core','data','onet')
  and has_table_privilege('authenticated', c.oid, 'SELECT')
  and not has_table_privilege('service_role', c.oid, 'SELECT')
order by 1;
core.archetypes
core.assessment_sessions
core.ipip_share_tokens
core.personality_assessments
core.portfolio_items
core.soft_skills
core.user_archetypes
core.user_assessment_xp

Or from a test:

await createAdminClient().schema("core").from("soft_skills").select("*").limit(1)
// { code: "42501", message: "permission denied for table soft_skills" }

Why it matters

service_role is the bypass-everything role; a table it cannot read is almost always an oversight in the migration that created it, not a policy. core.soft_skills in particular is public reference data seeded by migration 001 — there is no reason to withhold it.

This is the same class as the grants gaps fixed by migrations 332 (api_keys) and 335 (scheduling).

Where it bit

Hit while fixing #464 (PR #479). GET /v1/profiles/:username resolves skill names from core.soft_skills; reading that catalog with the service client fails, so the route reads catalogs with the caller's client and only user-owned rows with the service client. That workaround is fine on its own merits, but it was forced rather than chosen — see the comment on resolveSkillNames in packages/supabase/functions/api/routes/profiles.ts.

Suggested fix

A grants migration following the shape of 332/335, granting service_role the privileges its siblings already have. Check INSERT/UPDATE/DELETE too — this query only tests SELECT.

Acceptance

  • The query above returns zero rows.
  • createAdminClient().schema("core").from("soft_skills").select("*") succeeds.
  • packages/supabase/functions/api/__tests__/routes/profiles.test.ts still passes (it currently reads that catalog as anon specifically to dodge this).

Activity

  1. added
    bug
    agent-ready
    on Jul 30, 2026
  2. thinkclay commented on Aug 27, 2026

    @thinkclay
    ContributorAuthor

    Related instance found by a full sweep: core.review_links grants only to postgres — no authenticated, no service_role — so GET /v1/reviews/links and GET /v1/reviews/links/by-token/{token} both return permission denied, breaking review collection including the emailed reviewer link. Filed as #654 since it is a different table set from the eight here.

    The wider sweep (#660) found 45 references to tables that do not exist at all, which is the same failure mode one layer up: a table is created, or renamed, and the route that reads it is never checked. #651 adds a test that catches new instances of the missing-table half; the grants half is still only caught at runtime, so a companion check over information_schema.role_table_grants would close that gap too.

  3. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    Fixed. The issue's own reproduction query now returns nothing:

    select c.relnamespace::regnamespace||'.'||c.relname
    from pg_class c
    where c.relkind='r'
      and c.relnamespace::regnamespace::text in ('core','data','onet')
      and has_table_privilege('authenticated', c.oid, 'SELECT')
      and not has_table_privilege('service_role', c.oid, 'SELECT');
    -- (0 rows)

    All eight — archetypes, assessment_sessions, ipip_share_tokens, personality_assessments, portfolio_items, soft_skills, user_archetypes, user_assessment_xp — now grant to service_role.

    Closing on the local schema, which is the same migration set production runs. If someone confirms production separately and finds a gap, reopen.

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-readybugtype: backend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions