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 1wO6e6-001JeW-1a for pgsql-bugs@arkaria.postgresql.org; Sat, 16 May 2026 04:29:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wO6e5-002GNZ-0X for pgsql-bugs@arkaria.postgresql.org; Sat, 16 May 2026 04:29:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wO6e4-002GNR-2u for pgsql-bugs@lists.postgresql.org; Sat, 16 May 2026 04:29:00 +0000 Received: from mail-yx1-xb12e.google.com ([2607:f8b0:4864:20::b12e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wO6e2-00000000rua-2D6t for pgsql-bugs@lists.postgresql.org; Sat, 16 May 2026 04:29:00 +0000 Received: by mail-yx1-xb12e.google.com with SMTP id 956f58d0204a3-651bf695701so824797d50.2 for ; Fri, 15 May 2026 21:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778905737; cv=none; d=google.com; s=arc-20240605; b=OiApXdGly1x7A719t1S6yu/MXMB8JwXFBJcMvIovwC4+n+GhCA/wP6S56/Gey4FBhz BTor9GMAsE0Njd9H6FD3rrc+qOJ5EhiV+kP17VjvPqWH/7hL6kJEpKj99XE8LIZX1+D7 O4BAFVLqfAkQPoipdpl636SSqOesujWbw/45t2MhZcsn3nGKDMEO6MPwpBYg+FP14/gl tkjECCKMZ99HLl6Yaqzux/UpUu8WdiyanglzPWY0cly8Du/4YMX3+L/bUboN+kty4NAr APKqt2mGgYI9/Zme6MTppQJvuYQcw5WWEfWxSadf0otwTA7i9UMpNfxXysUHedwMzo4Y lQ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:dkim-signature; bh=KVD7zUYIjE6Wf1dJGw4SvfDp5fI50YyNKlrXw2T/PAU=; fh=OJZeKDDRsG+3XukQmy924vLw9O2Gr8oEsf9+JYVYNqc=; b=DBMAgmO8MPmmHE0GGAkhUNf4jXHyuymj/o1X7XVqdMBY26Q0FCncmyFVYX/EPNFT70 z9WNzjLseMEurF2xi6ywDhjAfxx+rCMKx7nixyJvnUxJXmfqZuOn4esx63zFeUBPsiLE Woihq0LI35/g4rAkx+dazz40FDyrmsWg5fk/W4Ka+2caCbNDz/wx+8b/6O9QcveD0DoI bHTR6wLXhTUvKVowCGmoIlF29DuJVNjcq5M7vR8ZEkUsHOcX+YYcxRIkGY9vMudSeIN2 gVniOjuUCL8l17GXhKLDYP1s2hqNPu0YOQNGowqHTF6LqMJC/mwFMT72oFYux1EFc54a TwYA==; 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=1778905737; x=1779510537; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KVD7zUYIjE6Wf1dJGw4SvfDp5fI50YyNKlrXw2T/PAU=; b=GjCBTP8hKi/LcZFqubPXDGXt4pME3IMIgPZGhcaRkWrcTZk7hw4eE0ayA+b0pG/3Jb SZ7rZWDD6mf651ITC0a2gnRSOlQlJ/8GHSz916tVWnt3WYtOsuX9U1gbF/EtDGpZNdXx oArYfr7J8g44LNm3bV05lQkjy4+rYEpHOIrKbkWZk7o/48+rYNxvQ7JAQbP7xFl8PYC+ uO3Hw4d05ZwD0KVm6SfTF1kGTggt6EYy/te72Xc6Hoz/J6FmvTBs5K8UBxb8mt8ze9KS 3UxmgmpVVqQJNJvriB7V+ko+JX0W0A0sk9EL6qex91Ob0gCD0YxGzbklYb5pvrnjhev/ 9bag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778905737; x=1779510537; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KVD7zUYIjE6Wf1dJGw4SvfDp5fI50YyNKlrXw2T/PAU=; b=h6iccfadx51waIv6gSd1DG7wQp+Fd/WqmlGwk0nxzu+kTvUfrSrMou8dYKub+/pGzg g0BtYkvCmCdB/l4IbiPDRBaSVBo4M1BUq0ubztRvr66LLAK556udtNCz0ta3YPwtQemg FTI9wPZHzY22CvmIqnCrROlqQFcCfX4mCVL4+mXUElJ366UmPjPdcLQNc8AVyLjmCraI zigXRScN5jPWystI8vl1Z3Fy6fpJpkOp1srXLuApHAHrT/Yv/ucPxKP1svde4KGopJmD ud71p0eX3lSKJrGhDp5Q+L6eAZqerbn/95WHuzUBIS9ge3DCzxsR1FcxNx4M08JexR9m 1L/A== X-Forwarded-Encrypted: i=1; AFNElJ+Qun6nir4NDV81PibhAcwHEQpBWhgeh2lMKdOfNmPUnhhaylFcpY/ML0qod7FHJ8LmnR88QfzWzCXk@lists.postgresql.org X-Gm-Message-State: AOJu0Yxd/Ea+T3M6FJayAr+IQT2reKCjysZK2Dwvqw7QwlHtluq4kjZR 7trNkSJ/niA7yNErw3lUkTquhkMTLMNFBy7IY2Hhb6fuaL8iQFdl2qbvmSWz4uAX2ERMV6nCE1c zf/Z5uAtvbMbJUXg0cFHC+zAL01WdBoo= X-Gm-Gg: Acq92OHKCqZK6TPaOdpx0QYdzXyoLV2RrAReI25vcLy2JSYK4S81lmf32DcijPnpvX8 +0OnSow0/k/Nj9WsRTcTWw9wmB5h+pAF+56HDLZj/jeD5T5xMvUQfI7QGugBUlTKCThipkbA7Xo XaljYlXhFEKwA+ZB0hl5AYt1emYscKCNCXSMz4rAJMZTS+qxPr4FL5mjg8pSZYoFy+yHKASl/v1 ohmnrV/l0W36RSKIZ6Fbs2bNt2lCeDZzoEDsMVsuUP5utwAOhy135/epeJryiFDDktXXgmnaFTm cBSy8gBChP1fwiiXYYcyg8Yt0SSHME4UIUWRGhBf8xWrBRn4eA== X-Received: by 2002:a05:690e:1285:b0:657:4568:c4c4 with SMTP id 956f58d0204a3-65e226d9078mr7472673d50.18.1778905736904; Fri, 15 May 2026 21:28:56 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:7011:c147:20b0:515:8e2b:dba3 with HTTP; Fri, 15 May 2026 21:28:56 -0700 (PDT) In-Reply-To: References: <19478-37289e8b0d1a1299@postgresql.org> From: "David G. Johnston" Date: Fri, 15 May 2026 21:28:56 -0700 X-Gm-Features: AVHnY4LoZYhYnClCDzp31vpP5Zduh5gc6KnKJPHy2BTxhLK-uugmgRXhQzamsJ4 Message-ID: Subject: Re: BUG #19478: `dblink_close` can be used for injection. To: Kirill Reshke Cc: Japin Li , PostgreSQL mailing lists , zengman Content-Type: multipart/alternative; boundary="0000000000008985240651e7c4da" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008985240651e7c4da Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, May 15, 2026, Kirill Reshke wrote: > > > On Sat, 16 May 2026, 06:24 Japin Li, wrote: > >> On Fri, 15 May 2026 at 01:29, PG Bug reporting form < >> noreply@postgresql.org> wrote: >> > The following bug has been logged on the website: >> > >> > Bug reference: 19478 >> > Logged by: Man Zeng >> > Email address: zengman@halodbtech.com >> > PostgreSQL version: 18.4 >> > Operating system: 24.04.1-Ubuntu >> > Description: >> > >> > >> > >> > - appendStringInfo(&buf, "CLOSE %s", curname); >> > + appendStringInfo(&buf, "CLOSE %s", quote_ident_cstr(curname)); >> > >> >> >> According to the documentation [1], it should be a cursor name. Wrappin= g >> it >> in quotes can prevent attacks like SQL injection. I think your >> modification >> is correct, and we should add test cases for it. >> >> [1] https://www.postgresql.org/docs/current/contrib-dblink-close.html >> > > Well, is there any actual injection? I mean, if user can execute >> dblink_close, then user can do an SQL with dblink_open and simply do a S= QL? >> Unless wierd case when we only granted with close function, I guess >> > Switching to quote_ident means we no longer lowercase an unquoted input. Is this improvement in api design worth the potential breakage? If so, make sure we at least change the dblink_open (and fetch=E2=80=A6) code simi= larly. I=E2=80=99m disinclined to change this unless it=E2=80=99s shown the only p= ossible use of the identifier is within the dblink function arguments where can change all uses to quote_identifier. Even then, inconsistent capitalization still might exist. David J. --0000000000008985240651e7c4da Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, May 15, 2026, Kirill Reshke <reshkekirill@gmail.com> wrote:


On Sat, 16 May 2026, 06:24 Japin Li, <japinli@hotmail.com> wrote:
On Fri, 15 May 2026 at= 01:29, PG Bug reporting form <noreply@postgresql.org> wrote:=
> The following bug has been logged on the website:
>
> Bug reference:=C2=A0 =C2=A0 =C2=A0 19478
> Logged by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Man Zeng
> Email address:=C2=A0 =C2=A0 =C2=A0 zengman@halodbtech.com
> PostgreSQL version: 18.4
> Operating system:=C2=A0 =C2=A024.04.1-Ubuntu
> Description:=C2=A0 =C2=A0 =C2=A0 =C2=A0
>
>
>=C2=A0
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0appendStringInfo(&buf, "CLOSE %s&= quot;, curname);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0appendStringInfo(&buf, "CLOSE %s&= quot;, quote_ident_cstr(curname));
>=C2=A0


According to the documentation [1], it should be a cursor name.=C2=A0 Wrapp= ing it
in quotes can prevent attacks like SQL injection.=C2=A0 I think your modifi= cation
is correct, and we should add test cases for it.

[1] https://www.postgres= ql.org/docs/current/contrib-dblink-close.html
=C2=A0
Well, is there any actual injection? = I mean, if user can execute dblink_close, then user can do an SQL with=C2= =A0dblink_open and simply do a SQL? Unless wierd case when we only granted = with close function, I guess

Switching to quote_ident means we no longer lowercase = an unquoted input.=C2=A0 Is this improvement in api design worth the potent= ial breakage?=C2=A0 If so, make sure we at least change the dblink_open (an= d fetch=E2=80=A6) code similarly.

I=E2=80=99m disi= nclined to change this unless it=E2=80=99s shown the only possible use of t= he identifier is within the dblink function arguments where can change all = uses to quote_identifier.=C2=A0 Even then, inconsistent capitalization stil= l might exist.

David J.

--0000000000008985240651e7c4da--