Sql-server – Permissions required to execute UDF Scalar Function inside a trigger

sql-server-2016

I have a scalar function that user don't have execute permissions on. However the users have select , insert, update , delete permissions on a table that has a trigger and the trigger calls the scalar function. The user gets an error when they try to run the function saying that they don't have execute permissions on the function which is fine. But when the user runs a update query on the table that fires off the trigger, the functions runs fine . How does that work?

Best Answer

Permissions on indirectly referenced objects are not checked as long as the objects involved have the same owner. This is known as ownership chaining. Users need permission on only the object used directly (table in this case), not on the objects used by the trigger (e.g. function) as long as the ownership chain is unbroken.

One can leverage ownership chains to encapsulate functionality in views, stored procedures, triggers, and functions without granting direct permissions.

See the Ownership Chains topic in the Authorization and Permissions in SQL Server documentation for more information.