os.path.normpath of relative path r".\C:\x" returns absolute path r"C:\x" on Windows, similar in pathlib
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
os.path.normpath normalizes "./" or "../" path elements to clean the path.
As os.path.normpath doesn't consider a case where the normalized path starts with a drive letter, a relative path with a drive letter-like path element will be normalized to an absolute path. This behavior can result in a path traversal, depending on the implementation.
The minimal snippet to reproduce this behavior is the following:
> os.path.normpath("./C:/Windows/System32")
This snippet will return "C:\Windows\System32", which is an absolute path on Windows. (tested with Python 3.11.1 on Windows)
This vulnerability is similar to CVE-2022-29804 of Go.
as reported to security@ by RyotaK on 2022-12-09.
Golang solved their issue in https://github.com/golang/go/issues/52476 which may be helpful to look at.
The Python Security Response Team agreed that this issue did not require an embargo.
It looks like pathlib probably also has issues in this area:
>>> p1 = pathlib.PureWindowsPath('P:\\windows')
>>> p2 = pathlib.PureWindowsPath('.\\P:\\windows')
>>> p1 == p2
False
>>> p1
PureWindowsPath('P:/windows')
>>> p2
PureWindowsPath('P:/windows')
>>> p1.is_absolute()
True
>>> p2.is_absolute()
False
>>> str(p1) == str(p2)
True
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先從 Windows 重現中展示的 os.path.normpath 行為開始,然後檢查相關的 pathlib.PureWindowsPath 範例。比較包含類似磁碟機代號元素的相對路徑是如何分類和正規化的,並使用程式碼片段驗證相對路徑仍維持為相對路徑,而絕對路徑保留其現有行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- operating-systems, security
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100