From 6940926c6fae942962fe4f69a022301547ee35e9 Mon Sep 17 00:00:00 2001 From: leemour Date: Wed, 25 Nov 2026 21:51:08 +0100 Subject: [PATCH] fix(organizations): domain-lists update names each host once hostFetch refuses a host list with a repeat, and the manifest's own host and its release assets are all github.com, so every real update failed before it started. Found running the update against the first published pack. Co-Authored-By: Claude Opus 5.5 --- src/services/domain-lists-download.test.ts | 17 ++++++++++++++++- src/services/domain-lists-download.ts | 9 +++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/services/domain-lists-download.test.ts b/src/services/domain-lists-download.test.ts index 2485f8ad9..a13b6c103 100644 --- a/src/services/domain-lists-download.test.ts +++ b/src/services/domain-lists-download.test.ts @@ -3,7 +3,7 @@ import { existsSync, rmSync } from "node:fs" import { gzipSync } from "node:zlib" import { afterEach, expect, it } from "vitest" import { domainListsDirectory, installedPack, listFile, lookupDomains } from "../domain/domain-lists.js" -import { updateDomainLists } from "./domain-lists-download.js" +import { packHosts, updateDomainLists } from "./domain-lists-download.js" const MANIFEST = "https://example.org/manifest.json" @@ -113,3 +113,18 @@ it("refuses a manifest whose source id would write outside the pack", async () = ) await expect(updateDomainLists({ env: process.env, fetch, manifestUrl: MANIFEST })).rejects.toThrow(/source id/) }) + +it("names each host a download may reach once, the release's own included", () => { + expect( + packHosts([ + "https://github.com/WireCatLabs/cli-core/releases/download/domain-lists/manifest.json", + "https://github.com/WireCatLabs/cli-core/releases/download/domain-lists-2026-11-25/ut1-sectors.txt.gz", + "https://www.stopforumspam.com/downloads/toxic_domains_whole.txt", + ]), + ).toEqual([ + "github.com", + "release-assets.githubusercontent.com", + "objects.githubusercontent.com", + "www.stopforumspam.com", + ]) +}) diff --git a/src/services/domain-lists-download.ts b/src/services/domain-lists-download.ts index a8fc97088..9d075ddff 100644 --- a/src/services/domain-lists-download.ts +++ b/src/services/domain-lists-download.ts @@ -37,6 +37,11 @@ export interface DomainListsUpdate { const RELEASE_HOSTS = ["github.com", "release-assets.githubusercontent.com", "objects.githubusercontent.com"] const DOWNLOAD_MS = 10 * 60_000 +/** The hosts a download may reach, each once: `hostFetch` refuses a list that names one twice. */ +export const packHosts = (urls: readonly string[]): string[] => [ + ...new Set([...RELEASE_HOSTS, ...urls.map((url) => new URL(url).hostname)]), +] + const ID = /^[a-z0-9][a-z0-9-]{0,62}$/ const SHA256 = /^[0-9a-f]{64}$/ const DOMAIN = /^[a-z0-9_]([a-z0-9_.-]*[a-z0-9])?$/ @@ -131,12 +136,12 @@ export const updateDomainLists = async ({ }: DomainListsUpdateOptions): Promise => { const manifest = await fetchManifest( manifestUrl, - given ?? hostFetch({ hosts: [...RELEASE_HOSTS, new URL(manifestUrl).hostname], timeoutMs: 60_000 }), + given ?? hostFetch({ hosts: packHosts([manifestUrl]), timeoutMs: 60_000 }), ) const get = given ?? hostFetch({ - hosts: [...RELEASE_HOSTS, ...manifest.sources.map((one) => new URL(one.url).hostname)], + hosts: packHosts(manifest.sources.map((one) => one.url)), timeoutMs: DOWNLOAD_MS, }) const before = installedPack(env)