Skip to content

Commit a2694ce

Browse files
committed
feat: Enforce path traversal boundaries for autonomous filesystem reads (#9743)
1 parent ce8ba69 commit a2694ce

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

ai/mcp/server/memory-core/services/DreamService.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,16 @@ NEVER output raw markdown or conversational text. YOU MUST output EXACTLY ONE JS
410410

411411
if (payload.action === 'read_file' && payload.path) {
412412
try {
413-
const raw = fs.readFileSync(path.join(neoRootDir, payload.path), 'utf8');
413+
const targetPath = path.resolve(neoRootDir, payload.path);
414+
const relativePath = path.relative(neoRootDir, targetPath);
415+
416+
if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) {
417+
messages.push({ role: 'assistant', content: result.content });
418+
messages.push({ role: 'user', content: `Security Error: Target path ${payload.path} attempts to traverse outside the repository root. This is forbidden.` });
419+
continue;
420+
}
421+
422+
const raw = fs.readFileSync(targetPath, 'utf8');
414423
messages.push({ role: 'assistant', content: result.content });
415424
messages.push({ role: 'user', content: `File contents of ${payload.path}:\n\n${raw}` });
416425
} catch(e) {

0 commit comments

Comments
 (0)