python / python/cpython

docs: Zipfile contains a 13-years outdated warning regarding path sanitization

未关闭 适合新手
#157,339 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

docs pending
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Documentation

The extract/extractall documentation contains a warning that became outdated 13 years ago:

https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.extractall

"Warning: Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of path, for example, members that have absolute filenames or filenames with “..” components. This module attempts to prevent that. See extract() note."

This incorrect and completely outdated comment should have been deleted when the malicious zip sanitization was added to Python 13 years ago, in February 2013:

https://github.com/python/cpython/commit/b47acbf46abd425f69dcc03e9b4f0c7f7c321ac2

Here's the official Python code:

https://github.com/python/cpython/blob/main/Lib/zipfile/__init__.py#L2467

Both extract() and extractall() use _extract_member, which performs complete sanitizing:

# 1. Strips leading slashes (/), drive letters (C:), and UNC paths (\\server\share)
drive, root, arcname = os.path.splitroot(arcname)
...
# 2. Defines invalid parts: empty strings, current directory (.), and parent directory (..)
invalid_path_parts = ('', os.path.curdir, os.path.pardir)

# 3. Filters out any occurrences of '.' and '..'
arcname = os.path.sep.join(x for x in arcname.split(os.path.sep)
                           if x not in invalid_path_parts)

And even the original Zip Slip author said that Python is not vulnerable:

https://security.snyk.io/research/zip-slip-vulnerability

"We also vetted the Ruby and Python ecosystems and couldn’t find any vulnerable code snippets or libraries. In fact, Python libraries were vulnerable until fixed in 2014. Ruby has a number of existing vulnerabilities that have been fixed in previous versions here , here and here."

(He's wrong about 2014; Python added the malicious Zip path sanitization in February 2013.)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中链接的 ZipFile.extractall 文档开始,并检查 Lib/zipfile/init.py 中相关的 _extract_member 实现。删除过时的路径清理警告,然后构建或验证文档,以确认对 extract() 和 extractall() 的引用仍然正确。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
documentation
Issue 类型
文档
难度
2/5
预计耗时
1-3 小时
活跃度
活跃
描述清晰度
描述清楚
新手友好度
78/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。