#1 Persistent memory for AI coding agents based on real-world benchmarks
TypeScript agentmemoryagentsaiclaudeclaudecodecodexcopilotcursorgenaiharnesshermesmemoryompopenclawopencodepi
fix: reject symlinks in mem::compress-file to prevent arbitrary file writes (#151)
Rohit Ghumarecad377d6fa47
diff --git a/src/functions/compress-file.ts b/src/functions/compress-file.tsindex f339c496..53e3e9e9 100644--- a/src/functions/compress-file.ts+++ b/src/functions/compress-file.ts@@ -1,4 +1,4 @@-import { readFile, writeFile } from "node:fs/promises";+import { lstat, readFile, writeFile } from "node:fs/promises";import { basename, dirname, extname, join, resolve } from "node:path";import type { ISdk } from "iii-sdk";import type { MemoryProvider } from "../types.js";@@ -112,6 +112,15 @@ export function registerCompressFileFunction(return { success: false, error: "refusing to process sensitive-looking path" };}+ try {+ const stat = await lstat(absolutePath);+ if (stat.isSymbolicLink()) {+ return { success: false, error: "symlinks are not supported" };+ }+ } catch {+ return { success: false, error: "file not found" };+ }+let original: string;try {original = await readFile(absolutePath, "utf-8");diff --git a/test/compress-file.test.ts b/test/compress-file.test.tsindex a3afc134..f3a5142a 100644--- a/test/compress-file.test.ts+++ b/test/compress-file.test.ts@@ -5,8 +5,12 @@ vi.mock("../src/logger.js", () => ({}));const fileStore = new Map<string, string>();+const symlinkPaths = new Set<string>();vi.mock("node:fs/promises", () => ({+ lstat: vi.fn(async (path: string) => ({+ isSymbolicLink: () => symlinkPaths.has(path),+ })),readFile: vi.fn(async (path: string) => {const value = fileStore.get(path);if (value === undefined) throw new Error("ENOENT");@@ -68,6 +72,7 @@ describe("mem::compress-file", () => {beforeEach(() => {fileStore.clear();+ symlinkPaths.clear();sdk = mockSdk();kv = mockKV();summarize = vi.fn();@@ -78,6 +83,15 @@ describe("mem::compress-file", () => {);});+ it("rejects symlinks", async () => {+ symlinkPaths.add("/tmp/notes.md");+ const result = (await sdk.trigger("mem::compress-file", {+ filePath: "/tmp/notes.md",+ })) as { success: boolean; error: string };+ expect(result.success).toBe(false);+ expect(result.error).toContain("symlink");+ });+it("rejects non-markdown paths", async () => {const result = (await sdk.trigger("mem::compress-file", {filePath: "/tmp/readme.txt",