Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ognWD-0000OH-NV for pgsql-docs@arkaria.postgresql.org; Fri, 07 Oct 2022 13:36:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ognWB-0007g1-CU for pgsql-docs@arkaria.postgresql.org; Fri, 07 Oct 2022 13:35:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ognWB-0007fs-4y for pgsql-docs@lists.postgresql.org; Fri, 07 Oct 2022 13:35:59 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ognW4-0005rU-E3 for pgsql-docs@lists.postgresql.org; Fri, 07 Oct 2022 13:35:58 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1ognW1-005nGZ-K3; Fri, 07 Oct 2022 09:35:49 -0400 Date: Fri, 7 Oct 2022 09:35:49 -0400 From: Bruce Momjian To: Erki Eessaar Cc: "pgsql-docs@lists.postgresql.org" , Noah Misch , Peter Eisentraut Subject: Re: SQL-standard function bodies and creating SECURITY DEFINER routines securely Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Oct 7, 2022 at 08:05:36AM +0000, Erki Eessaar wrote: > Hello > > I confirmed, that setting search_path is indeed sometimes needed in case of > SECURITY DEFINER routines that have SQL-standard bodies. See an example at the > end of the letter. > > I suggest the following paragraph to the documentation: > > Starting from PostgreSQL 14 SQL-standard bodies can be used in SQL-language > functions. This form tracks dependencies between the function and objects used > in the function body. However, there is still a possibility that such function > calls other code that reacts to search path. Thus, as a best practice, SECURITY > DEFINER functions with SQL-standard bodies should also override search_path. I think this gets back to what Noah said about this section not needing to explain all the details but rather give general guidance. I am not sure adding the reasons for _why_ you should use search path for SQL-standard bodies is really adding anything. Noah, is that accurate? -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Indecision is a decision. Inaction is an action. Mark Batterson