Skip to content

Commit 229f91f

Browse files
michelpsvenklemm
andauthored
Use explicit schema in format calls in DO blocks (#120)
The DO blocks in the version update scripts did not sufficiently lock down search_path for the format calls allowing injection of a malicious format function to be executed during upgrades. Co-authored-by: Sven Klemm <sven@timescale.com>
1 parent b0eefc4 commit 229f91f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

extension/pgsodium--1.1.1--1.2.0.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ BEGIN
107107
'pgsodium_keymaker']
108108
LOOP
109109
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = new_role) THEN
110-
EXECUTE format($i$
110+
EXECUTE pg_catalog.format($i$
111111
CREATE ROLE %I WITH
112112
NOLOGIN
113113
NOSUPERUSER
@@ -152,7 +152,7 @@ BEGIN
152152
'crypto_sign_new_keypair'
153153
]
154154
LOOP
155-
EXECUTE format($i$
155+
EXECUTE pg_catalog.format($i$
156156
REVOKE ALL ON FUNCTION %s FROM PUBLIC;
157157
GRANT EXECUTE ON FUNCTION %s TO pgsodium_keymaker;
158158
$i$, func, func);
@@ -188,7 +188,7 @@ BEGIN
188188
'crypto_sign_update_agg2'
189189
]
190190
LOOP
191-
EXECUTE format($i$
191+
EXECUTE pg_catalog.format($i$
192192
REVOKE ALL ON FUNCTION %s FROM PUBLIC;
193193
GRANT EXECUTE ON FUNCTION %s TO pgsodium_keyholder;
194194
$i$, func, func);
@@ -220,7 +220,7 @@ BEGIN
220220
'crypto_shorthash'
221221
]
222222
LOOP
223-
EXECUTE format($i$
223+
EXECUTE pg_catalog.format($i$
224224
REVOKE ALL ON FUNCTION %s FROM PUBLIC;
225225
GRANT EXECUTE ON FUNCTION %s TO pgsodium_keyiduser;
226226
$i$, func, func);

extension/pgsodium--1.2.0--2.0.0.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ BEGIN
169169
'crypto_aead_det_keygen'
170170
]
171171
LOOP
172-
EXECUTE format($i$
172+
EXECUTE pg_catalog.format($i$
173173
REVOKE ALL ON FUNCTION %s FROM PUBLIC;
174174
GRANT EXECUTE ON FUNCTION %s TO pgsodium_keymaker;
175175
$i$, func, func);
@@ -194,7 +194,7 @@ BEGIN
194194
'crypto_aead_det_decrypt(bytea, bytea, bytea, bytea)'
195195
]
196196
LOOP
197-
EXECUTE format($i$
197+
EXECUTE pg_catalog.format($i$
198198
REVOKE ALL ON FUNCTION %s FROM PUBLIC;
199199
GRANT EXECUTE ON FUNCTION %s TO pgsodium_keyholder;
200200
$i$, func, func);
@@ -214,7 +214,7 @@ BEGIN
214214
'crypto_aead_det_decrypt(bytea, bytea, bigint, bytea, bytea)'
215215
]
216216
LOOP
217-
EXECUTE format($i$
217+
EXECUTE pg_catalog.format($i$
218218
REVOKE ALL ON FUNCTION %s FROM PUBLIC;
219219
GRANT EXECUTE ON FUNCTION %s TO pgsodium_keyiduser;
220220
$i$, func, func);

extension/pgsodium--3.0.4--3.0.5.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ BEGIN
870870
'pgsodium.crypto_aead_ietf_decrypt(bytea, bytea, bytea, uuid)'
871871
]
872872
LOOP
873-
EXECUTE format($i$
873+
EXECUTE pg_catalog.format($i$
874874
REVOKE ALL ON FUNCTION %s FROM PUBLIC;
875875
GRANT EXECUTE ON FUNCTION %s TO pgsodium_keyiduser;
876876
$i$, func, func);

0 commit comments

Comments
 (0)