summaryrefslogtreecommitdiff
path: root/src/backend/commands/trigger.c
diff options
context:
space:
mode:
authorTom Lane2012-02-23 20:38:56 +0000
committerTom Lane2012-02-23 20:38:56 +0000
commit891e6e7bfd9bb72687522af08c18689f795cb60a (patch)
tree712c343bd83a23e56bbfb7aa6ad16c002debbc23 /src/backend/commands/trigger.c
parent74e29162a4f0ec0ad1c7224b8be936d1f9a51f7e (diff)
Require execute permission on the trigger function for CREATE TRIGGER.
This check was overlooked when we added function execute permissions to the system years ago. For an ordinary trigger function it's not a big deal, since trigger functions execute with the permissions of the table owner, so they couldn't do anything the user issuing the CREATE TRIGGER couldn't have done anyway. However, if a trigger function is SECURITY DEFINER, that is not the case. The lack of checking would allow another user to install it on his own table and then invoke it with, essentially, forged input data; which the trigger function is unlikely to realize, so it might do something undesirable, for instance insert false entries in an audit log table. Reported by Dinesh Kumar, patch by Robert Haas Security: CVE-2012-0866
Diffstat (limited to 'src/backend/commands/trigger.c')
-rw-r--r--src/backend/commands/trigger.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 2838b66e402..caae2dafab1 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -108,8 +108,8 @@ static void AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
* if TRUE causes us to modify the given trigger name to ensure uniqueness.
*
* When isInternal is not true we require ACL_TRIGGER permissions on the
- * relation. For internal triggers the caller must apply any required
- * permission checks.
+ * relation, as well as ACL_EXECUTE on the trigger function. For internal
+ * triggers the caller must apply any required permission checks.
*
* Note: can return InvalidOid if we decided to not create a trigger at all,
* but a foreign-key constraint. This is a kluge for backwards compatibility.
@@ -377,6 +377,13 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
* Find and validate the trigger function.
*/
funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
+ if (!isInternal)
+ {
+ aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, ACL_KIND_PROC,
+ NameListToString(stmt->funcname));
+ }
funcrettype = get_func_rettype(funcoid);
if (funcrettype != TRIGGEROID)
{