Skip to content

Commit 8251578

Browse files
fix(server): Antigravity file writes cannot escape the workspace through a linked ancestor (pingdotgg#26184)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent b5af460 commit 8251578

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,19 @@ describe("AntigravityAdapterV2 client file system", () => {
260260
).pipe(Effect.exit);
261261
assert.isTrue(Exit.isFailure(linkedDirWrite), "a write under an escaping directory link");
262262
assert.isFalse(yield* fileSystem.exists(path.join(outside, "new.txt")));
263+
const nestedLinkedDirWrite = yield* writeTextFile(
264+
{
265+
sessionId: "mock-session-1",
266+
path: path.join(workspace, "linked-dir", "a", "b", "file.txt"),
267+
content: "planted",
268+
},
269+
context("fs/write_text_file"),
270+
).pipe(Effect.exit);
271+
assert.isTrue(
272+
Exit.isFailure(nestedLinkedDirWrite),
273+
"a write to missing directories under an escaping directory link",
274+
);
275+
assert.isFalse(yield* fileSystem.exists(path.join(outside, "a")));
263276
const insideLink = path.join(workspace, "inside-link.ts");
264277
yield* fileSystem.symlink(insidePath, insideLink);
265278
const viaInsideLink = yield* readTextFile(

‎apps/server/src/provider/acp/AntigravityClientFiles.ts‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Effect from "effect/Effect";
2+
import * as Option from "effect/Option";
23
import type * as FileSystem from "effect/FileSystem";
34
import type * as Path from "effect/Path";
45
import * as EffectAcpErrors from "effect-acp/errors";
@@ -25,23 +26,27 @@ const resolveClientFilePath = Effect.fn("AntigravityClientFiles.resolveClientFil
2526
const outside = EffectAcpErrors.AcpRequestError.invalidParams(
2627
`Path '${input.requestPath}' is outside the session workspace.`,
2728
);
28-
const real = yield* input.fileSystem.realPath(resolved).pipe(
29-
Effect.catch(() =>
30-
Effect.gen(function* () {
31-
// Fall back to the parent only for missing files, never dangling or unreadable links.
32-
const entryExists = yield* input.fileSystem.readLink(resolved).pipe(
33-
Effect.as(true),
34-
Effect.catch(() => input.fileSystem.exists(resolved)),
35-
Effect.orElseSucceed(() => true),
36-
);
37-
if (entryExists) return yield* outside;
38-
const parent = yield* input.fileSystem
39-
.realPath(path.dirname(resolved))
40-
.pipe(Effect.orElseSucceed(() => path.dirname(resolved)));
41-
return path.join(parent, path.basename(resolved));
42-
}),
43-
),
44-
);
29+
// Canonicalize the deepest existing ancestor, so a link above missing directories cannot escape.
30+
let candidate = resolved;
31+
const missingSuffix: Array<string> = [];
32+
let real: string;
33+
while (true) {
34+
const canonical = yield* input.fileSystem.realPath(candidate).pipe(Effect.option);
35+
if (Option.isSome(canonical)) {
36+
real = path.join(canonical.value, ...missingSuffix);
37+
break;
38+
}
39+
// Walk up only past missing entries, never dangling or unreadable links.
40+
const entryExists = yield* input.fileSystem.readLink(candidate).pipe(
41+
Effect.as(true),
42+
Effect.catch(() => input.fileSystem.exists(candidate)),
43+
Effect.orElseSucceed(() => true),
44+
);
45+
const parent = path.dirname(candidate);
46+
if (entryExists || parent === candidate) return yield* outside;
47+
missingSuffix.unshift(path.basename(candidate));
48+
candidate = parent;
49+
}
4550
const roots = yield* Effect.forEach(input.allowedRoots, (root) =>
4651
input.fileSystem.realPath(root).pipe(Effect.orElseSucceed(() => root)),
4752
);

0 commit comments

Comments
 (0)