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

未关闭 适合新手
#3,761 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, nodejs
领域
backend, security

调研方向

错误位于 packages/hdx-eval/scripts/viewer/server.js 中的 safeJoin(约第 39 行),它对解析后的根路径只做了简单的 startsWith 检查。复现方法:创建同级目录 runs-other,然后在第 176 行附近的 run 路由上请求 /api/batches/..%2Fruns-other/runs/a/b/c/1。完成标准是:检查时以路径分隔符为边界与根目录比较(或使用 path.relative),并且对同级目录的请求返回错误,而不是返回文件。

由索引模型根据 Issue 内容生成。

描述

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;
主要语言
TypeScript
星标
10.1k
派生
527
平均合并
1 天 20 小时
30 天内合并 PR
186

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ClickHouse/ClickStack 的其他 Issue

查看 ClickHouse/ClickStack 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。