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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/test/paths.test.ts?version=310&format=json
161 linesFirst import 99% · infra-split 1%Last change infra-split in version 37, 2 versions changed it

You're reading version 310. The newest is 318, and no version since then changed this file. Go to the newestCompare with 318

1// Canonical paths (#30): every write refuses a path that isn't the one
2// spelling of a file, so "./harness/x" can't slip past a filter on
3// "harness/" and "../x" can't escape a box's folder. Old logs still load, and
4// a file with such a path from before can still be removed.
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { buildBase } from "../../../src/engine/index.ts";
9import { MemoryStore, Project, ProjectError, pathProblem } from "../project.ts";
11const BAD = [
12 "./harness/test262/held-out/zzz.json",
13 "harness/./held-out/x.json",
14 "harness/../x",
15 "../x",
16 "a//b",
17 "a/",
18 "/etc/passwd",
19 "C:/x",
20 "c:x",
21 "a\\b",
22 "a\u0000b",
23 "a\tb",
24 ".git/config",
25 "sub/.GIT/hooks/x",
26];
27const GOOD = [
28 "harness/test262/held-out/zzz.json",
29 "a.ts",
30 ".gitignore",
31 "a/.github/x.yml",
32 "dir/..x/y",
33 "x..y",
34 ".a/b",
35];
37test("pathProblem names every non-canonical form, and passes canonical paths", () => {
38 for (const p of BAD) assert.notEqual(pathProblem(p), undefined, JSON.stringify(p));
39 for (const p of GOOD) assert.equal(pathProblem(p), undefined, p);
40});
42const refused = (f: () => unknown): boolean => {
43 try {
44 f();
45 } catch (e) {
46 return e instanceof ProjectError && e.code === "bad-request" && /bad file path/.test(e.message);
47 }
48 return false;
49};
51test("every write refuses them: init, edit, record (files, modes, blobs), and plain-git intake", () => {
52 for (const p of BAD) {
53 assert.ok(
54 refused(() => new Project(new MemoryStore()).init({ [p]: "x\n" }, 0)),
55 `init ${JSON.stringify(p)}`,
56 );
57 const project = new Project(new MemoryStore(), { hasBlob: () => true });
58 project.init({ "a.ts": "a\n" }, 0);
59 assert.ok(
60 refused(() => project.edit("ann", { file: p, content: "x\n" }, 1)),
61 `edit ${JSON.stringify(p)}`,
62 );
63 assert.ok(
64 refused(() => project.record("ann", { [p]: "x\n" }, 1)),
65 `record ${JSON.stringify(p)}`,
66 );
67 assert.ok(
68 refused(() => project.record("ann", {}, 1, { [p]: { exec: true } })),
69 `modes ${JSON.stringify(p)}`,
70 );
71 assert.ok(
72 refused(() => project.record("ann", {}, 1, {}, { [p]: "a".repeat(64) })),
73 `blobs ${JSON.stringify(p)}`,
74 );
75 assert.ok(
76 refused(() =>
77 project.ingest(
78 { author: "p", base: 0, commits: [{ sha: "abcdef12", message: "m", files: { "a.ts": "a\n", [p]: "x\n" } }] },
79 2,
80 ),
81 ),
82 `ingest ${JSON.stringify(p)}`,
83 );
84 assert.deepEqual(project.files(), { "a.ts": "a\n" });
85 }
86});
88test("a log with a non-canonical path from before still loads, reads, and the file can be removed", () => {
89 const atom = buildBase(
90 { "./harness/held-out/zzz.json": "{}\n", "a.ts": "a\n" },
91 { author: "init", message: "old", time: 0 },
92 );
93 const project = Project.load([{ type: "init", atom, time: 0 }], new MemoryStore());
94 assert.deepEqual(Object.keys(project.files()), ["./harness/held-out/zzz.json", "a.ts"]);
95 assert.equal(project.fileAt("./harness/held-out/zzz.json", 0).text, "{}\n");
96 // Writing to it is refused; removing it is not.
97 assert.ok(refused(() => project.record("ann", { "./harness/held-out/zzz.json": '{"pass": 1}\n' }, 1)));
98 project.record("ann", { "./harness/held-out/zzz.json": null }, 1);
99 assert.equal(project.publish("ann", "Remove the stray path", 2).ok, true);
100 assert.deepEqual(Object.keys(project.files()), ["a.ts"]);
101});
103test("paths every agent's disk can hold: no Windows short names, no < > \" | ? *, no part ending in a dot or space (git's CVE-2019-1353)", () => {
104 for (const p of [
105 "CLAUDE~1/settings.json",
106 "GIT~1/hooks/pre-commit",
107 "avcs~1/config.json",
108 "src/NODE_M~1/x.js",
109 "BACKUP~1.TXT",
110 "a<b.txt",
111 "what?.md",
112 "x|y",
113 "star*.ts",
114 'q"uote',
115 ".git./config",
116 ".git /config",
117 "docs./a.md",
118 ]) {
119 assert.notEqual(pathProblem(p), undefined, p);
120 }
121 for (const p of ["src/a~b.ts", "notes/v1.2~draft.md", "longername~1/x", "a.b/c.d", "file.txt"]) {
122 assert.equal(pathProblem(p), undefined, p);
123 }
124});
126test("the engine refuses what the client refuses: colons, .git and .avcs in any spelling, invisible characters, device names", () => {
127 const project = new Project(new MemoryStore());
128 project.init({ "a.txt": "a\n" }, 0);
129 const refused = (p: string) =>
130 assert.throws(() => project.record("ann", { [p]: "x\n" }, 1), /bad file path|is under \.avcs/, p);
131 for (const p of [
132 ".claude::$INDEX_ALLOCATION/settings.json",
133 ".git::$INDEX_ALLOCATION/config",
134 "a:b",
135 "C:/x",
136 ".AVCS/config.json",
137 "sub/.Avcs/x",
138 ".avc\u017f/config.json",
139 ".g\u0131t/config",
140 ".GIT/config",
141 ".g\u200cit/config",
142 ".git\ufeff/config",
143 "nul.txt",
144 "a/CON",
145 "com1",
146 "LPT9.log",
147 ])
148 refused(p);
149 // U+200C/U+200D are ordinary in Persian and Indic names: only a reserved name spelled with them is refused.
150 for (const p of [
151 "notes/console.md",
152 "src/nullable.ts",
153 "gitignore.md",
154 "avcs.json",
155 "docs/.avcsignore-notes.md",
156 "src/n\u200came.ts",
157 "docs/می\u200cخوام.md",
158 ]) {
159 assert.equal(pathProblem(p), undefined, p);
160 }
161});