Search-path security
Overview
Unqualified names in PostgreSQL resolve according to search_path. Only trusted schemas should participate in name resolution for privileged code. SECURITY DEFINER functions run with their owner’s privileges, unlike SECURITY INVOKER. Objective: distinguish qualified object identity from an unqualified name.
First example
SELECT schema_name,object_name FROM sec_objects WHERE object_name='report' ORDER BY schema_name;Observed SQLite result (rows in JSON):
[ [ "app", "report" ], [ "sandbox", "report" ]]How it works
Use schema-qualified references and a fixed safe function search_path, with pg_temp explicitly last; restrict CREATE in trusted schemas, revoke default PUBLIC EXECUTE where appropriate, grant only needed execution rights and use a minimally privileged owner. SQLite does not implement PostgreSQL search_path; this catalog exercise models ambiguity only.
Practical example
SELECT schema_name||'.'||object_name FROM sec_objects WHERE schema_name='app' AND object_name='report' AND trusted=1;Observed SQLite result (rows in JSON):
[ [ "app.report" ]]Practice and mistakes
Practice: identify the trusted report object. Hint 1: filter object_name. Hint 2: select the trusted schema explicitly. Check: app.report only. Mistake: relying on the caller’s path in privileged functions.
PostgreSQL 17 example — NOT RUN
SHOW search_path;Expected result, not executed: "Reports current search path, not proof of trusted schema permissions."