Skip to content

Enable RLS on notification tables and fix RLS-disabled exposed tables #170

Closed

Description

@thinkclay

Summary

Supabase Database Linter reported that several tables have RLS policies defined but RLS is not enabled on the table (so policies have no effect), and many tables in schemas exposed to PostgREST have no RLS at all. One table exposes a sensitive column (token) without RLS. This can lead to unauthorized data access or data exposure.

Risk

  • Policies on notification tables are not enforced; table access is unrestricted.
  • Exposed tables without RLS are readable/writable according to role grants.
  • core.notification_devices.token may expose device push tokens.

Affected objects

Policy exists but RLS disabled (enable RLS and keep policies):

  • core.notification_deliveries (policies: notification_deliveries_select_own, notification_deliveries_service_all)
  • core.notification_devices (policies: notification_devices_service_all, notification_devices_user_all)
  • core.notification_digest_queue (policies: notification_digest_queue_select_own, notification_digest_queue_service_all)
  • core.notification_events (policies: notification_events_select_own, notification_events_service_all)
  • core.notification_preferences (policies: notification_preferences_service_all, notification_preferences_user_all)

RLS disabled in public / exposed (add RLS and appropriate policies):

  • Core: notification_* tables; ONET: many reference tables (task_ratings, tasks_to_dwas, occupation_level_metadata, etc.); Data: trades, masterformat, universities, certifications; Public: spatial_ref_sys

Sensitive column exposed without RLS:

  • core.notification_devices — column token (e.g. push token) exposed via API without RLS.

Remediation

  1. For the five core.notification_* tables: run ALTER TABLE core.<table> ENABLE ROW LEVEL SECURITY; so existing policies take effect. See Policy Exists RLS Disabled.
  2. For all other exposed tables: enable RLS and add policies that match intended access. See RLS Disabled in Public.
  3. Ensure core.notification_devices is not exposed without RLS and that token is only accessible to authorized roles. See Sensitive Columns Exposed.

References

Activity

  1. thinkclay commented on Mar 10, 2026

    @thinkclay
    ContributorAuthor

    Implemented (Phase 1 of security hardening plan):

    • Migration added: 402_enable_rls_notification_tables.sql enables RLS on the five core.notification_* tables (notification_deliveries, notification_events, notification_preferences, notification_devices, notification_digest_queue). Policies from 025_req_89_notifications_expansion.sql were already in place; they now take effect for authenticated requests. service_role continues to bypass RLS.
    • Applied locally: Migration history repaired (migration repair --status reverted 202 --local), then migration up --local --include-all applied 402 successfully.
    • RLS regression test added: packages/supabase/functions/trpc/__tests__/integration/notifications.test.ts — new test "Notifications router - list returns only rows for authenticated user (RLS regression)" asserts every returned notification has user_id matching the authenticated user.
    • Verification: pnpm supa:generate and pnpm test:unit pass. Full test:endpoints is blocked by one pre-existing auth test ("Worker failed to boot"); once that is fixed, notification integration tests (including the new RLS test) will run in the suite.

    Remaining remediation from the original issue (RLS on other exposed tables, sensitive column exposure) is out of scope for this change and can be tracked separately or in a follow-up.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions