Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Path traversal via double percent-encoded slash bypasses directory containment check

Đã đóng Phù hợp với người mới
#152 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của 11ty/dev-server

Tất cả issue của 11ty/dev-server

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.