The eval viewer's safeJoin allows a sibling directory sharing the runs prefix

Đang mở Phù hợp với người mới
#3,761 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

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
72/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, nodejs
Lĩnh vực
backend, security

Hướng nghiên cứu

Lỗi nằm trong safeJoin ở packages/hdx-eval/scripts/viewer/server.js (khoảng dòng 39), dùng kiểm tra startsWith đơn giản trên thư mục gốc đã được phân giải. Để tái hiện, hãy tạo thư mục anh em runs-other rồi gửi yêu cầu /api/batches/..%2Fruns-other/runs/a/b/c/1 tới route runs gần dòng 176. Việc được coi là xong khi kiểm tra so sánh với thư mục gốc có ranh giới ký tự phân tách đường dẫn (hoặc dùng path.relative) và yêu cầu tới thư mục anh em trả về lỗi thay vì tệp.

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

Mô tả

external

The eval viewer's safeJoin allows a sibling directory sharing the runs prefix

Summary

The eval viewer's safeJoin checks only startsWith(path.resolve(root)). A sibling directory whose name begins with the runs root name passes the check. A crafted request can therefore read a JSON run artifact from outside the configured runs directory.

Location

  • Repository: hyperdxio/hyperdx
  • File: packages/hdx-eval/scripts/viewer/server.js
  • Line: 39 (safeJoin; the run route is at 176)
  • Revision: 1773c11942a7

Affected code

function safeJoin(root, ...parts) {
  const p = path.resolve(root, ...parts);
  if (!p.startsWith(path.resolve(root))) throw new Error('path escapes root');
  return p;
}

The prefix check has no path-separator boundary.

Expected behavior

A request may only read files under the configured runs directory. A path resolving to a sibling such as runs-other/... must be rejected.

Actual behavior

Create a sibling runs-other/a/b/c/1.json next to runs, then run the viewer and request:

/api/batches/..%2Fruns-other/runs/a/b/c/1

The server returns the sibling file:

200 {"trajectory":{"secret":"outside"},"grade":null}

The file is outside packages/hdx-eval/runs.

Root cause

path.resolve(root, '../runs-other/...') produces a path that still starts with the root string (.../runs-other starts with .../runs). startsWith therefore accepts it.

Suggested fix

Append a path separator to the root before comparing, or use path.relative and reject results starting with .. or absolute paths:

const base = path.resolve(root);
const p = path.resolve(base, ...parts);
const rel = path.relative(base, p);
if (rel.startsWith('..') || path.isAbsolute(rel)) throw new Error('path escapes root');
return p;
Ngôn ngữ chính
TypeScript
Star
10.1k
Fork
527
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
186

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 ClickHouse/ClickStack

Tất cả issue của ClickHouse/ClickStack

Issue tương tự

Thêm issue về TypeScript

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.