Skip to content

Commit f419e3a

Browse files
committed
only allow certain extensions in requires key in control file
1 parent ca4e31a commit f419e3a

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

supabase/migrations/20231110061036_allow_publishing_relocatable_and_requires.sql

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,124 @@
1+
-- A list of extensions which are allowed in the requires key of the control file
2+
create table app.allowed_extensions (
3+
name text primary key
4+
);
5+
6+
insert into app.allowed_extensions (name)
7+
values
8+
-- extensions available on Supabase
9+
('citext'),
10+
('pg_cron'),
11+
('pg_graphql'),
12+
('pg_stat_statements'),
13+
('pg_trgm'),
14+
('pg_crypto'),
15+
('pg_jwt'),
16+
('pg_sodium'),
17+
('plpgsql'),
18+
('uuid-ossp'),
19+
('address_standardizer'),
20+
('address_standardizer_data_us'),
21+
('autoinc'),
22+
('bloom'),
23+
('btree_gin'),
24+
('btree_gist'),
25+
('cube'),
26+
('dblink'),
27+
('dict_int'),
28+
('dict_xsyn'),
29+
('earthdistance'),
30+
('fuzzystrmatch'),
31+
('hstore'),
32+
('http'),
33+
('hypopg'),
34+
('insert_username'),
35+
('intarray'),
36+
('isn'),
37+
('ltree'),
38+
('moddatetime'),
39+
('pg_hashids'),
40+
('pg_jsonschema'),
41+
('pg_net'),
42+
('pg_repack'),
43+
('pg_stat_monitor'),
44+
('pg_walinspect'),
45+
('pgaudit'),
46+
('pgroonga'),
47+
('pgroonga_database'),
48+
('pgrouting'),
49+
('pgrowlocks'),
50+
('pgtap'),
51+
('plcoffee'),
52+
('pljava'),
53+
('plls'),
54+
('plpgsql_check'),
55+
('plv8'),
56+
('postgis'),
57+
('postgis_raster'),
58+
('postgis_sfcgal'),
59+
('postgis_tiger_geocoder'),
60+
('postgis_topology'),
61+
('postgres_fdw'),
62+
('refint'),
63+
('rum'),
64+
('seg'),
65+
('sslinfo'),
66+
('supautils'),
67+
('tablefunc'),
68+
('tcn'),
69+
('timescaledb'),
70+
('tsm_system_rows'),
71+
('tsm_system_time'),
72+
('unaccent'),
73+
('vector'),
74+
('wrappers'),
75+
76+
-- extensions available on AWS (except those already in Supabase)
77+
-- full list here: https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-extensions.html
78+
('amcheck'),
79+
('aws_commons'),
80+
('aws_lambda'),
81+
('aws_s3'),
82+
('bool_plperl'),
83+
('decoder_raw'),
84+
('h3-pg'),
85+
('hll'),
86+
('hstore_plperl'),
87+
('intagg'),
88+
('ip4r'),
89+
('jsonb_plperl'),
90+
('lo'),
91+
('log_fdw'),
92+
('mysql_fdw'),
93+
('old_snapshot'),
94+
('oracle_fdw'),
95+
('orafce'),
96+
('pageinspect'),
97+
('pg_bigm'),
98+
('pg_buffercache'),
99+
('pg_freespacemap'),
100+
('pg_hint_plan'),
101+
('pg_partman'),
102+
('pg_prewarm'),
103+
('pg_proctab'),
104+
('pg_similarity'),
105+
('pg_tle'),
106+
('pg_transport'),
107+
('pg_visibility'),
108+
('pgcrypto'),
109+
('pgstattuple'),
110+
('pgvector'),
111+
('plperl'),
112+
('plprofiler'),
113+
('plrust'),
114+
('pltcl'),
115+
('prefix'),
116+
('rdkit'),
117+
('rds_tools'),
118+
('tds_fdw'),
119+
('test_parser'),
120+
('wal2json');
121+
1122
grant insert (partial_name, handle, control_description, control_relocatable, control_requires)
2123
on app.packages
3124
to authenticated;
@@ -17,11 +138,24 @@ create or replace function public.publish_package(
17138
as $$
18139
declare
19140
account app.accounts = account from app.accounts account where id = auth.uid();
141+
require text;
20142
begin
21143
if account.handle is null then
22144
raise exception 'user not logged in';
23145
end if;
24146

147+
foreach require in array requires
148+
loop
149+
if not exists (
150+
select true
151+
from app.allowed_extensions
152+
where
153+
name = require
154+
) then
155+
raise exception '`requires` in the control file can''t have `%` in it', require;
156+
end if;
157+
end loop;
158+
25159
insert into app.packages(handle, partial_name, control_description, control_relocatable, control_requires)
26160
values (account.handle, package_name, package_description, relocatable, requires)
27161
on conflict on constraint packages_handle_partial_name_key

0 commit comments

Comments
 (0)