Skip to content

Commit

Permalink
Add security definer and search_path to event trigger functions.
Browse files Browse the repository at this point in the history
Similar to #156, this prevents users from defining their own versions of functions used in the event triggers. Either one should be sufficient on its own, but both provides better defense against regressions.
  • Loading branch information
dwsteele committed Nov 4, 2021
1 parent 1818afb commit 438fc93
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MODULE_big = pgaudit
OBJS = pgaudit.o $(WIN32RES)

EXTENSION = pgaudit
DATA = pgaudit--1.5.sql
DATA = pgaudit--1.5.1.sql pgaudit--1.5--1.5.1.sql
PGFILEDESC = "pgAudit - An audit logging extension for PostgreSQL"

REGRESS = pgaudit
Expand Down
32 changes: 32 additions & 0 deletions pgaudit--1.5--1.5.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgaudit" to load this file.\quit

-- Drop old triggers and functions
drop event trigger if exists pgaudit_ddl_command_end;
drop function if exists pgaudit_ddl_command_end();

drop event trigger if exists pgaudit_sql_drop;
drop function if exists pgaudit_sql_drop();

-- Create triggers and functions with security definer and search_path
CREATE FUNCTION pgaudit_ddl_command_end()
RETURNS event_trigger
SECURITY DEFINER
SET search_path = 'pg_catalog, pg_temp'
LANGUAGE C
AS 'MODULE_PATHNAME', 'pgaudit_ddl_command_end';

CREATE EVENT TRIGGER pgaudit_ddl_command_end
ON ddl_command_end
EXECUTE PROCEDURE pgaudit_ddl_command_end();

CREATE FUNCTION pgaudit_sql_drop()
RETURNS event_trigger
SECURITY DEFINER
SET search_path = 'pg_catalog, pg_temp'
LANGUAGE C
AS 'MODULE_PATHNAME', 'pgaudit_sql_drop';

CREATE EVENT TRIGGER pgaudit_sql_drop
ON sql_drop
EXECUTE PROCEDURE pgaudit_sql_drop();
4 changes: 4 additions & 0 deletions pgaudit--1.5.sql → pgaudit--1.5.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

CREATE FUNCTION pgaudit_ddl_command_end()
RETURNS event_trigger
SECURITY DEFINER
SET search_path = 'pg_catalog, pg_temp'
LANGUAGE C
AS 'MODULE_PATHNAME', 'pgaudit_ddl_command_end';

Expand All @@ -12,6 +14,8 @@ CREATE EVENT TRIGGER pgaudit_ddl_command_end

CREATE FUNCTION pgaudit_sql_drop()
RETURNS event_trigger
SECURITY DEFINER
SET search_path = 'pg_catalog, pg_temp'
LANGUAGE C
AS 'MODULE_PATHNAME', 'pgaudit_sql_drop';

Expand Down
2 changes: 1 addition & 1 deletion pgaudit.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pgaudit extension
comment = 'provides auditing functionality'
default_version = '1.5'
default_version = '1.5.1'
module_pathname = '$libdir/pgaudit'
relocatable = true

0 comments on commit 438fc93

Please sign in to comment.