Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pm-stack/aggregator/src/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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).
(() => {
Expand Down
40 changes: 40 additions & 0 deletions pm-stack/aggregator/test/slice3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down