The following bug has been logged on the website:
Bug reference: 19714
Logged by: Qifan Liu
Email address: imchifan@163.com
PostgreSQL version: 18.6
Operating system: Linux on amd64
Description:
pgp_sym_encrypt accepts the malformed option s2k-mode=not_a_number and
produces usable ciphertext. The documented s2k-mode values are numeric modes
0, 1, and 3, so nonnumeric text should be rejected rather than silently
selecting mode 0. This can cause encryption to use a different string-to-key
mode than the caller specified. The impact is localized to pgcrypto option
validation.
Steps to reproduce
------------------
CREATE EXTENSION pgcrypto;
SELECT pgp_sym_decrypt(
pgp_sym_encrypt('payload',
'key',
's2k-mode=not_a_number'),
'key') = 'payload' AS malformed_s2k_mode_accepted;
Actual result
-------------
malformed_s2k_mode_accepted
-----------------------------
t
(1 row)
The malformed value is accepted, and the produced ciphertext decrypts
successfully.
Expected result
---------------
pgp_sym_encrypt should reject s2k-mode=not_a_number with an error because
s2k-mode accepts only the documented numeric values. It should not interpret
malformed text as mode 0 or produce ciphertext.
Additional information
----------------------
The issue was reproduced on PostgreSQL 20devel, PostgreSQL 18.6, and
PostgreSQL 17.11.
Inference: the behavior is consistent with numeric conversion that maps text
without a valid numeric prefix to zero before validating the resulting mode.