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 1oO2Ix-0000ZT-Li for pgsql-docs@arkaria.postgresql.org; Tue, 16 Aug 2022 19:32:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oO2Iw-0005bj-8l for pgsql-docs@arkaria.postgresql.org; Tue, 16 Aug 2022 19:32:46 +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 1oO2Iw-0005ba-0w for pgsql-docs@lists.postgresql.org; Tue, 16 Aug 2022 19:32:46 +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 1oO2Ip-0004OA-Ff for pgsql-docs@lists.postgresql.org; Tue, 16 Aug 2022 19:32:44 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1oO2Im-00EoWE-AD; Tue, 16 Aug 2022 15:32:36 -0400 Date: Tue, 16 Aug 2022 15:32:36 -0400 From: Bruce Momjian To: Erki Eessaar Cc: "pgsql-docs@lists.postgresql.org" Subject: Re: SQL-standard function bodies and creating SECURITY DEFINER routines securely Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="6fxbbgSDZf+WynL7" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6fxbbgSDZf+WynL7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Dec 25, 2021 at 02:36:27PM +0000, Erki Eessaar wrote: > > Hello > > PostgreSQL 14 added the feature: "Allow SQL-language functions and procedures > to use SQL-standard function bodies." > > If I understand correctly, then in this case the system will track > dependencies between tables and routines that use the tables. Thus, the > SECURITY DEFINER routines that use the new approach do not require the > following mitigation, i.e., SET search_path= is not needed. The following part > of documentation does not mention this. > > https://www.postgresql.org/docs/current/sql-createfunction.html# > SQL-CREATEFUNCTION-SECURITY > > [elephant] PostgreSQL: Documentation: 14: CREATE FUNCTION > Overloading. PostgreSQL allows function overloading; that is, the > same name can be used for several different functions so long as > they have distinct input argument types.Whether or not you use it, > this capability entails security precautions when calling functions > in databases where some users mistrust other users; see Section > 10.3.. Two functions are considered the same if they have the same > ... > www.postgresql.org I have written the attached patch to mention this issue about sql_body functions. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Indecision is a decision. Inaction is an action. Mark Batterson --6fxbbgSDZf+WynL7 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="function.diff" diff --git a/doc/src/sgml/ref/create_function.sgml b/doc/src/sgml/ref/create_function.sgml index 7e6d52c7dc..976d4caad6 100644 --- a/doc/src/sgml/ref/create_function.sgml +++ b/doc/src/sgml/ref/create_function.sgml @@ -779,7 +779,10 @@ SELECT * FROM dup(42); Because a SECURITY DEFINER function is executed with the privileges of the user that owns it, care is needed to - ensure that the function cannot be misused. For security, + ensure that the function cannot be misused. This is particularly + important for non-sql_body functions because + their function bodies are evaulated at run-time, not creation time. + For security, should be set to exclude any schemas writable by untrusted users. This prevents malicious users from creating objects (e.g., tables, functions, and --6fxbbgSDZf+WynL7--