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

Aberta Para iniciantes
#3,761 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
javascript, nodejs
Domínio
backend, security

Direção de pesquisa

O bug está em safeJoin, em packages/hdx-eval/scripts/viewer/server.js (por volta da linha 39), que usa uma verificação startsWith simples sobre a raiz resolvida. Para reproduzir, crie um diretório irmão runs-other e faça a requisição /api/batches/..%2Fruns-other/runs/a/b/c/1 na rota de runs, perto da linha 176. Está concluído quando a verificação compara com a raiz usando um limite de separador de caminho (ou usa path.relative) e a requisição ao diretório irmão retorna um erro em vez do arquivo.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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;
Linguagem predominante
TypeScript
Estrelas
10.1k
Forks
527
Merge médio
1d 20h
PRs com merge (30d)
186

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de ClickHouse/ClickStack

Todas as issues de ClickHouse/ClickStack

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.