Skip to content

gh-123726: Document caveats of zipfile.Path around name sanitization #130537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2025

Conversation

AffanShaikhsurab
Copy link
Contributor

@AffanShaikhsurab AffanShaikhsurab commented Feb 25, 2025

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.

This Pr solves the issue #123726


📚 Documentation preview 📚: https://cpython-previews--130537.org.readthedocs.build/

…ation



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.
@ghost
Copy link

ghost commented Feb 25, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@jaraco jaraco self-assigned this Mar 8, 2025
@jaraco jaraco added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Mar 8, 2025
@jaraco jaraco merged commit a3990df into python:main Mar 8, 2025
27 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Mar 8, 2025
@miss-islington-app
Copy link

Thanks @AffanShaikhsurab for the PR, and @jaraco for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 8, 2025
…ation (pythonGH-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 <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Mar 8, 2025

GH-130986 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 8, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 8, 2025
…ation (pythonGH-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 <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Mar 8, 2025

GH-130987 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Mar 8, 2025
Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this over a few times. I considered changing it to point out that it's mostly relevant when manifesting names in a file system, or making a reference to the open issues around providing a sanitizing extractor, but decided against that. This is a good, complete contribution. Thanks!

jaraco pushed a commit that referenced this pull request Mar 8, 2025
…zation (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 <[email protected]>
jaraco pushed a commit that referenced this pull request Mar 8, 2025
…zation (GH-130537) (#130987)

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 <[email protected]>
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…ation (python#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants