GHSA-5MM5-4MH4-6GM6
InputSanitizer.sanitizePath sibling-directory escape via non-separator-anchored prefix check
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-5MM5-4MH4-6GM6 divulgada | |
| Remediación | Parche 5.15.5 | network-ai · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
`InputSanitizer.sanitizePath()`, a published path validation helper exported from the `network-ai` package as `network-ai/security`, fails to confine a resolved path to its intended base directory. The containment check at `security.ts:387` uses a bare string `startsWith(resolvedBase)` without a trailing path separator, so any path in a sibling directory whose name begins with the base directory's name (for example `/data/project-evil/secret.txt` against base `/data/project`) is accepted as in-scope. A caller that invokes this helper to validate attacker-influenced paths can be tricked into treating out-of-scope paths as safe, enabling file access outside the directory the helper is supposed to enforce.
Root Cause
The security invariant is that a path returned by `sanitizePath()` must resolve to a location inside `basePath`. The method normalizes the input, resolves it to an absolute path, and then tests containment only with `resolvedPath.startsWith(resolvedBase)`. Plain string prefix matching is not path-boundary aware: the base string `/data/project` is a prefix of the unrelated sibling `/data/project-evil`, so the check passes for a path that is not under the base directory. The method never appends a path separator to the base before comparing, and it never re-checks the final resolved path against a separator-anchored boundary. The companion `SandboxPolicy` checks in `lib/agent-runtime.ts` use the correct separator-anchored form (`startsWith(base + sep)`), but that pattern was never applied to this helper; `security.ts` does not even import `sep`.
security.ts:374 static sanitizePath(inputPath, basePath)
security.ts:387 if (!resolvedPath.startsWith(resolvedBase)) { throw ... } // missing separator anchor
security.ts:20 import { join, normalize, isAbsolute } from 'path' // 'sep' not importedImpact
An actor who can supply the `inputPath` argument to a caller of `InputSanitizer.sanitizePath()` can cause the helper to return an out-of-scope path as if it were validated. The attacker controls `inputPath`; `basePath` is set by the consuming application. Exploitation requires the attacker to supply (or guess) a sibling directory name that shares a string prefix with the base directory, a common condition for conventional layouts such as `/data/project` next to `/data/project-evil` or `/data/project2`. Because the helper is the terminal path-validation step, any filesystem operation the caller performs on the returned path (read or directory listing in the demonstrated case) then operates outside the intended base directory, disclosing files the sandbox was meant to withhold. The primitive demonstrated directly is read/list disclosure across the sibling-prefix boundary. Because the helper is a general path validator whose return value carries no record of the intended operation, a caller that validates a write destination with it receives the same out-of-scope path and writes outside the base directory, letting attacker-controlled content be created or overwritten there; the package's own companion sandbox check is applied to read, write, and directory-listing calls alike, so write validation is an expected use of a helper of this kind rather than a hypothetical one.
Proof of Concept
No dependencies beyond Node.js. The script reproduces the exact resolution and
containment logic of security.ts:374-392 and compares it against the fixed,
separator-anchored pattern used in lib/agent-runtime.ts.const { normalize, isAbsolute, join, sep } = require('path');
function vulnerable(inputPath, basePath) {
const normalized = normalize(inputPath);
const absolute = isAbsolute(normalized) ? normalized : join(basePath, normalized);
const resolvedBase = normalize(basePath);
const resolvedPath = normalize(absolute);
if (!resolvedPath.startsWith(resolvedBase)) throw new Error('PATH_TRAVERSAL');
return resolvedPath;
}
const base = '/data/project';
for (const input of ['/data/project-evil/secret.txt', '../project-evil/secret.txt',
'/data/project2/key.pem', '../project2/key.pem']) {
try { console.log('ACCEPTED', input, '=>', vulnerable(input, base)); }
catch (e) { console.log('BLOCKED ', input); }
}ACCEPTED /data/project-evil/secret.txt => /data/project-evil/secret.txt
ACCEPTED ../project-evil/secret.txt => /data/project-evil/secret.txt
ACCEPTED /data/project2/key.pem => /data/project2/key.pem
ACCEPTED ../project2/key.pem => /data/project2/key.pemAll four sibling-prefix paths are returned as validated, each resolving outside the base directory `/data/project`. A classic `../../../etc/passwd` input is still rejected, and legitimate children under the base are accepted, confirming the flaw is specifically the missing separator anchor rather than broken traversal handling generally.
Attack Chain
- Exposure: The consuming application imports `InputSanitizer` from the published `network-ai/security` subpath export and calls `InputSanitizer.sanitizePath(inputPath, basePath)` to validate a path before a filesystem operation, with `basePath` set to its intended sandbox root.
- Control: The attacker controls `inputPath`. They provide a sibling path whose leading component shares a string prefix with `basePath`, for example `/data/project-evil/secret.txt` (absolute) or `../project-evil/secret.txt` (relative), when the base is `/data/project`.
- Path: `normalize()` leaves the sibling path unchanged (no dot segments or redundant separators), and `join()` resolves the relative form to the same absolute sibling path. Control reaches the single containment check unchanged.
- Guard: The only guard, `resolvedPath.startsWith(resolvedBase)` at `security.ts:387`, lacks a trailing separator. `'/data/project-evil/secret.txt'.startsWith('/data/project')` is `true`, so the guard passes for an out-of-scope path.
- Primitive: The helper returns the out-of-scope path to the caller as a validated, in-scope path.
- Result: The caller performs its filesystem operation (file read or directory listing in the demonstrated case) on a location outside the intended base directory, disclosing files the base-directory restriction was meant to protect.
Bypass Evidence
The relevant protection is the containment check at `security.ts:387`. The strongest challenge is whether `normalize()` or the `isAbsolute()`/`join()` handling removes the escape before the check; it does not, because a sibling path such as `/data/project-evil/secret.txt` contains no dot segments or redundant separators to normalize away, and the relative form joins to the identical absolute sibling path. The check then reduces to `'/data/project-evil/secret.txt'.startsWith('/data/project')`, which is `true`. The separator-anchored form used elsewhere in the package (`lib/agent-runtime.ts:456`, `resolved === base || resolved.startsWith(base + sep)`) rejects the same input, demonstrating that the missing anchor is the specific defect. This helper is a distinct code path from the previously reported `SandboxPolicy` checks in `lib/agent-runtime.ts`: the earlier fix added separator anchoring only in that file, and `security.ts` has never been modified across the available repository history and still omits the `sep` import, so this validation path remains unguarded against the sibling-prefix input.
Affected Versions
- Ecosystem: `npm`
- Package: `network-ai`
- Confirmed affected range: `<= 5.15.4`
- Latest release checked: `5.15.4` (npm registry
https://www.npmjs.com/package/network-ai/v/5.15.4) - Fix status: not fixed
The vulnerable `startsWith(resolvedBase)` containment check in `security.ts` is present in the latest published release, 5.15.4, and `security.ts` has not been modified across the available repository history. The earlier sibling-prefix fix was applied only to `lib/agent-runtime.ts` and did not change this helper, so no release addresses this code path. The introduction boundary cannot be established from the available checkout, which is why the range is left open at the lower end rather than anchored to a specific introducing version.
Suggested Fix
Enforce a separator-anchored containment boundary in `sanitizePath()`: after resolving both the input and the base to absolute, normalized paths, accept the result only when it equals the base or begins with the base followed by the platform path separator (`resolvedPath === resolvedBase || resolvedPath.startsWith(resolvedBase + sep)`), mirroring the pattern already used in `lib/agent-runtime.ts`. This requires importing `sep` from `path` in `security.ts`. Ensure the comparison is applied after full resolution so both relative inputs (joined to the base) and absolute inputs are checked against the anchored boundary, and add test coverage for the sibling-prefix vectors (both absolute and relative) alongside the existing classic traversal test.
---
Reported by zx.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmnetwork-ai |
Corregida | 5.15.5 | 0 d | 6.0.1 no afectada |
5.15.5Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/Jovancoding/Network-AI/security/advisories/GHSA-5mm5-4mh4-6gm6Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
