Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 82800aa4597cdee5b847fae72ae3a005f005a275
parent 894f1bfc6accaf9f355414da6dd6d74af1ed05a6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 12 Nov 2026 00:27:18 -0500

archives: the private-host check reads three more IPv6 forms that carry an IPv4 -- NAT64's local-use prefix, IPv4-translated and 6to4 -- and tests pin every spelling of a local address at connect, a redirect to one, and more look-alike hosts (demo epic D1 re-review, self-check)

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/remoteArchives.test.ts | 26++++++++++++++++++++++++++
Mcommon/lib/archiveHosts-server.test.ts | 41+++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/archiveHosts-server.ts | 6+++++-
Mcommon/lib/archiveTrust.test.ts | 7+++++++
4 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/common/controller/remoteArchives.test.ts b/common/controller/remoteArchives.test.ts @@ -94,3 +94,29 @@ test("a local or private archive host is refused before anything is asked of it; const stored = world([{ id: "lan", origin: "http://10.0.0.7", title: "LAN", addedAt: "2026-11-11T00:00:00.000Z" }]); assert.equal((await connectRemoteArchive({ origin: "http://10.0.0.7" }, stored.deps)).already, true); }); + +// demo epic D1 re-review, must-fix 2: the address forms a URL may spell, and a redirect at connect. +test("a local address in any spelling is refused at connect, nothing asked; allowed only by the operator's own word", async () => { + for (const origin of ["http://[::ffff:7f00:1]", "http://[::ffff:127.0.0.1]:3001", "http://[::1]", "http://0.0.0.0:3001", "http://2130706433", "http://0x7f000001", "http://0177.0.0.1", "http://127.1"]) { + const w = world(); + await assert.rejects(connectRemoteArchive({ origin }, w.deps), /an archive on this machine or its network is connected only when/, origin); + assert.deepEqual(w.asked, [], `${origin}: nothing asked`); + assert.equal(w.writes.length, 0, `${origin}: nothing written`); + const allowed = world([], { ARCHILYZER_ALLOW_PRIVATE_ARCHIVES: "1" }); + assert.equal((await connectRemoteArchive({ origin }, allowed.deps)).already, false, `${origin}: allowed when decided here`); + } +}); + +test("a public archive that redirects its corpus.json to a private address is not followed and not connected", async () => { + for (const location of ["http://127.0.0.1:3001/corpus.json", "http://[::ffff:7f00:1]/corpus.json", "http://169.254.169.254/latest/meta-data/", "http://2130706433/corpus.json", "//localhost:3001/corpus.json"]) { + const w = world(); + const asked: string[] = []; + w.deps.fetch = async (url) => { + asked.push(url); + return new Response(null, { status: 302, headers: { location } }); + }; + await assert.rejects(connectRemoteArchive({ origin: "https://stub.test" }, w.deps), /an archive's documents are read from its own origin only/, location); + assert.deepEqual(asked, ["https://stub.test/corpus.json"], `${location}: the redirect is not followed`); + assert.equal(w.writes.length, 0, `${location}: nothing written`); + } +}); diff --git a/common/lib/archiveHosts-server.test.ts b/common/lib/archiveHosts-server.test.ts @@ -55,6 +55,47 @@ test("a mapped literal in an origin is refused at connect, and a name resolving assert.equal(await privateHostRefusal("http://[::ffff:5db8:d822]", { lookup }), null); }); +test("the other ways an IPv6 literal carries a private IPv4: NAT64's local-use prefix, IPv4-translated, 6to4", () => { + for (const a of ["64:ff9b:1::7f00:1", "::ffff:0:7f00:1", "::ffff:0:10.0.0.1", "2002:7f00:1::", "2002:c0a8:101::1", "2002:a9fe:a9fe::"]) { + assert.equal(isPrivateAddress(a), true, a); + } + for (const a of ["64:ff9b:1::808:808", "::ffff:0:808:808", "2002:808:808::1"]) assert.equal(isPrivateAddress(a), false, a); +}); + +test("every spelling of a local address in an origin is refused: decimal, hex, octal, short, a trailing dot, bracketed IPv6", async () => { + const { archiveOriginOf } = await import("./remoteArchives"); + // The names' answers are what a resolver gives for them; nothing here is asked of the network. + const lookup = async (h: string) => (/^localhost\.?$/.test(h) || /\.local\.?$/.test(h) ? [{ address: "127.0.0.1" }] : [{ address: "93.184.216.34" }]); + for (const typed of [ + "http://[::ffff:7f00:1]", + "http://[::ffff:127.0.0.1]", + "http://[0:0:0:0:0:ffff:127.0.0.1]", + "http://[::1]", + "http://[::]", + "http://0.0.0.0", + "http://0", + "http://2130706433", // 127.0.0.1 as one decimal number + "http://3232235777", // 192.168.1.1 + "http://0x7f000001", + "http://0x7f.0.0.1", + "http://017700000001", + "http://0177.0.0.1", + "http://127.1", + "http://127.0.0.1.", + "http://169.254.169.254.", + "http://LOCALHOST", + "http://localhost.", + "http://nas.local.", + "http://router.lan", + "http://[64:ff9b:1::7f00:1]", + "http://[2002:7f00:1::]", + ]) { + const origin = archiveOriginOf(typed); + assert.ok(origin, `${typed} is an origin`); + assert.match((await privateHostRefusal(origin, { lookup })) ?? "", /a local or private address|a local name/, typed); + } +}); + test("a host's refusal: literal, by name, by what the name resolves to; a public one passes", async () => { const lookup = async (h: string) => (h === "inside.example" ? [{ address: "10.0.0.2" }] : [{ address: "93.184.216.34" }]); assert.match((await privateHostRefusal("http://169.254.169.254", { lookup }))!, /a local or private address/); diff --git a/common/lib/archiveHosts-server.ts b/common/lib/archiveHosts-server.ts @@ -70,7 +70,8 @@ const v4Of = (hi: number, lo: number) => `${hi >> 8}.${hi & 255}.${lo >> 8}.${lo * Whether an IP address is loopback, private, link-local, site-local, CGNAT, * unspecified or multicast — in IPv6 also when it only CARRIES such an IPv4 * address: IPv4-mapped (`::ffff:a.b.c.d`, in either spelling), the old - * IPv4-compatible form (`::a.b.c.d`) and NAT64 (`64:ff9b::/96`). + * IPv4-compatible form (`::a.b.c.d`), NAT64 (`64:ff9b::/96` and the local-use + * `64:ff9b:1::/48`), IPv4-translated (`::ffff:0:a.b.c.d`) and 6to4 (`2002::/16`). */ export function isPrivateAddress(address: string): boolean { const a = address.replace(/^\[|\]$/g, "").toLowerCase(); @@ -84,6 +85,9 @@ export function isPrivateAddress(address: string): boolean { if (zero(0, 5) && g[5] === 0xffff) return v4Private(v4Of(g[6], g[7])); // IPv4-mapped if (zero(0, 6)) return v4Private(v4Of(g[6], g[7])); // IPv4-compatible (deprecated) if (g[0] === 0x64 && g[1] === 0xff9b && zero(2, 6)) return v4Private(v4Of(g[6], g[7])); // NAT64 + if (g[0] === 0x64 && g[1] === 0xff9b && g[2] === 1) return v4Private(v4Of(g[6], g[7])); // NAT64, the local-use prefix 64:ff9b:1::/48 + if (zero(0, 4) && g[4] === 0xffff && g[5] === 0) return v4Private(v4Of(g[6], g[7])); // IPv4-translated ::ffff:0:a.b.c.d + if (g[0] === 0x2002) return v4Private(v4Of(g[1], g[2])); // 6to4 2002:a.b.c.d::/48 return ( (g[0] & 0xfe00) === 0xfc00 || // fc00::/7 unique local (g[0] & 0xffc0) === 0xfe80 || // fe80::/10 link-local diff --git a/common/lib/archiveTrust.test.ts b/common/lib/archiveTrust.test.ts @@ -32,6 +32,13 @@ test("a record's page URL: a look-alike of a platform's host is not that platfor "https://youtu.be.evil.example/a1", "https://web.archive.org/web/2020/https://www.youtube.com/watch?v=a1", "https://notbitchute.com/video/a/", + "https://notyoutube.com/watch?v=a1", + "https://evil-rumble.com/v9-x.html", + "https://rumble.comevil.example/v9-x.html", + "https://evil.example/youtube.com/watch?v=a1", + "https://evil.example\\@youtube.com/watch?v=a1", + "https://youtube.com%2eevil.example/watch?v=a1", + "https://youtubе.com/watch?v=a1", // a Cyrillic е ]) { assert.match(r(u)!, /is not a video platform's host/, u); }