Skip to content

Make functions schema-safe via pinned search_path - #69

Merged
seanwevans merged 2 commits into
mainfrom
claude/searchpath-robustness
Jun 26, 2026
Merged

Make functions schema-safe via pinned search_path#69
seanwevans merged 2 commits into
mainfrom
claude/searchpath-robustness

Conversation

@seanwevans

Copy link
Copy Markdown
Owner

Problem

Installing the extension into a non-default schema and then calling its functions failed unless the caller's search_path happened to include that schema:

CREATE EXTENSION pg_os WITH SCHEMA os;
SET search_path = public;
SELECT os.create_user('alice');
-- ERROR: relation "users" does not exist

The SECURITY INVOKER functions referenced their tables unqualified and inherited whatever search_path the session had.

Fix

  • Pin SET 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.
  • GRANT USAGE ON SCHEMA @extschema@ TO pgos_admin so the SECURITY DEFINER locking helpers can reach those tables outside public. PUBLIC only receives that USAGE for the public schema automatically, so without this create_mutex etc. failed with "relation mutexes does not exist" in a custom-schema install.

Test

Adds a schema_install regression test that installs into a dedicated schema, removes that schema from search_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

claude and others added 2 commits June 26, 2026 19:38
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
@seanwevans
seanwevans merged commit 874be45 into main Jun 26, 2026
0 of 2 checks passed
@seanwevans
seanwevans deleted the claude/searchpath-robustness branch June 26, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants