Skip to content

Set explicit search_path on database functions #172

Closed

Description

@thinkclay

Summary

The linter reported many functions that do not set an explicit search_path. Relying on the session's search_path can make behavior depend on the caller and open the door to search_path-based attacks. Setting search_path on each function (e.g. to the function's schema) fixes this.

Affected objects

Run Supabase MCP get_advisors with type: "security" and filter by function_search_path_mutable. Affected schemas: core, data, forsured, onet, public (many functions in each).

Remediation

  1. For each function, add a fixed search_path (e.g. SET search_path = core) in the function definition.
  2. Example: CREATE OR REPLACE FUNCTION core.foo() RETURNS ... SET search_path = core AS $$ ... $$;
  3. See Function Search Path Mutable.

References

Activity

  1. thinkclay commented on Mar 10, 2026

    @thinkclay
    ContributorAuthor

    Implemented (Phase 3 of security hardening):

    • Migration added: 404_function_search_path.sql sets an explicit search_path on all application-owned functions in schemas core, data, forsured, onet, and public. Each function gets search_path set to its own schema. Only functions owned by the migration runner (current_user) are altered, so extension/system functions (e.g. public.regexp_split_to_table) are skipped.
    • Applied locally: migration 404 applied successfully; pnpm supa:generate run.
    • Effect: Functions no longer rely on the session's search_path, reducing risk of search_path-based attacks.
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