commit f3ce86a97be65dfe3412ea8dc00fb75f0df23446
parent 4be38e262fd8a2dc666f50d438682fdb52202419
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 12 Nov 2026 02:53:25 -0500
umtool: posts attach refuses a capture's file name, post id or channel that is not a plain name (a separator, . or .., empty) before any file is read or any folder made, in either tree
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/umtool/lib/report/postComboCli.mjs b/umtool/lib/report/postComboCli.mjs
@@ -150,8 +150,17 @@ export async function scenesView(project, { channelsDir = null } = {}) {
const TIER_WORDS = { "media-id": "X media id", sha256: "same file", audio: "same sound" };
const MATCH_WORDS = { id: "the X media id", file: "the X media id, then the file's bytes", audio: "the X media id, the bytes, then the sound" };
+/**
+ * Is this ONE path segment -- a capture's file name, a post id, a channel slug as a capture or a manifest gives them?
+ * Not empty, not `.` or `..`, no separator (either slash) and no NUL: a name is joined into a path in a channels tree
+ * and in the project, and `../../x` would read, and write, outside both.
+ */
+export const isPathSegment = (v) => typeof v === "string" && v !== "" && v !== "." && v !== ".." && !/[/\\\0]/.test(v);
+
/** Copy a capture's file into the project (never through a link out of it); the same size already there is left. */
async function copyIn(projectDir, from, rel) {
+ // Before anything is made: every segment a plain name (attachFromCaptures checks them too -- this is the writer's own).
+ if (!rel.split("/").every(isPathSegment)) throw new ComboError(`${JSON.stringify(rel)} is not a path inside the project — not copying`);
const to = path.join(projectDir, ...rel.split("/"));
const [a, b] = await Promise.all([stat(from).catch(() => null), stat(to).catch(() => null)]);
if (a && b && a.size === b.size) return;
@@ -206,6 +215,10 @@ export async function attachFromCaptures(project, { ids = null, dryRun = false,
const postId = String(tl.find((e) => e?.id === id)?.post ?? "").split("/")[1];
const media = [];
for (const m of list) {
+ // A capture's names are data: refused before any file is looked at, in whichever tree it was found.
+ for (const [what, v] of [["file name", m.name], ["post id", postId], ["channel", m.slug]]) {
+ if (!isPathSegment(v)) throw new ComboError(`${id}: its capture's ${what} ${JSON.stringify(v ?? null)} is not a plain name (a path separator, "." or "..", or empty) — nothing attached`);
+ }
const from = path.join(m.tree, m.slug, "posts-media", postId, m.name);
if (!(await stat(from).catch(() => null))) continue;
const rel = `posts-media/${m.slug}/${postId}/${m.name}`;
diff --git a/umtool/lib/report/postComboCli.test.mjs b/umtool/lib/report/postComboCli.test.mjs
@@ -8,7 +8,7 @@ import { tmpdir } from "node:os";
import path from "node:path";
import { after, test } from "node:test";
import { postsCommand } from "./postsCli.mjs";
-import { attachFromCaptures, attachLines, repeatsView } from "./postComboCli.mjs";
+import { attachFromCaptures, attachLines, isPathSegment, repeatsView } from "./postComboCli.mjs";
const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-post-combo-"));
after(() => rm(ROOT, { recursive: true, force: true }));
@@ -175,3 +175,46 @@ test("posts attach reads every channels tree: the project's first, then the arch
assert.equal(await listing(), archiveBefore, "nothing added to the archive");
assert.equal((await stat(gif)).mtimeMs, mtimeBefore, "its file untouched");
});
+
+test("posts attach refuses a capture whose file name is not a plain name, before any file is touched -- in either tree", async () => {
+ const { readdir } = await import("node:fs/promises");
+ for (const bad of ["../../x", "a/b", "..", ".", "a\\b"]) assert.equal(isPathSegment(bad), false, bad);
+ assert.equal(isPathSegment(""), false);
+ assert.equal(isPathSegment("3_1.mp4"), true);
+ let n = 0;
+ for (const bad of ["../../x", "a/b", ".."]) {
+ for (const where of ["project", "archive"]) {
+ n += 1;
+ const p = await project(`bad${n}`);
+ const shadow = path.join(p.dir, ".shadow-channels");
+ const archive = path.join(ROOT, `bad-archive-${n}`);
+ const tree = where === "project" ? shadow : archive;
+ const capDir = path.join(tree, "obv-x", "posts-media", "3");
+ await mkdir(capDir, { recursive: true });
+ await mkdir(shadow, { recursive: true });
+ await mkdir(archive, { recursive: true });
+ // A file where the name points, so only the check stands between it and a read.
+ await writeFile(path.join(tree, "x"), "OUTSIDE");
+ await writeFile(path.join(capDir, "capture.json"), JSON.stringify({ media: [{ name: bad, url: "https://video.twimg.com/tweet_video/C.mp4" }] }));
+ const before = (await readdir(p.dir, { recursive: true })).sort().join("\n");
+ const manifestBefore = await readFile(path.join(p.dir, "video.manifest.json"), "utf8");
+ for (const dryRun of [true, false]) {
+ await assert.rejects(attachFromCaptures(p, { channelsDirs: [shadow, archive], dryRun }), (e) => {
+ assert.match(e.message, /p-3: its capture's file name .* is not a plain name/, `${bad} in the ${where}'s tree`);
+ return true;
+ });
+ }
+ assert.equal((await readdir(p.dir, { recursive: true })).sort().join("\n"), before, "no directory made in the project");
+ assert.equal(await readFile(path.join(p.dir, "video.manifest.json"), "utf8"), manifestBefore);
+ // The CLI says it and exits 2.
+ if (where === "project") {
+ const m = JSON.parse(manifestBefore);
+ m.provenance.channelsDir = shadow;
+ await writeFile(path.join(p.dir, "video.manifest.json"), JSON.stringify(m, null, 2));
+ const r = await run(["attach", `bad${n}`, "--all", "--dry-run"]);
+ assert.equal(r.code, 2, r.out + r.err);
+ assert.match(r.err, /is not a plain name/);
+ }
+ }
+ }
+});
diff --git a/umtool/report-to-video/post-combo-prints.mjs b/umtool/report-to-video/post-combo-prints.mjs
@@ -211,12 +211,14 @@ export async function captureOnlyMedia(manifest, { channelsDir = null, channelsD
const trees = (Array.isArray(channelsDirs) && channelsDirs.length ? channelsDirs : [channelsDir]).filter((d) => typeof d === "string" && d);
if (!trees.length) return {};
const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : [];
- const channels = [...new Set(tl.filter((e) => e?.type === "post" && typeof e.post === "string").map((e) => e.post.split("/")[0]).filter(Boolean))];
+ const channels = [...new Set(tl.filter((e) => e?.type === "post" && typeof e.post === "string").map((e) => e.post.split("/")[0]).filter((c) => c && c !== "." && c !== ".." && !/[\\\0]/.test(c)))];
const out = {};
for (const e of tl) {
if (e?.type !== "post" || typeof e.post !== "string" || (Array.isArray(e.media) && e.media.length)) continue;
const [own, postId] = e.post.split("/");
if (!own || !postId) continue;
+ // A post id of dots is no folder of a capture: never joined into a tree's path.
+ if ([own, postId].some((v) => v === "." || v === ".." || /[\\\0]/.test(v))) continue;
found: for (const tree of trees) {
for (const slug of [own, ...channels.filter((c) => c !== own)]) {
const dirOf = path.join(tree, slug, "posts-media", postId);