From a508f314277202eb4e44e4891dea05a34828d136 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 18:17:30 -0600 Subject: [PATCH] fix(pm-stack): refuse impossible renewal dates in JSON DNS register path (#4858) --- pm-stack/aggregator/src/dns.ts | 15 ++++++++-- pm-stack/aggregator/test/slice3.test.ts | 40 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/pm-stack/aggregator/src/dns.ts b/pm-stack/aggregator/src/dns.ts index b8e7f5ccfa..4310690f04 100644 --- a/pm-stack/aggregator/src/dns.ts +++ b/pm-stack/aggregator/src/dns.ts @@ -132,7 +132,13 @@ export function dnsSectionFromRegisterJson( } = raw; if (typeof domain !== "string" || domain.length === 0 || seen.has(domain)) return null; if (typeof registrar !== "string" || typeof dnsHost !== "string") return null; - if (typeof renewal !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(renewal)) return null; + // Shape alone is not enough: an impossible calendar date + // (2027-02-30, 2026-13-01) must return null like any other + // malformation, so the caller falls back to the Markdown parse + // instead of serving a poisoned register (#4858, cf. #2199). + // isIsoDate re-checks the components, so leap dates + // (2024-02-29) still parse. + if (typeof renewal !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(renewal) || !isIsoDate(renewal)) return null; if (price !== null && price !== undefined && (typeof price !== "number" || !Number.isFinite(price))) return null; if (autoRenew !== null && autoRenew !== undefined && typeof autoRenew !== "boolean") return null; seen.add(domain); @@ -180,7 +186,12 @@ export function isDnsSection(v: unknown): v is DnsSection { typeof e === "object" && e !== null && typeof (e as DnsEntry).domain === "string" && - typeof (e as DnsEntry).renewal === "string" && + // renewal must be a real calendar date, not merely a string: + // an impossible date (2027-02-30, 2026-13-01) string-sorts + // into summarizeDns and poisons nextRenewal (#4858, cf. #2199 + // for the builder paths). isIsoDate also rejects non-strings + // and shape-invalid strings, so this subsumes the typeof check. + isIsoDate((e as DnsEntry).renewal) && // priceUsd is number|null in the model: null/absent stays valid, // but a present value must be a finite number (#2412). (() => { diff --git a/pm-stack/aggregator/test/slice3.test.ts b/pm-stack/aggregator/test/slice3.test.ts index fc9214f6c9..23dd38a9c5 100644 --- a/pm-stack/aggregator/test/slice3.test.ts +++ b/pm-stack/aggregator/test/slice3.test.ts @@ -252,6 +252,46 @@ describe("dns register parser", () => { expect(dnsSectionFromRegisterJson(dup, "2026-11-01T17:00:00Z", "t", mdEntries)).toBeNull(); }); + test("register.json section: impossible renewal dates yield null, leap date kept (#4858)", () => { + const mdEntries = parseDnsRegister(REGISTER_MD); + const row = (domain: string, next_renewal: string) => ({ + domain, + registrar: "Porkbun", + dns_hosted_at: "Porkbun", + next_renewal, + auto_renew: true, + renewal_price_usd: 10, + }); + // One impossible row poisons the whole JSON section: the builder + // returns null on ANY malformation so the caller falls back to + // the Markdown parse, mirroring the #2199 Markdown cases (#4835). + for (const bad of ["2027-02-30", "2026-13-01", "2026-00-10", "2026-04-31"]) { + const json = JSON.stringify({ domains: [row("good.example", "2027-01-15"), row("bad.example", bad)] }); + expect(dnsSectionFromRegisterJson(json, "2026-11-01T17:00:00Z", "t", mdEntries)).toBeNull(); + } + // Real dates still parse, including the leap date. + const ok = JSON.stringify({ domains: [row("leap.example", "2024-02-29"), row("real.example", "2027-01-15")] }); + const section = dnsSectionFromRegisterJson(ok, "2026-11-01T17:00:00Z", "t", mdEntries); + expect(section?.entries.map((e) => e.domain)).toEqual(["leap.example", "real.example"]); + expect(section?.totalAnnualListUsd).toBe(20); + expect(isDnsSection(section)).toBe(true); + }); + + test("isDnsSection rejects impossible entry renewal dates (#4858)", () => { + const good = dnsSectionFromRegister(REGISTER_MD, "2026-10-25T00:00:00Z", "test"); + expect(good).not.toBeNull(); + expect(isDnsSection(good)).toBe(true); + const withRenewal = (renewal: unknown) => ({ + ...good, + entries: good!.entries.map((e, i) => (i === 0 ? { ...e, renewal } : e)), + }); + for (const bad of ["2027-02-30", "2026-13-01", "2026-00-10", "2026-04-31", "soon", 20270209, undefined]) { + expect(isDnsSection(withRenewal(bad))).toBe(false); + } + expect(isDnsSection(withRenewal("2024-02-29"))).toBe(true); + expect(isDnsSection(withRenewal("2027-01-15"))).toBe(true); + }); + test("isDnsSection owns the finite-number + status rules (#2412)", () => { const good = dnsSectionFromRegister(REGISTER_MD, "2026-10-25T00:00:00Z", "test"); expect(good).not.toBeNull();