Skip to content

Commit f1d8b59

Browse files
cliffhallclaude
andcommitted
fix(filesystem): bound the case-respelling fs calls from #470
namesOneEntry's readdir and lstat calls go through withFsTimeout; a timeout answers no, so the respelling is refused rather than hanging. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent f3e5d36 commit f1d8b59

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

‎src/filesystem/__tests__/bounded-walk.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,24 @@ describe("path validation", () => {
227227
);
228228
});
229229
});
230+
231+
describe("allowed-directory case respelling (#470)", () => {
232+
it("refuses the respelling when the parent's readdir never settles", async () => {
233+
const root = path.join(dir, "CaseTest");
234+
await fs.mkdir(root);
235+
await fs.writeFile(path.join(root, "f.txt"), "inside");
236+
const scoped = await connect([root]);
237+
try {
238+
client = scoped.client;
239+
const called = stall("readdir", dir);
240+
const result = await callPastTimeout(called, "read_text_file", {
241+
path: path.join(dir, "CASETEST", "f.txt"),
242+
});
243+
expect(result.isError).toBe(true);
244+
expect(textOf(result)).toMatch(/^Access denied - path outside/);
245+
} finally {
246+
vi.useRealTimers();
247+
await scoped.close();
248+
}
249+
});
250+
});

‎src/filesystem/lib.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,25 @@ async function namesOneEntry(
262262
): Promise<boolean> {
263263
try {
264264
const key = caseMatchKey(requested);
265-
const entries = (await fs.readdir(parent)) ?? [];
265+
const entries =
266+
(await withFsTimeout(fs.readdir(parent), "readdir", parent)) ?? [];
266267
if (entries.filter((entry) => caseMatchKey(entry) === key).length !== 1) {
267268
return false;
268269
}
269-
const requestedStats = await fs.lstat(path.join(parent, requested), {
270-
bigint: true,
271-
});
272-
const configuredStats = await fs.lstat(path.join(parent, configured), {
273-
bigint: true,
274-
});
270+
// Bounded like every request-path fs call (#4162); a timeout lands in the
271+
// catch below and answers no, so the request is refused.
272+
const requestedPath = path.join(parent, requested);
273+
const configuredPath = path.join(parent, configured);
274+
const requestedStats = await withFsTimeout(
275+
fs.lstat(requestedPath, { bigint: true }),
276+
"lstat",
277+
requestedPath,
278+
);
279+
const configuredStats = await withFsTimeout(
280+
fs.lstat(configuredPath, { bigint: true }),
281+
"lstat",
282+
configuredPath,
283+
);
275284
return (
276285
requestedStats.dev === configuredStats.dev &&
277286
requestedStats.ino === configuredStats.ino

0 commit comments

Comments
 (0)