From cdeac5efdba5a3d7057ca7e35726504d7160a47d Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Tue, 3 Feb 2026 08:07:59 -0600 Subject: [PATCH] gh-74453: Add stronger security warning to os.path.commonprefix (GH-144401) (cherry picked from commit 4e15b8d95da9a0f58ad58283979c37e43ff61229) Co-authored-by: Seth Michael Larson --- Doc/library/os.path.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst index 4a187af3bf3576..910cc37e460801 100644 --- a/Doc/library/os.path.rst +++ b/Doc/library/os.path.rst @@ -95,15 +95,17 @@ the :mod:`glob` module.) .. function:: commonprefix(list) - Return the longest path prefix (taken character-by-character) that is a - prefix of all paths in *list*. If *list* is empty, return the empty string + Return the longest string prefix (taken character-by-character) that is a + prefix of all strings in *list*. If *list* is empty, return the empty string (``''``). - .. note:: + .. warning:: This function may return invalid paths because it works a - character at a time. To obtain a valid path, see - :func:`commonpath`. + character at a time. + If you need a **common path prefix**, then the algorithm + implemented in this function is not secure. Use + :func:`commonpath` for finding a common path prefix. ::