Skip to content

Commit 8274bee

Browse files
committed
test(file-transfer): cover final symlink write policy
1 parent ec023a4 commit 8274bee

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎extensions/file-transfer/src/node-host/file-write.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe("handleFileWrite — parent directory handling", () => {
164164
});
165165

166166
describe("handleFileWrite — symlink protection", () => {
167-
it("refuses to write through an existing symlink (lstat)", async () => {
167+
it("rejects a final symlink by default with the canonical target", async () => {
168168
const real = path.join(tmpRoot, "real.txt");
169169
const link = path.join(tmpRoot, "link.txt");
170170
await fs.writeFile(real, "untouched");
@@ -175,8 +175,24 @@ describe("handleFileWrite — symlink protection", () => {
175175
contentBase64: b64("evil"),
176176
overwrite: true,
177177
});
178+
expectFailure(r, "SYMLINK_REDIRECT");
179+
expect(r.ok ? null : r.canonicalPath).toBe(real);
180+
expect(await fs.readFile(real, "utf-8")).toBe("untouched");
181+
});
182+
183+
it("refuses to write through a final symlink when followSymlinks=true", async () => {
184+
const real = path.join(tmpRoot, "real.txt");
185+
const link = path.join(tmpRoot, "link.txt");
186+
await fs.writeFile(real, "untouched");
187+
await fs.symlink(real, link);
188+
189+
const r = await handleFileWrite({
190+
path: link,
191+
contentBase64: b64("evil"),
192+
overwrite: true,
193+
followSymlinks: true,
194+
});
178195
expectFailure(r, "SYMLINK_TARGET_DENIED");
179-
// The original file must be unchanged.
180196
expect(await fs.readFile(real, "utf-8")).toBe("untouched");
181197
});
182198

0 commit comments

Comments
 (0)