Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ describe("AntigravityAdapterV2 client file system", () => {
).pipe(Effect.exit);
assert.isTrue(Exit.isFailure(linkedDirWrite), "a write under an escaping directory link");
assert.isFalse(yield* fileSystem.exists(path.join(outside, "new.txt")));
const nestedLinkedDirWrite = yield* writeTextFile(
{
sessionId: "mock-session-1",
path: path.join(workspace, "linked-dir", "a", "b", "file.txt"),
content: "planted",
},
context("fs/write_text_file"),
).pipe(Effect.exit);
assert.isTrue(
Exit.isFailure(nestedLinkedDirWrite),
"a write to missing directories under an escaping directory link",
);
assert.isFalse(yield* fileSystem.exists(path.join(outside, "a")));
const insideLink = path.join(workspace, "inside-link.ts");
yield* fileSystem.symlink(insidePath, insideLink);
const viaInsideLink = yield* readTextFile(
Expand Down
39 changes: 22 additions & 17 deletions apps/server/src/provider/acp/AntigravityClientFiles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
import type * as FileSystem from "effect/FileSystem";
import type * as Path from "effect/Path";
import * as EffectAcpErrors from "effect-acp/errors";
Expand All @@ -25,23 +26,27 @@ const resolveClientFilePath = Effect.fn("AntigravityClientFiles.resolveClientFil
const outside = EffectAcpErrors.AcpRequestError.invalidParams(
`Path '${input.requestPath}' is outside the session workspace.`,
);
const real = yield* input.fileSystem.realPath(resolved).pipe(
Effect.catch(() =>
Effect.gen(function* () {
// Fall back to the parent only for missing files, never dangling or unreadable links.
const entryExists = yield* input.fileSystem.readLink(resolved).pipe(
Effect.as(true),
Effect.catch(() => input.fileSystem.exists(resolved)),
Effect.orElseSucceed(() => true),
);
if (entryExists) return yield* outside;
const parent = yield* input.fileSystem
.realPath(path.dirname(resolved))
.pipe(Effect.orElseSucceed(() => path.dirname(resolved)));
return path.join(parent, path.basename(resolved));
}),
),
);
// Canonicalize the deepest existing ancestor, so a link above missing directories cannot escape.
let candidate = resolved;
const missingSuffix: Array<string> = [];
let real: string;
while (true) {
const canonical = yield* input.fileSystem.realPath(candidate).pipe(Effect.option);
if (Option.isSome(canonical)) {
real = path.join(canonical.value, ...missingSuffix);
break;
}
// Walk up only past missing entries, never dangling or unreadable links.
const entryExists = yield* input.fileSystem.readLink(candidate).pipe(
Effect.as(true),
Effect.catch(() => input.fileSystem.exists(candidate)),
Effect.orElseSucceed(() => true),
);
const parent = path.dirname(candidate);
if (entryExists || parent === candidate) return yield* outside;
missingSuffix.unshift(path.basename(candidate));
candidate = parent;
}
const roots = yield* Effect.forEach(input.allowedRoots, (root) =>
input.fileSystem.realPath(root).pipe(Effect.orElseSucceed(() => root)),
);
Expand Down
Loading