Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 20 to 21

Compare

+51 −3 in 4 places
Lines 9–16 at 21 (were 9–15 at 20)
99// The protocol is JSON-RPC 2.0, one message per line, with no library: the
1010// client uses nothing outside Node.
1111
12−import { resolve } from "node:path";
12+import { realpathSync } from "node:fs";
13+import { isAbsolute, relative, resolve, sep } from "node:path";
1314import { clientVersion } from "./client-version.ts";
1415import { commandTable, main } from "./main.ts";
1516
Lines 93–100 at 21 (were 92–98 at 20)
9293 },
9394 folder: {
9495 type: "string",
95− description: "The abso folder to run in (default: the folder this server started in).",
96+ description:
97+ "The abso folder to run in: the folder this server started in (the default), or one inside it.",
9698 },
9799 json: { type: "boolean", description: "Answer with the command's JSON (as --json) instead of its text." },
98100 ...flags,
Lines 105–154 at 21 (were 103–108 at 20)
103105 });
104106}
105107
108+/** A path as it really is (through links), or as given when it doesn't exist. */
109+function real(path: string): string {
110+ try {
111+ return realpathSync.native(path);
112+ } catch {
113+ return path;
114+ }
115+}
117+/** Whether `path` is `start` or inside it, after links are followed. */
118+function inside(start: string, path: string): boolean {
119+ const rel = relative(real(start), real(path));
120+ return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
121+}
123+/**
124+ * Where a tool call runs, and what it may read (Security on 233): its folder and
125+ * every --attach file stay inside the folder the server started in. A relative
126+ * path that climbs out (..), an absolute one elsewhere, or a link out is
127+ * refused, so no tool reads a file outside the project. Answers the folder, or
128+ * why the call is refused.
129+ */
130+export function confineCall(
131+ start: string,
132+ input: Readonly<Record<string, unknown>>,
133+): { folder: string } | { refused: string } {
134+ const named = typeof input.folder === "string" && input.folder !== "" ? input.folder : undefined;
135+ const folder = named === undefined ? start : resolve(start, named);
136+ if (!inside(start, folder))
137+ return {
138+ refused: `folder ${JSON.stringify(named)} is outside ${start}, the folder this server started in; tools run there or below`,
139+ };
140+ if (typeof input.attach === "string")
141+ for (const p of input.attach
142+ .split(",")
143+ .map((x) => x.trim())
144+ .filter((x) => x !== ""))
145+ if (!inside(start, resolve(folder, p)))
146+ return {
147+ refused: `--attach ${p} is outside ${start}, the folder this server started in; a tool attaches files from there or below`,
148+ };
149+ return { folder };
150+}
106152/** The command line a tool call stands for: flags as --name=value, then the words after --. */
107153export function argvFor(command: string, input: Readonly<Record<string, unknown>>): string[] {
108154 const def = commandTable()[command]!;
Lines 204–212 at 21 (were 158–164 at 20)
158204 const command = MCP_COMMANDS.find((c) => toolName(c) === name);
159205 if (command === undefined) return fail(id, -32602, `no tool ${JSON.stringify(name)}; tools/list names them`);
160206 const args = (params.arguments ?? {}) as Record<string, unknown>;
161− const folder = typeof args.folder === "string" && args.folder !== "" ? resolve(cwd, args.folder) : cwd;
207+ const where = confineCall(cwd, args);
208+ if ("refused" in where) return reply(id, { content: [{ type: "text", text: where.refused }], isError: true });
209+ const folder = where.folder;
162210 let streamed = "";
163211 const result = await main(argvFor(command, args), {
164212 cwd: folder,
MCP
compare on this site's /mcp
CLI
abso diff 20 21 client/src/mcp.ts --json
JSON
/christopher/abso-core/compare/20..21?file=client%2Fsrc%2Fmcp.ts&format=json