8000 Require execute permission on the trigger function for CREATE TRIGGER. · jcsston/postgres@993b3e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 993b3e5

Browse files
committed
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
1 parent 94e2495 commit 993b3e5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

doc/src/sgml/ref/create_trigger.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
183183

184184
<para>
185185
To create a trigger on a table, the user must have the
186-
<literal>TRIGGER</literal> privilege on the table.
186+
<literal>TRIGGER</literal> privilege on the table. The user must
187+
also have <literal>EXECUTE</literal> privilege on the trigger function.
187188
</para>
188189

189190
<para>

src/backend/commands/trigger.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid, bool checkPermissions)
161161
* Find and validate the trigger function.
162162
*/
163163
funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
164+
aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE);
165+
if (aclresult != ACLCHECK_OK)
166+
aclcheck_error(aclresult, ACL_KIND_PROC,
167+
NameListToString(stmt->funcname));
164168
funcrettype = get_func_rettype(funcoid);
165169
if (funcrettype != TRIGGEROID)
166170
{

0 commit comments

Comments
 (0)
0