Public: anyone can read this; the crew can change it.

A spawn body id that begins with `-` is refused before it can reach tar as an option #15004

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/14992-a-spawn-body-id-that-begins-with-is-refu → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/14992-a-spawn-body-id-that-begins-with-is-refu was merged into main as 0948e2f.

Review

Sign in to review this change.
1 file changed +21 −1
test/forge-archive.test.ts +21 −1
@@ -5,7 +5,7 @@
55 * Restore.
66 */
77 import { afterAll, beforeAll, expect, test } from "bun:test";
8 import { existsSync, readdirSync } from "node:fs";
8 import { existsSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
99 import { mkdtemp, rm } from "node:fs/promises";
1010 import { tmpdir } from "node:os";
1111 import { join } from "node:path";
@@ -194,6 +194,26 @@ test("a copy that does not read back the same removes nothing", async () => {
194194 expect(archivedForges(parent).some((a) => a.name === "kept-safe")).toBe(false);
195195 });
196196
197 test("a body id that begins with - is refused before it reaches tar as an option (#14992)", async () => {
198 const { made, childDir, child } = await makeForge("dash-id", false);
199 child.close();
200 // A ledger whose body id tar would read as `--remove-files`: the archive would delete the ledger
201 // it had just copied.
202 const evil = "--remove-files";
203 renameSync(childDir, childDirOf(parent, evil));
204 const ledger = join(dir, "spawn", "dash-id.json");
205 writeFileSync(ledger, JSON.stringify({ ...JSON.parse(readFileSync(ledger, "utf8")), bodyId: evil }));
206 const done = await archiveForge(parent, "dash-id", { destination: { source: "dir", store: dirStore(store) } });
207 expect(done.ok).toBe(false);
208 expect(done.says).toContain("no data directory to archive");
209 expect(existsSync(ledger)).toBe(true);
210 expect(existsSync(childDirOf(parent, evil))).toBe(true);
211 expect((await dirStore(store).list("forge-archives/dash-id/")).length).toBe(0);
212 // Put back as it was, so the forges after this one see an ordinary host.
213 renameSync(childDirOf(parent, evil), childDir);
214 writeFileSync(ledger, JSON.stringify({ ...JSON.parse(readFileSync(ledger, "utf8")), bodyId: made.bodyId }));
215 });
216

The restore only runs if every expect above passes. Put the body in try/finally so a red assertion does not poison the forges after it.

197217 test("with no backup destination nothing is archived", async () => {
198218 const saved = process.env["FORGE_SNAPSHOT_DIR"];
199219 delete process.env["FORGE_SNAPSHOT_DIR"];

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs