Skip to content

Commit

Permalink
Check if schema already exists before create extension
Browse files Browse the repository at this point in the history
If the schema aiven_extras already exists and belongs to an
unprivileged user before adding the extension, it’s possible
to abuse it to run some queries in the context of the superuser.

[BF-2375]
  • Loading branch information
0xlianhu committed Mar 7, 2024
1 parent 1504010 commit bb93ca9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
short_ver = 1.1.12
last_ver = 1.1.11
short_ver = 1.1.13
last_ver = 1.1.12
long_ver = $(shell git describe --long 2>/dev/null || echo $(short_ver)-0-unknown-g`git describe --always`)
generated = aiven_extras.control \
sql/aiven_extras--$(short_ver).sql \
Expand Down
1 change: 1 addition & 0 deletions sql/aiven_extras--1.1.11--1.1.12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- NOOP
12 changes: 12 additions & 0 deletions sql/aiven_extras.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
-- Check that if schema owned by other already exist
DO LANGUAGE plpgsql
$$
BEGIN
IF EXISTS (
SELECT * FROM information_schema.schemata WHERE schema_name = 'aiven_extras' AND schema_owner <> current_user
) THEN
RAISE EXCEPTION 'Cannot create extension, schema ''aiven_extras'' owned by other user already exists';
END IF;
END
$$;

DO LANGUAGE plpgsql
$OUTER$
DECLARE
Expand Down

0 comments on commit bb93ca9

Please sign in to comment.