Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aef7eda

Browse filesBrowse files
[3.13] gh-123726: Document caveats of zipfile.Path around name sanitization (GH-130537) (#130986)
gh-123726: Document caveats of zipfile.Path around name sanitization (GH-130537) Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution. (cherry picked from commit a3990df) Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
1 parent fead51d commit aef7eda
Copy full SHA for aef7eda

File tree

1 file changed

+8
-0
lines changed
Filter options

1 file changed

+8
-0
lines changed

‎Doc/library/zipfile.rst

Copy file name to clipboardExpand all lines: Doc/library/zipfile.rst
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ Path Objects
543543
e.g. 'dir/file.txt', 'dir/', or ''. Defaults to the empty string,
544544
indicating the root.
545545

546+
.. note::
547+
The :class:`Path` class does not sanitize filenames within the ZIP archive. Unlike
548+
the :meth:`ZipFile.extract` and :meth:`ZipFile.extractall` methods, it is the
549+
caller's responsibility to validate or sanitize filenames to prevent path traversal
550+
vulnerabilities (e.g., filenames containing ".." or absolute paths). When handling
551+
untrusted archives, consider resolving filenames using :func:`os.path.abspath`
552+
and checking against the target directory with :func:`os.path.commonpath`.
553+
546554
Path objects expose the following features of :mod:`pathlib.Path`
547555
objects:
548556

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.