forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit01463e1
committed
Ensure that AFTER triggers run as the instigating user.
With deferred triggers, it is possible that the current role changesbetween the time when the trigger is queued and the time it isexecuted (for example, the triggering data modification could havebeen executed in a SECURITY DEFINER function).Up to now, deferred trigger functions would run with the current roleset to whatever was active at commit time. That does not matter forforeign-key constraints, whose correctness doesn't depend on thecurrent role. But for user-written triggers, the current rolecertainly can matter.Hence, fix things so that AFTER triggers are fired under the rolethat was active when they were queued, matching the behavior ofBEFORE triggers which would have actually fired at that time.(If the trigger function is marked SECURITY DEFINER, that of courseoverrides this, as it always has.)This does not create any new security exposure: if you do DML on atable owned by a hostile user, that user has always had various waysto exploit your permissions, such as the aforementioned BEFOREtriggers, default expressions, etc. It might remove some securityexposure, because the old behavior could potentially expose someother role besides the one directly modifying the table.There was discussion of making a larger change, such as running asthe trigger's owner. However, that would break the common idiom ofcapturing the value of CURRENT_USER in a trigger for auditing/loggingpurposes. This change will make no difference in the typical scenariowhere the current role doesn't change before commit.Arguably this is a bug fix, but it seems too big a semantic changeto consider for back-patching.Author: Laurenz Albe <laurenz.albe@cybertec.at>Reviewed-by: Joseph Koshakow <koshy44@gmail.com>Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>Discussion:https://postgr.es/m/77ee784cf248e842f74588418f55c2931e47bd78.camel@cybertec.at1 parent4e7f62b commit01463e1
File tree
4 files changed
+154
-0
lines changed- doc/src/sgml
- src
- backend/commands
- test/regress
- expected
- sql
4 files changed
+154
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3635 | 3635 | | |
3636 | 3636 | | |
3637 | 3637 | | |
| 3638 | + | |
3638 | 3639 | | |
3639 | 3640 | | |
3640 | 3641 | | |
| |||
4117 | 4118 | | |
4118 | 4119 | | |
4119 | 4120 | | |
| 4121 | + | |
4120 | 4122 | | |
4121 | 4123 | | |
4122 | 4124 | | |
| |||
4289 | 4291 | | |
4290 | 4292 | | |
4291 | 4293 | | |
| 4294 | + | |
| 4295 | + | |
4292 | 4296 | | |
4293 | 4297 | | |
4294 | 4298 | | |
| |||
4492 | 4496 | | |
4493 | 4497 | | |
4494 | 4498 | | |
| 4499 | + | |
| 4500 | + | |
| 4501 | + | |
| 4502 | + | |
| 4503 | + | |
| 4504 | + | |
| 4505 | + | |
| 4506 | + | |
| 4507 | + | |
| 4508 | + | |
| 4509 | + | |
4495 | 4510 | | |
4496 | 4511 | | |
4497 | 4512 | | |
| |||
4506 | 4521 | | |
4507 | 4522 | | |
4508 | 4523 | | |
| 4524 | + | |
| 4525 | + | |
| 4526 | + | |
| 4527 | + | |
4509 | 4528 | | |
4510 | 4529 | | |
4511 | 4530 | | |
| |||
6431 | 6450 | | |
6432 | 6451 | | |
6433 | 6452 | | |
| 6453 | + | |
6434 | 6454 | | |
6435 | 6455 | | |
6436 | 6456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3748 | 3748 | | |
3749 | 3749 | | |
3750 | 3750 | | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
| 3764 | + | |
| 3765 | + | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
| 3793 | + | |
| 3794 | + | |
| 3795 | + | |
| 3796 | + | |
| 3797 | + | |
| 3798 | + | |
| 3799 | + | |
| 3800 | + | |
| 3801 | + | |
| 3802 | + | |
| 3803 | + | |
| 3804 | + | |
| 3805 | + | |
| 3806 | + | |
| 3807 | + | |
| 3808 | + | |
| 3809 | + | |
| 3810 | + | |
| 3811 | + | |
| 3812 | + | |
| 3813 | + | |
| 3814 | + | |
| 3815 | + | |
| 3816 | + | |
| 3817 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2839 | 2839 | | |
2840 | 2840 | | |
2841 | 2841 | | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
| 2863 | + | |
| 2864 | + | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
0 commit comments
Comments
(0)