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 9a037a4
Showing 1 changed file with 12 additions and 0 deletions.
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 9a037a4

Please sign in to comment.