fix(core): authorize symlinks by lexical path (#38180)

Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot] 2026-07-21 15:13:18 -05:00 committed by GitHub
commit e6607fb58d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 78 additions and 15 deletions

View file

@ -220,6 +220,39 @@ describe("WriteTool", () => {
),
)
it.live("writes an external symlink target with only its in-location permission", () =>
Effect.acquireUseRelease(
Effect.promise(() => Promise.all([tmpdir(), tmpdir()])),
([active, outside]) => {
reset()
if (process.platform === "win32") return Effect.void
const target = path.join(outside.path, "external.txt")
const link = path.join(active.path, "link.txt")
return Effect.promise(async () => {
await fs.writeFile(target, "before")
await fs.symlink(target, link)
}).pipe(
Effect.andThen(
withTool(active.path, (registry) => executeTool(registry, call({ path: "link.txt", content: "after" }))),
),
Effect.andThen((result) =>
Effect.sync(() => {
expect(result.type).toBe("text")
expect(assertions.map((input) => input.action)).toEqual(["edit"])
expect(assertions[0]?.resources).toEqual(["link.txt"])
}),
),
Effect.andThen(Effect.promise(() => fs.readFile(target, "utf8"))),
Effect.tap((content) => Effect.sync(() => expect(content).toBe("after"))),
)
},
([active, outside]) =>
Effect.promise(() =>
Promise.all([active[Symbol.asyncDispose](), outside[Symbol.asyncDispose]()]).then(() => undefined),
),
),
)
it.live("approves an explicit external absolute path before edit", () =>
Effect.acquireUseRelease(
Effect.promise(() => Promise.all([tmpdir(), tmpdir()])),