Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wi3B1-000YTJ-14 for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Jul 2026 04:49:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wi3Ay-00Fpt2-1t for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Jul 2026 04:49:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wi3Ay-00Fpsu-0h for pgsql-bugs@lists.postgresql.org; Fri, 10 Jul 2026 04:49:25 +0000 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wi3Aw-00000000QDA-1bnd for pgsql-bugs@lists.postgresql.org; Fri, 10 Jul 2026 04:49:24 +0000 Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-51c15bf5000so2249851cf.3 for ; Thu, 09 Jul 2026 21:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783658962; cv=none; d=google.com; s=arc-20260327; b=suQAAnXcXtC0How88DRdCONWSFu5xP7Fy7/1POnGwVDWktgGfpwnvdHHgOglUJ6gtM z088QvtqFlkBn2wjMw9EFkMSukc48DFkeohUR5/mJaREjSZrjRztMX9g+l919b+svncz IuCVszkXPJeKRsDNry8btCV0x6LarUqKKDVM/+kiXpC4NLIJrk5wK8p1VOoGltET9lW/ KGzR4G+OBBD/cr0eB+31ywsy3CXtCrq3QOLpxreguL2tlpFXvwkjuIS0WjmDabg9yoK2 MOFNQPnb+R+b/mX4v1KvV/Z1I/7a1nsXGSABsAyQ1WS2XGLO8zYMRl3NrexW7dE5kK9e xWnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=IjAzS0eFTDrAPYRrU6eZuXuqumMYdDaTdZDE8t7XMu8=; fh=uMpN+JClxh8iWO8xp9QqNNV5TibIEDW3vT3TFi3qtCQ=; b=q4eIMcKEr7PLHgr3qyi/Y+l/0GEpvC3SjdnL4K9o70scv6ird2Dr3SzNzt14D5OJGU UjDMuVEaU853g9h0NQrvXUp2A5P/CjIBfXBKlRkfcQHZoOO4LIkRgjfnUXVPTLTGnpai okeBQqCKddoOOOaKgSBJoySgBMxywUclwqnwEh9XyL/b07S+1oE1B0F3dp4CkEV+1H1l eFUaB4zwD49NLqp1/FmkvD4IGOXVEkRLTbEKDeAh7PLmWEoVuUtgzE/rPWysO4lv+8qW r3FS/JdMWGD8b9E14fSCLMaQxUksCm/mu9VZyMUK78myX6VgbFf2bRmyLb7PKkbISr8Z t4PA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783658962; x=1784263762; darn=lists.postgresql.org; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:from:to:cc:subject:date:message-id:reply-to :content-type; bh=IjAzS0eFTDrAPYRrU6eZuXuqumMYdDaTdZDE8t7XMu8=; b=Y2Z+BfXthBp/e8Nw1H7DWe3B2T9HpV8CG5e/+nTH1+RBHRo4V0CagDeqzK1C5svwPd iqoGT6wlPZy/Kr2bJYiZUh8xig3g40owZwb/p5VHQr1HpBuu0xSDG1mMOHAYhahhAlVM 2nGCjIMT2IZQtUv6RkFXKj21h4cIOiJEXVitK8eHpsky0IDwk0dfBDmI1XRKbiKasq1h uQF7gKDloHtC5LnJjL/C6CqybVl9vxp7zNvXMbAVhMvyRw8cgDlJ6TyrVYetdONjVYsj M286LV5Q1sQs0LVQETsYNm7USupDVtGEOI2X8z8yzvR6kHOlxiUMsueib195Id/J+ZSM bBdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783658962; x=1784263762; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=IjAzS0eFTDrAPYRrU6eZuXuqumMYdDaTdZDE8t7XMu8=; b=Kz7ALUjXVnId3z1YvhPgvljzIYrf6QpoDlXb9YuvFd5rNcqM+zZ/tgTsF1I4oHIBjp FsC+kY71JyDgDDuKCdx8wUfmSfLUsG5IqRqzltM7F2pbQ8MchH6VdWNwdnyLUaA/2Abe L4nnVMmFKo8xbm4llyerjQ68ahFMefpMtGrwjpPv/9ycFPhIPHz2Fv7jxasM9zPdlQXl oS+eiJansfEfDjSI7l2IEu4qGUX2thxFADBQHuA4BvqRrLAh+x7hvXm4Gw+/RLC7IvLj Bc/Y2S/NPYCtt3Jw3nLtbUv7lINq2nXzGTI2oGPxhIbu8jQEWv6REdzGzEP0w29BClB2 ZpxA== X-Gm-Message-State: AOJu0YxYJvA1d4ytAqhOHkv/Vp9uHJ/iL8NvEMvLRuupyqsevYvqYXc2 1BTdzzTEsncXJ4rQJHAH5ThrFMkx6JDDbs6T04FV2REYGiv127naFsirSMivf+HvR9QOCY69Y0O Ancabs+1OZuaJFqIA0h/61LOlv2Ygu84= X-Gm-Gg: AfdE7cnpri9/wFlnWt7XkXQ3gHo/gCrZ1sATpWhA+lICLt+3001AMt1/yPmhEbXrE6D HRgRuIfh22YJbl2nz2+qUdgTj0Mro8ob1fbujPMioLu4T1vNmjDrMN3Fn5sh94KuRC2/WWgvXVs 4Xt+LhVwwRAx7Ixx/oB0tg4hZvuB7xOHuzmuzJPO+K+ZYUJ9mUVGkN/rX0FyvZl4g9I9xaJhyoM jILSikPgeZTBQoYHllbNhop5r7mgPKnkWKKqoeqwtDfn09s6aVk9phOdVCmLJQfhnehIYiS4NU9 V67KfzYZcDwjJZ37Dm/KZ3/oETzGAaJoWD/BsVc4p5k1MKMxo2YU8i0XpqgezDTAzUnk0Gs= X-Received: by 2002:a05:622a:d3:b0:51c:7b12:6004 with SMTP id d75a77b69052e-51c8b57db22mr124475961cf.80.1783658961759; Thu, 09 Jul 2026 21:49:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Kirill Reshke Date: Fri, 10 Jul 2026 09:49:10 +0500 X-Gm-Features: AVVi8Cf8kK-dj8Dz6GXV_2mUGTzRXmTfnkr72mO6UqPeLJ1cVHF_kPVlaaZX8wM Message-ID: Subject: Re: BUG #19523: psql tab-completion shadows pg_db_role_setting To: Vismay Tiwari Cc: PostgreSQL mailing lists Content-Type: multipart/alternative; boundary="000000000000d0f14706563a76de" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d0f14706563a76de Content-Type: text/plain; charset="UTF-8" Hi! You seem to create two threads on the issue, so I don't quite understand where to respond. anyway: On Thu, 9 Jul 2026, 15:14 Vismay Tiwari, wrote: > Hi, > > Reproduced on current master. The tab-completion query for > "ALTER DATABASE ... RESET" (Query_for_list_of_database_vars) references > pg_db_role_setting and pg_database without a pg_catalog qualification, so a > same-named table earlier in search_path shadows the catalog: > > CREATE SCHEMA attacker; > CREATE TABLE attacker.pg_db_role_setting (setdatabase oid, setrole > oid, setconfig text[]); > INSERT INTO attacker.pg_db_role_setting > SELECT oid, 0, ARRAY['evil_var=x'] FROM pg_database WHERE > datname = 'postgres'; > SET search_path = attacker, pg_catalog; > -- "ALTER DATABASE postgres RESET " then offers evil_var > > Preventing this makes sense in case somebody accidentally misconfigured their server. Which is not very probable for a table with ` pg_db_role_setting` name. Also note that this is not a vulnerability: from https://www.postgresql.org/docs/current/app-psql.html says: If untrusted users have access to a database that has not adopted a secure schema usage pattern, begin your session by removing publicly-writable schemas from search_path. Anyway +1 on fixing --000000000000d0f14706563a76de Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi! You = seem to create two threads on the issue, so I don't=C2=A0quite understa= nd where=C2=A0to respond. anyway:

On Thu, 9 Jul 2026, 15:14 Vismay Tiwari, <= ;vismay.t@gmail.com= > wrote:
= Hi,

Reproduced on current master. The tab-completion query for
"ALTER DATABASE ... RESET" (Query_for_list_of_database_vars) refe= rences
pg_db_role_setting and pg_database without a pg_catalog qualification, so a=
same-named table earlier in search_path shadows the catalog:

=C2=A0 =C2=A0 CREATE SCHEMA attacker;
=C2=A0 =C2=A0 CREATE TABLE attacker.pg_db_role_setting (setdatabase oid, se= trole
oid, setconfig text[]);
=C2=A0 =C2=A0 INSERT INTO attacker.pg_db_role_setting
=C2=A0 =C2=A0 =C2=A0 SELECT oid, 0, ARRAY['evil_var=3Dx'] FROM pg_d= atabase WHERE
datname =3D 'postgres';
=C2=A0 =C2=A0 SET search_path =3D attacker, pg_catalog;
=C2=A0 =C2=A0 -- "ALTER DATABASE postgres RESET <TAB>" then= offers evil_var


Preventing this makes= sense=C2=A0in case somebody=C2=A0accidentally=C2=A0misconfigured their ser= ver. Which is not very probable=C2=A0for a table with `pg_db_role_setting` name.
Also not= e that this is not a vulnerability: from https://www.postgresql.org/docs/current/app= -psql.html says:

=C2=A0 If untrusted users have access to a data= base that has not adopted a secure
=C2=A0 schema usage pattern, begin yo= ur session by removing publicly-writable
=C2=A0 schemas from search_path= .

Anyw= ay=C2=A0+1 on fixing

=C2=A0
<= /div>
--000000000000d0f14706563a76de--