docs: Zipfile contains a 13-years outdated warning regarding path sanitization
まだ誰も着手していません。
- 主要言語
- 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.)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
IssueにリンクされているZipFile.extractallのドキュメントから始め、Lib/zipfile/init.pyにある関連する_extract_memberの実装を確認します。古いパスサニタイズの警告を削除し、その後ドキュメントをビルドまたは検証して、extract()とextractall()への参照が引き続き正しいことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 78/100