commit 68133d7568bef61acd02ea992cba862736a1de4b
parent b8d96d6587d21cb085bbf6f9c0cfd4ae42d9d4cc
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 23:39:01 -0500
archives: a record's page host is its platform's own domain or a subdomain, never a look-alike; a remote-only channel whose archive was removed from settings is refused before its record is read (demo epic D1 re-review, must-fix 1 and item 6)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
6 files changed, 137 insertions(+), 5 deletions(-)
diff --git a/common/lib/archiveTrust.test.ts b/common/lib/archiveTrust.test.ts
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
-import { recordPageRefusal, sameOrigin } from "./remoteArchives";
+import { connectedArchives, disconnectedArchiveRefusal, isPlatformHost, recordPageRefusal, sameOrigin } from "./remoteArchives";
import { fetchOnOrigin, OffOriginError, plainGetJson, type FetchLike } from "./remoteArchives-server";
import { detectPlatform } from "./detectPlatform.mjs";
@@ -19,6 +19,56 @@ test("a record's page URL: only a video platform's host, the channel's own platf
assert.equal(r(undefined), "no page URL");
});
+test("a record's page URL: a look-alike of a platform's host is not that platform (re-review, must-fix 1)", () => {
+ const r = (u: string, p: string | null = null) => recordPageRefusal(u, p, detectPlatform);
+ // detectPlatform says "youtube" of each of these (a bare endsWith); the host table does not.
+ for (const u of [
+ "https://evilyoutube.com/watch?v=a1",
+ "https://notrumble.com/v9-x.html",
+ "https://fakeodysee.com/@a/b",
+ "https://xtwitch.tv/videos/1",
+ "https://akick.com/video/1",
+ "https://www.youtube.com.evil.example/watch?v=a1",
+ "https://youtu.be.evil.example/a1",
+ "https://web.archive.org/web/2020/https://www.youtube.com/watch?v=a1",
+ "https://notbitchute.com/video/a/",
+ ]) {
+ assert.match(r(u)!, /is not a video platform's host/, u);
+ }
+ assert.match(r("https://evilyoutube.com/watch?v=a1", "youtube")!, /^evilyoutube\.com is not a video platform's host/);
+ // The platforms' own hosts, bare and under a subdomain.
+ for (const u of [
+ "https://youtube.com/watch?v=a1",
+ "https://m.youtube.com/watch?v=a1",
+ "https://music.youtube.com/watch?v=a1",
+ "https://youtu.be/a1",
+ "https://rumble.com/v9-x.html",
+ "https://www.rumble.com/v9-x.html",
+ "https://odysee.com/@a/b",
+ "https://www.twitch.tv/videos/1",
+ "https://kick.com/video/1",
+ "https://archive.org/details/x",
+ "https://www.archive.org/details/x",
+ "https://www.bitchute.com/video/a/",
+ "https://old.bitchute.com/video/a/",
+ ]) {
+ assert.equal(r(u), null, u);
+ }
+ assert.equal(isPlatformHost("youtube", "YOUTUBE.com"), true);
+ assert.equal(isPlatformHost("youtube", "youtube.com.evil.example"), false);
+ assert.equal(isPlatformHost("twitter", "x.com"), false, "not a video platform: no table, no host");
+});
+
+test("an archive removed from settings is not read for the channel registered from it (re-review, item 6)", () => {
+ const list = connectedArchives([{ id: "stub", origin: "https://stub.test", title: "Stub", addedAt: "2026-11-11T00:00:00Z" }], {});
+ assert.equal(disconnectedArchiveRefusal("https://stub.test", list), null);
+ assert.equal(disconnectedArchiveRefusal("https://stub.test/", list), null);
+ assert.equal(disconnectedArchiveRefusal(undefined, list), null, "a channel naming no archive has none to lose");
+ assert.match(disconnectedArchiveRefusal("https://stub.test", [])!, /^its archive https:\/\/stub\.test is no longer connected/);
+ // The environment's archive counts as connected.
+ assert.equal(disconnectedArchiveRefusal("https://env.test", connectedArchives([], { TRANSCRIPT_SITE_URL: "https://env.test" })), null);
+});
+
function redirecting(map: Record<string, { status: number; location?: string; body?: unknown }>): FetchLike & { asked: string[] } {
const asked: string[] = [];
const f = (async (url: string) => {
diff --git a/common/lib/remoteArchives.ts b/common/lib/remoteArchives.ts
@@ -176,6 +176,19 @@ export function findConnectedArchive(list: readonly ConnectedArchive[], origin:
}
/**
+ * Why a remote-only channel's archive is not read any more, or null: the
+ * origin its config names (`remoteArchive`) is no longer among the connected
+ * archives — removed from settings since the channel was registered. Its
+ * record is not asked for and no window is fetched for it (demo epic D1
+ * re-review, item 6).
+ */
+export function disconnectedArchiveRefusal(origin: string | null | undefined, list: readonly ConnectedArchive[]): string | null {
+ if (!origin) return null;
+ if (findConnectedArchive(list, origin)) return null;
+ return `its archive ${origin} is no longer connected — connect it again (the editor's /sites, "Connected archives") to fetch its windows`;
+}
+
+/**
* The marker a remote-only channel's whole-recording refusal starts with
* (controller/remoteOnlyChannel.ts wholeRecordingRefusal): umtool's chain
* looks for it to offer the one-press override (`allowWholeRecording`).
@@ -190,6 +203,28 @@ export const WHOLE_RECORDING_REFUSED = "whole recording refused:";
// thread path on any host.
export const RECORD_PAGE_PLATFORMS = ["youtube", "rumble", "odysee", "twitch", "kick", "archiveorg", "bitchute"] as const;
+// Each platform's own domains, matched EXACTLY or as a parent (`host === d` or
+// `host` ends in `.d`). lib/detectPlatform.mjs answers "which platform is
+// this", loosely (`host.endsWith("youtube.com")` is true of evilyoutube.com);
+// here the question is "may this machine fetch from that host", so the answer
+// it gives is checked against this table (demo epic D1 re-review, must-fix 1).
+export const RECORD_PAGE_HOSTS: Record<(typeof RECORD_PAGE_PLATFORMS)[number], readonly string[]> = {
+ youtube: ["youtube.com", "youtu.be"],
+ rumble: ["rumble.com"],
+ odysee: ["odysee.com"],
+ twitch: ["twitch.tv"],
+ kick: ["kick.com"],
+ archiveorg: ["archive.org"],
+ bitchute: ["bitchute.com"],
+};
+
+/** Whether `host` is one of `platform`'s own domains or a subdomain of one. */
+export function isPlatformHost(platform: string, host: string): boolean {
+ const domains = (RECORD_PAGE_HOSTS as Record<string, readonly string[] | undefined>)[platform];
+ const h = host.toLowerCase().replace(/\.$/, "");
+ return !!domains && domains.some((d) => h === d || h.endsWith(`.${d}`));
+}
+
/**
* Why a remote-only channel's page URL — an archive record's `webpageUrl`, or
* one an ask carried for it — is not fetched, or null when it may be. The
@@ -207,7 +242,7 @@ export function recordPageRefusal(url: string | null | undefined, channelPlatfor
}
if ((u.protocol !== "https:" && u.protocol !== "http:") || u.username || u.password) return `${u.protocol}//${u.host} is not a page URL a window is fetched from`;
const platform = detect(url);
- if (!platform || !(RECORD_PAGE_PLATFORMS as readonly string[]).includes(platform)) {
+ if (!platform || !(RECORD_PAGE_PLATFORMS as readonly string[]).includes(platform) || !isPlatformHost(platform, u.hostname)) {
return `${u.host} is not a video platform's host (${RECORD_PAGE_PLATFORMS.join(", ")}): the archive's page URL is not fetched`;
}
if (channelPlatform && channelPlatform !== platform) {
diff --git a/editor/app/api/media/fetch-window/route.remote.test.ts b/editor/app/api/media/fetch-window/route.remote.test.ts
@@ -32,8 +32,10 @@ const DOCS: Record<string, unknown> = {
[`${ORIGIN}/transcripts/rb-remote/manifest.json`]: { slugToPage: { rb9: 0 } },
[`${ORIGIN}/transcripts/rb-remote/page-0000.json`]: [{ id: "rb9", duration: 600, webpageUrl: "https://rumble.com/vrb9-x.html" }],
};
+const asked: string[] = [];
globalThis.fetch = (async (input: RequestInfo | URL) => {
const url = String(input);
+ asked.push(url);
return url in DOCS ? new Response(JSON.stringify(DOCS[url]), { status: 200 }) : new Response("nope", { status: 404 });
}) as typeof fetch;
const { POST } = await import("./route");
@@ -69,3 +71,13 @@ test("a single window whose archive record points at a non-platform host is refu
assert.equal(r.status, 400);
assert.match(r.json.error ?? "", /^yt-evil\/e1: 169\.254\.169\.254 is not a video platform's host/);
});
+
+// LAST: it disconnects the archive for the rest of the file.
+test("a remote-only channel whose archive was removed from settings is refused (400), and the archive is not read", async () => {
+ await writeFile(process.env.SETTINGS_FILE!, JSON.stringify({ remoteArchives: [] }));
+ asked.length = 0;
+ const r = await post({ channelSlug: "rb-remote", videoId: "rb9", from: 10, to: 20, requestedBy: "test", reason: "a test" });
+ assert.equal(r.status, 400, r.json.error);
+ assert.match(r.json.error ?? "", /^rb-remote is a remote-only channel, and its archive https:\/\/stub\.test is no longer connected/);
+ assert.deepEqual(asked, [], "nothing asked of an archive that is not connected");
+});
diff --git a/editor/app/api/media/fetch-window/route.ts b/editor/app/api/media/fetch-window/route.ts
@@ -22,7 +22,7 @@ import { getPaths } from "yt-dlp-transcript-common/lib/paths";
import { getSettings } from "yt-dlp-transcript-common/lib/settings";
import { detectPlatform } from "yt-dlp-transcript-common/lib/platform";
import { isRemoteOnlyChannel } from "yt-dlp-transcript-common/lib/channelConfig";
-import { connectedArchives, findConnectedArchive, recordPageRefusal } from "yt-dlp-transcript-common/lib/remoteArchives";
+import { connectedArchives, disconnectedArchiveRefusal, findConnectedArchive, recordPageRefusal } from "yt-dlp-transcript-common/lib/remoteArchives";
import { cachedArchiveGetJson } from "yt-dlp-transcript-common/lib/archiveCache-server";
import { readChannelConfig } from "yt-dlp-transcript-common/controller/channels";
import { wholeRecordingFor } from "yt-dlp-transcript-common/controller/fetchWindows";
@@ -227,6 +227,10 @@ export async function POST(request: Request) {
}
}
if (config && isRemoteOnlyChannel(config)) {
+ // An archive removed from settings is not read any more, for a channel
+ // registered while it was connected either.
+ const gone = disconnectedArchiveRefusal(config.remoteArchive, connectedArchives(getSettings().remoteArchives));
+ if (gone) return NextResponse.json({ error: `${channelSlug} is a remote-only channel, and ${gone}` }, { status: 400 });
const record = config.remoteArchive ? await archiveRecordOf(config.remoteArchive, channelSlug, videoId, { getJson }).catch(() => null) : null;
webpageUrl ||= record?.webpageUrl;
// An archive is untrusted input (demo epic D1 review): its page URL must
diff --git a/editor/app/api/ops/fetch-windows/route.remote.test.ts b/editor/app/api/ops/fetch-windows/route.remote.test.ts
@@ -35,10 +35,12 @@ const DOCS: Record<string, unknown> = {
[`${ORIGIN}/transcripts/rb-remote/manifest.json`]: { pageCount: 1, slugToPage: { rb9: 0 } },
[`${ORIGIN}/transcripts/rb-remote/page-0000.json`]: [{ id: "rb9", duration: 5400, webpageUrl: "https://rumble.com/vrb9-x.html" }],
// An archive pointing the editor at its own API (review of 9fddc3bb, blocker 2).
- [`${ORIGIN}/transcripts/evil-remote/manifest.json`]: { slugToPage: { e1: 0, e2: 0 } },
+ [`${ORIGIN}/transcripts/evil-remote/manifest.json`]: { slugToPage: { e1: 0, e2: 0, e3: 0 } },
[`${ORIGIN}/transcripts/evil-remote/page-0000.json`]: [
{ id: "e1", webpageUrl: "http://127.0.0.1:3001/api/ops/settings" },
{ id: "e2", webpageUrl: "https://rumble.com/ve2-x.html" },
+ // A look-alike of the channel's platform (re-review, must-fix 1).
+ { id: "e3", webpageUrl: "https://evilyoutube.com/watch?v=e3" },
],
};
const asked: string[] = [];
@@ -111,3 +113,23 @@ test("an archive's record pointing anywhere but its channel's video platform is
assert.deepEqual(r.json.jobIds, []);
assert.equal(asked.some((u) => u.startsWith("http://127.0.0.1")), false);
});
+
+test("a look-alike of the channel's platform host is refused before any request", async () => {
+ const r = await post({ requestedBy: "test", archive: ORIGIN, items: [{ slug: "evil-remote", id: "e3", from: 1, to: 5 }, { slug: "evil-remote", id: "e4", from: 1, to: 5, webpageUrl: "https://www.youtube.com.evil.example/watch?v=e4" }] });
+ assert.equal(r.status, 200, r.json.error);
+ const errors = (r.json.unresolved as Unresolved).map((u) => u.error);
+ assert.match(errors[0], /^evilyoutube\.com is not a video platform's host/);
+ assert.match(errors[1], /^www\.youtube\.com\.evil\.example is not a video platform's host/);
+ assert.deepEqual(r.json.jobIds, []);
+});
+
+// LAST: it disconnects the archive for the rest of the file.
+test("a remote-only channel whose archive was removed from settings is refused, and the archive is not read", async () => {
+ await writeFile(process.env.SETTINGS_FILE!, JSON.stringify({ remoteArchives: [] }));
+ asked.length = 0;
+ const r = await post({ requestedBy: "test", items: [{ slug: "rb-remote", id: "rb9", from: 60, to: 70 }] });
+ assert.equal(r.status, 200, r.json.error);
+ assert.deepEqual(r.json.jobIds, []);
+ assert.match((r.json.unresolved as Unresolved)[0].error, /^rb-remote is a remote-only channel, and its archive https:\/\/stub\.test is no longer connected/);
+ assert.deepEqual(asked, [], "nothing asked of an archive that is not connected");
+});
diff --git a/editor/app/channels/[slug]/videos/fetchWindowsAction.ts b/editor/app/channels/[slug]/videos/fetchWindowsAction.ts
@@ -63,7 +63,7 @@ import {
} from "yt-dlp-transcript-common/jobs/streamCommand";
import { safeRevalidate } from "../../../lib/safeRevalidate";
import { isRemoteOnlyChannel } from "yt-dlp-transcript-common/lib/channelConfig";
-import { connectedArchives, findConnectedArchive, recordPageRefusal, type ConnectedArchive } from "yt-dlp-transcript-common/lib/remoteArchives";
+import { connectedArchives, disconnectedArchiveRefusal, findConnectedArchive, recordPageRefusal, type ConnectedArchive } from "yt-dlp-transcript-common/lib/remoteArchives";
import {
archiveRecordOf,
ensureRemoteOnlyChannel,
@@ -351,6 +351,15 @@ async function planFetchWindows(
continue;
}
}
+ // An archive removed from settings is not read any more, for a channel
+ // registered while it was connected either: nothing is asked of it.
+ if (isRemoteOnlyChannel(config)) {
+ const gone = disconnectedArchiveRefusal(config.remoteArchive, connectedArchives(settings.remoteArchives));
+ if (gone) {
+ unresolved.push({ item, error: `${item.slug} is a remote-only channel, and ${gone}` });
+ continue;
+ }
+ }
// A REMOTE-ONLY channel has no metadata or playlist of its own: the page
// URL is the ask's, else its archive's record.
const record =