os.path.normpath of relative path r".\C:\x" returns absolute path r"C:\x" on Windows, similar in pathlib
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với hành vi của os.path.normpath được thể hiện trong bản tái hiện trên Windows, sau đó kiểm tra các ví dụ pathlib.PureWindowsPath liên quan. So sánh cách các đường dẫn tương đối chứa các phần tử giống ký tự ổ đĩa được phân loại và chuẩn hóa, đồng thời sử dụng các đoạn mã để xác minh rằng các đường dẫn tương đối vẫn là tương đối, trong khi các đường dẫn tuyệt đối vẫn giữ nguyên hành vi hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- operating-systems, security
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100