Make functions schema-safe via pinned search_path - #69
Merged
Conversation
When the extension was installed into a non-default schema, calling its functions failed with "relation ... does not exist" unless the caller happened to have that schema on their search_path. The SECURITY INVOKER functions referenced their tables unqualified and inherited whatever search_path the session had. Pin search_path = @extschema@, pg_temp on every function and procedure (the SECURITY DEFINER helpers already did this), so they always resolve the extension's own tables regardless of the caller's search_path. Also grant pgos_admin USAGE on the install schema so the SECURITY DEFINER locking helpers can reach those tables outside the public schema (PUBLIC only receives that USAGE for public automatically). Adds a schema_install regression test that installs into a dedicated schema, drops that schema from the search_path, and exercises the user/process/memory/file and mutex paths through fully-qualified calls. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ty3Rkif9Vfe95w8TMiKB4b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Installing the extension into a non-default schema and then calling its functions failed unless the caller's
search_pathhappened to include that schema:The SECURITY INVOKER functions referenced their tables unqualified and inherited whatever
search_paththe session had.Fix
SET search_path = @extschema@, pg_tempon every function and procedure (the SECURITY DEFINER helpers already did this), so they always resolve the extension's own tables regardless of the caller'ssearch_path.GRANT USAGE ON SCHEMA @extschema@ TO pgos_adminso the SECURITY DEFINER locking helpers can reach those tables outsidepublic.PUBLIConly receives thatUSAGEfor thepublicschema automatically, so without thiscreate_mutexetc. failed with "relation mutexes does not exist" in a custom-schema install.Test
Adds a
schema_installregression test that installs into a dedicated schema, removes that schema fromsearch_path, and exercises the user/role/process, memory, filesystem and mutex paths through fully-qualified calls. Suite is green (14/14 on this branch).🤖 Generated with Claude Code
Generated by Claude Code