Re: delta relations in AFTER triggers - Mailing list pgsql-hackers

From Marti Raudsepp
Subject Re: delta relations in AFTER triggers
Date
Msg-id CABRT9RB4kUj7Hkgpqiik4Q1F_ZoHJ-X7M-+OeYH1L6CR5EFx7g@mail.gmail.com
Whole thread Raw
In response to Re: delta relations in AFTER triggers  (Kevin Grittner <kgrittn@ymail.com>)
List pgsql-hackers
On Thu, Sep 4, 2014 at 12:14 AM, Kevin Grittner <kgrittn@ymail.com> wrote:
>> Did I miss something?
>
> Apparently.  I did a search on the document and counted and got 101
> occurrences of "transition table".
> | A transient table is a named table that may come into existence
> | implicitly during the evaluation of a <query expression> or the
> | execution of a trigger.

D'oh, I was reading only the sections about triggers. You are correct.

Anyway, I tried out the latest from your GitHub branch and it seems
most of my concerns no longer apply to the current version, as
transition tables are now local to the trigger function. Thanks.

----
Not sure if you're looking for feedback on this level yet, but I tried
breaking it and found that transition tuplestores don't work with
cursors.

Probably not a valid use case once we have some other way to pass
tuplestores between functions. I don't know if it could work anyway,
as cursors may outlive the trigger call. But in that case, a better
error message is in order.

create table test1(i int);
create or replace function test1trg() returns trigger language plpgsql as $$
declare   curs cursor for select * from newtab;   r record;
begin   for r in curs loop   end loop;   return new;
end;$$;
create trigger test1trg after insert on test1 referencing new table as
newtab execute procedure test1trg();
insert into test1 values(1);
ERROR:  executor could not find named tuplestore "newtab"
CONTEXT:  PL/pgSQL function test1trg() line 6 at FOR over cursor

----
I still see a chance of introducing security problems with SECURITY
DEFINER trigger functions. An attacker can overshadow table names
queried by such a function and inject arbitrary data into it. Similar
to search_path vulnerabilities, but there are ways to avoid that.

Perhaps there should be a restriction when using REFERENCING and the
function is SECURITY DEFINER: require that the trigger definer (if not
superuser) matches the function owner?

Regards,
Marti



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: pg_background (and more parallelism infrastructure patches)
Next
From: Andres Freund
Date:
Subject: Re: pg_background (and more parallelism infrastructure patches)