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

Abierto Apto para principiantes
#3,761 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, nodejs
Área
backend, security

Línea de trabajo

El error está en safeJoin en packages/hdx-eval/scripts/viewer/server.js (alrededor de la línea 39), que usa una comprobación startsWith simple sobre la raíz resuelta. Para reproducirlo, crea un directorio hermano runs-other y solicita /api/batches/..%2Fruns-other/runs/a/b/c/1 en la ruta de runs cerca de la línea 176. Está terminado cuando la comprobación compara con la raíz usando un límite de separador de ruta (o usa path.relative) y la solicitud al directorio hermano devuelve un error en lugar del archivo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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;
Lenguaje dominante
TypeScript
Estrellas
10.1k
Forks
527
Merge medio
1 d 20 h
PR fusionados (30 d)
186

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ClickHouse/ClickStack

Todos los issues de ClickHouse/ClickStack

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.