PG-417: Replace 'CREATE OR REPLACE' with 'CREATE' for extension.
While analyzing the pg_stat_monitor installation scripts I found several vulnerabilities. pg_stat_monitor uses CREATE OR REPLACE to install its functions which is a security hazard. An attacker can precreate the functions have a superuser install the extension and after installation the attacker can switch out the function with a malicious version since he would still be the owner of the function. Instead of CREATE OR REPLACE the installation script should use plain CREATE to prevent this attack. For reference https://www.postgresql.org/docs/current/extend-extensions.html#EXTEND-EXTENSIONS-SECURITY https://github.com/timescale/pgspotpull/232/head
parent
b3a2b8daf0
commit
a59bca088a
|
@ -89,7 +89,7 @@ RETURNS SETOF record
|
|||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
CREATE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
|
@ -102,7 +102,7 @@ SELECT
|
|||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE or REPLACE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
|
@ -225,7 +225,7 @@ SELECT
|
|||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION histogram(_bucket int, _quryid text)
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid text)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
|
|
|
@ -89,7 +89,7 @@ RETURNS SETOF record
|
|||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
CREATE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
|
@ -102,7 +102,7 @@ SELECT
|
|||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE or REPLACE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
|
@ -226,7 +226,7 @@ SELECT
|
|||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION histogram(_bucket int, _quryid text)
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid text)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
|
|
|
@ -86,7 +86,7 @@ RETURNS SETOF record
|
|||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
CREATE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
|
@ -99,7 +99,7 @@ SELECT
|
|||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE or REPLACE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
|
@ -212,7 +212,7 @@ SELECT
|
|||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION histogram(_bucket int, _quryid text)
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid text)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
|
|
Loading…
Reference in New Issue