Skip to content

fix(db): 10 functions from migrations 314-325 have no search_path #468

Closed

Description

@thinkclay

Found while fixing #442.

308_function_search_path.sql gives every owned function in core/data/community/onet/public an explicit search_path (Supabase advisor #172). But 10 functions have none, because they were created by migrations 314–325 — i.e. after 308 ran. They were never covered, in either 308's original form or the fixed one.

community.get_skill_ancestors
community.gift_karma
community.search_skill_taxonomy
community.set_updated_at
community.update_community_member_count
community.update_post_comment_count
community.update_post_rating_stats
community.update_scaffold_score
community.update_upvote_count
core.tasks_handle_completion

Verified against a freshly reset local DB:

select count(*) from pg_proc p join pg_namespace n on n.oid = p.pronamespace
where n.nspname in ('core','data','community','onet','public') and p.prokind = 'f'
  and p.proowner = (select oid from pg_roles where rolname = current_user)
  and not exists (select 1 from unnest(coalesce(p.proconfig,'{}')) c where c like 'search_path=%');
-- 10

Mostly trigger functions plus core.tasks_handle_completion, so the practical risk is low today — but a positional sweep migration is inherently a one-shot fix, and anything added after it drifts out of compliance silently.

Suggested fix: rather than another positional sweep that will go stale the same way, add the search_path to each function's own definition, and/or add a CI check asserting the count above is zero so a new function without one fails the build.

Note #442 changed 308 to preserve declared search_paths instead of overwriting them, so re-running it is now safe — but it still only covers functions that exist when it runs.

Activity

  1. added
    bug
    on Jul 30, 2026
  2. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    Fixed. The issue's own verification query returns 0 on a current local database:

    select count(*) from pg_proc p join pg_namespace n on n.oid = p.pronamespace
    where n.nspname in ('core','data','community','onet','public') and p.prokind = 'f'
      and p.proowner = (select oid from pg_roles where rolname = current_user)
      and not exists (select 1 from unnest(coalesce(p.proconfig,'{}')) c where c like 'search_path=%');
    -- 0

    All ten named functions now carry an explicit search_path, including the community.* set from migrations 314–325 and core.tasks_handle_completion.

    Worth noting for anyone adding a SECURITY DEFINER function later: 308 only covered what existed when it ran, so this class of gap reappears with every new definer function unless the migration sets search_path itself. Migration 349 (#703) does.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions