Open redirect via `//<host>/..%2f<dir>` in directory trailing-slash redirect

Đang mở Phù hợp với người mới
#982 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
78/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, node.js
Lĩnh vực
backend, cli, security

Hướng nghiên cứu

Bắt đầu tại lib/core/index.js, ở decodePathname(parsed.pathname) và phần chuyển hướng thư mục có dấu gạch chéo cuối đường dẫn tạo tiêu đề Location. Thêm một kiểm thử hồi quy dùng dạng yêu cầu được cung cấp và xác minh rằng chuyển hướng vẫn ở cùng origin của máy chủ và chỉ có một dấu gạch chéo ở đầu. Issue không nêu tệp kiểm thử, vì vậy trước tiên hãy tìm các kiểm thử chuyển hướng hiện có và chạy bộ kiểm thử liên quan.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

In http-server 14.1.1 and master (0d3b7bb, Node.js v26.13.0), requesting a path starting with //<host>/..%2f<subdir> when the served root contains <subdir> returns a 302 redirect with a scheme-relative Location header (//<host>/..%2f<subdir>/) that browsers resolve to http://<host>/..%2f<subdir>/ (CWE-601; incomplete fix for ecstatic advisory GHSA-9q64-mpxx-87fg).

const httpServer = require('http-server');
const fs = require('fs');

fs.mkdirSync('./test-root/dir', { recursive: true });
const server = httpServer.createServer({ root: './test-root' });

server.listen(0, '127.0.0.1', async () => {
  const { port } = server.server.address();
  const url = `http://127.0.0.1:${port}//evil.example/..%2fdir`;
  const res = await fetch(url, { redirect: 'manual' });
  const loc = res.headers.get('location');
  console.log('Status:', res.status);
  console.log('Location:', loc);
  console.log('Resolved URL:', new URL(loc, url).href);
  server.close();
});

Expected: Location is a single-slash origin-relative path (e.g. Location: /dir/) that stays on http://127.0.0.1:<port>/.

Actual:

Status: 302
Location: //evil.example/..%2fdir/
Resolved URL: http://evil.example/..%2fdir/

Reference: RFC 9110 §10.2.2 (Location header field) and WHATWG URL Standard §4.4 (a relative-URL string beginning with // is parsed as a scheme-relative-special-url whose host is the authority following //); see also GHSA-9q64-mpxx-87fg and commit jfhbrook/node-ecstatic@be6fc25.

In lib/core/index.js, decodePathname(parsed.pathname) decodes %2f and normalizes //evil.example/../dir to pathname = '/dir' (matching the local directory without a trailing slash), but the 302 response constructs Location from the unnormalized parsed.pathname (ensureUriEncoded(${parsed.pathname}/${q})) instead of pathname or a path with leading slashes collapsed ('/' + parsed.pathname.replace(/^[\/\\]+/, '')).

Credit: https://ucsbplse.github.io/

Ngôn ngữ chính
JavaScript
Star
14.2k
Fork
1.6k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

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 http-party/http-server

Tất cả issue của http-party/http-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.