Path traversal via double percent-encoded slash bypasses directory containment check
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript
- Lĩnh vực
- security
Hướng nghiên cứu
Bắt đầu tại server.js:282-284 và kiểm tra isFileInDirectory(), sau đó tái hiện trường hợp thư mục anh em được báo cáo bằng thiết lập /tmp/poc được cung cấp và yêu cầu curl. Xác nhận rằng kiểm tra tính chứa từ chối /tmp/poc/_site-leak nhưng vẫn giữ các đường dẫn hợp lệ bên trong /tmp/poc/_site; lệnh gọi ở cấp unit của issue cung cấp thêm một điểm xác minh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
isFileInDirectory()'s containment check uses a naive string-prefix test with no trailing-separator boundary, so a sibling directory whose name happens to share a prefix with the served directory (e.g. _site-leak next to _site) is incorrectly treated as "inside" it. This is normally unreachable over HTTP because new URL()'s dot-segment removal neutralizes literal ..//%2e%2e/ sequences — but if the path separator itself is also percent-encoded (%2f), the whole segment survives new URL() untouched as one opaque path component, and a later decodeURIComponent() call materializes a real ../ traversal after the containment check's path has already been constructed.
CWE: CWE-22 (Path Traversal)
Severity: Medium
CVSS: 5.3 — CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N (AC:H because exploitation depends on a sibling directory/file existing whose name happens to share the served directory's name as a literal prefix)
Root Cause
server.js:282-284:
isFileInDirectory(dir, file) {
let absoluteDir = TemplatePath.absolutePath(dir);
let absoluteFile = TemplatePath.absolutePath(file);
return absoluteFile.startsWith(absoluteDir); // no trailing separator check
}
Reproduction
mkdir -p /tmp/poc/_site /tmp/poc/_site-leak
echo "SIBLING-DIR-SECRET" > /tmp/poc/_site-leak/leak.txt
# start server on /tmp/poc/_site as in issue #150
$ curl http://localhost:PORT/%2e%2e%2f_site-leak%2fleak.txt
SIBLING-DIR-SECRET
Unit-level confirmation of the underlying primitive:
isFileInDirectory("/tmp/poc/_site", "/tmp/poc/_site-leak/leak.txt") // → true (wrong)
A single-level escape to a path that does not share the served directory's name prefix (e.g. /%2e%2e%2fsecret.txt reaching straight outside with no naming coincidence) is correctly rejected — this bug's impact is bounded to prefix-sharing siblings, not arbitrary filesystem read.
Recommended Fix
isFileInDirectory(dir, file) {
let absoluteDir = TemplatePath.absolutePath(dir);
let absoluteFile = TemplatePath.absolutePath(file);
return absoluteFile === absoluteDir || absoluteFile.startsWith(absoluteDir + path.sep);
}
Verification
Dynamically confirmed on v3.0.0-alpha.11 against a real running server instance with real curl requests, as shown above.
- Ngôn ngữ chính
- JavaScript
- Star
- 108
- Fork
- 19
- Merge trung bình
- 6 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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.
Issue khác của 11ty/dev-server
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
11ty/dev-server#95 ·
-
needs-votes
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
11ty/dev-server#113 · 2 bình luận ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
11ty/dev-server#86 · 1 bình luận ·
-
enhancement needs-votes
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
11ty/dev-server#82 · 4 bình luận ·
-
enhancement needs-votes
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
11ty/dev-server#53 · 3 bình luận · 2 reaction ·
Tất cả issue của 11ty/dev-server
Issue tương tự
-
task
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
TAMULib/fw-registry#550 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
-
NWCWalletService.subscribe: response is never published if the handler finishes after unsubscribe (regression in 8.1.0)Có thể đã có người làm @ajaysehwal đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
bigskysoftware/htmx#4151 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100