Skip to content

fix(db): core.system_config grants nothing to authenticated, so the geographic settings screen 403s on every read #856

Closed

Description

@thinkclay

Found by the release-1 route sweep (#852, PR #855).

Evidence

core.system_config has RLS off and grants only postgres and service_role:

select grantee||':'||privilege_type from information_schema.role_table_grants
where table_schema='core' and table_name='system_config';
-- postgres:*, service_role:*  — nothing for `authenticated`
select relrowsecurity from pg_class where oid='core.system_config'::regclass;  -- f

So every logged-in read through PostgREST answers 42501 insufficient privilege. The only caller is apps/scaffald/app/(admin)/office/settings/geographic.tsx:15-20, which reads site_overlap_threshold_percent directly through supabase.schema('core') rather than through the api edge function, and writes it back at :61.

This is the fifth instance of the same defect class — see #481 (8 tables), #751 (20 more), and the core_table_grants_gap pattern. The prepush guard added with #751 checks service_role only, which is why this one survived: the gap here is authenticated.

Change

  1. One idempotent migration granting the right privileges on core.system_config. Decide the shape first: either

    • GRANT SELECT TO authenticated + GRANT INSERT, UPDATE TO service_role and enable RLS with an office-role read policy, or
    • leave the table service-role-only and move the screen onto an api endpoint (/v1/office/settings/geographic), which matches how every other office screen reads privileged data.

    Recommendation: the second. A settings table that any authenticated user can read is a wider grant than the screen needs — the screen is office-role gated, the table is not — and every other office read already goes through the edge function with requireRole.

  2. Apply to dev/preview/prod via the Management API path, recording the ledger (numeric migrations bypass schema_migrations).

  3. Extend the prepush grants guard to check authenticated reads on tables the client queries directly, so the next one is caught by the guard rather than by a 403 storm.

Acceptance

  • /office/settings/geographic loads its current threshold and saves a new one, verified in a browser as an office user
  • No 42501 in the console on that route
  • The guard fails if the grant is removed again

Activity

  1. added
    bug
    agent-ready
    redesign
    on Sep 21, 2026
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

    Backendagent-readybugpriority: highredesigntype: backend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions