postgresql/src/fe_utils
Michael Paquier 6a67c540a6 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@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 14
Security: CVE-2026-6475
2026-05-11 05:13:48 -07:00
..
.gitignore Move psql's psqlscan.l into src/fe_utils. 2016-03-24 20:28:47 -04:00
archive.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
astreamer_file.c Prevent path traversal in pg_basebackup and pg_rewind 2026-05-11 05:13:48 -07:00
astreamer_gzip.c Fix multiple bugs in astreamer pipeline code. 2026-03-29 09:02:15 -04:00
astreamer_lz4.c Fix finalization of decompressor astreamers. 2026-03-22 18:06:48 -04:00
astreamer_tar.c Prevent path traversal in pg_basebackup and pg_rewind 2026-05-11 05:13:48 -07:00
astreamer_zstd.c Fix finalization of decompressor astreamers. 2026-03-22 18:06:48 -04:00
cancel.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
conditional.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
connect_utils.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
Makefile Drop warning-free support for Flex 2.5.35 2025-01-15 15:35:08 +01:00
mbprint.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
meson.build Drop warning-free support for Flex 2.5.35 2025-01-15 15:35:08 +01:00
option_utils.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
parallel_slot.c Fix grammatical typos around possessive "its" 2025-01-29 14:39:14 +07:00
print.c Fix incorrect format placeholders 2025-04-25 16:49:30 +02:00
psqlscan.l Fix accidentally-harmless thinko in psqlscan_test_variable(). 2025-03-31 12:16:32 -04:00
query_utils.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
recovery_gen.c pg_rewind: Add dbname to primary_conninfo when using --write-recovery-conf. 2025-03-12 16:56:04 -07:00
simple_list.c pg_restore cleanups 2025-04-16 12:04:34 -04:00
string_utils.c In fmtIdEnc(), handle failure of enlargePQExpBuffer(). 2025-02-16 12:46:35 -05:00