pgsql: Prevent path traversal in pg_basebackup and pg_rewind

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Prevent path traversal in pg_basebackup and pg_rewind
Date: 2026-05-11 12:19:41
Message-ID: E1wMPbp-0002g9-0M@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Prevent path traversal in pg_basebackup and pg_rewind

pg_rewind and pg_basebackup could be fed paths from rogue endpoints that
could overwrite the contents of the client when received, achieving path
traversal.

There were two areas in the tree that were sensitive to this problem:
- pg_basebackup, through the astreamer code, where no validation was
performed before building an output path when streaming tar data. This
is an issue in v15 and newer versions.
- pg_rewind file operations for paths received through libpq, for all
the stable branches supported.

In order to address this problem, this commit adds a helper function in
path.c, that reuses path_is_relative_and_below_cwd() after applying
canonicalize_path(). This can be used to validate the paths received
from a connection point. A path is considered invalid if any of the two
following conditions is satisfied:
- The path is absolute.
- The path includes a direct parent-directory reference.

Reported-by: XlabAI Team of Tencent Xuanwu Lab
Reported-by: Valery Gubanov <valerygubanov95(at)gmail(dot)com>
Author: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Backpatch-through: 14
Security: CVE-2026-6475

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/498829dca45ad207a23954fe2e5a30ed2ef4b363
Author: Michael Paquier <michael(at)paquier(dot)xyz>

Modified Files
--------------
src/bin/pg_rewind/file_ops.c | 23 +++++++++++++++++++++++
src/include/port.h | 1 +
src/port/path.c | 17 +++++++++++++++++
3 files changed, 41 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-05-11 13:40:29 Re: pgsql: Release notes for 18.4, 17.10, 16.14, 15.18, 14.23.
Previous Message Noah Misch 2026-05-11 12:19:40 pgsql: Add raw_connect and raw_connect_works to Cluster.pm