Skip to content

Review and fix security definer views #171

Closed

Description

@thinkclay

Summary

Six views are defined with SECURITY DEFINER. They run with the view owner's privileges and RLS context instead of the invoker's, which can bypass row-level security and lead to privilege escalation or unintended data exposure.

Affected objects

  • core.v_id_verification_latest
  • public.v_active_cron_jobs
  • core.v_team_daily_metrics_latest
  • core.v_team_member_workloads_latest
  • core.v_profile_search
  • core.v_news_feed_health

Remediation

  1. For each view, decide whether it must run as definer (e.g. for cross-schema access). If not, recreate the view with SECURITY INVOKER (default in newer Postgres).
  2. If definer is required, ensure the view definition and underlying objects are locked down and that only intended callers can use it.
  3. See Security Definer View.

References

Activity

  1. thinkclay commented on Mar 10, 2026

    @thinkclay
    ContributorAuthor

    Implemented (Phase 2 of security hardening):

    • Migration added: 403_security_invoker_views.sql sets security_invoker = on for five views so they run with the caller's privileges and RLS context:
      • core.v_id_verification_latest
      • core.v_team_daily_metrics_latest
      • core.v_team_member_workloads_latest
      • core.v_profile_search
      • core.v_news_feed_health
    • Left as SECURITY DEFINER: public.v_active_cron_jobs — it reads from cron.job (pg_cron); only the definer can read that catalog. Documented in the migration.
    • Applied locally: migration 403 applied successfully; pnpm supa:generate run.

    Callers of the five views must now have appropriate privileges on the underlying tables; RLS is enforced for the invoking role.

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