diff --git a/pm-stack/aggregator/src/feed.ts b/pm-stack/aggregator/src/feed.ts index 59d35c06fb..fcda1862be 100644 --- a/pm-stack/aggregator/src/feed.ts +++ b/pm-stack/aggregator/src/feed.ts @@ -625,11 +625,13 @@ export interface SubscriptionSanitization { /** One subscription row safe to hand to the renderers (#2446): the * strip maps esc(s.name)/esc(s.plan) and reads renewsAt unguarded, so * a null row or a non-string field 500s /quota and is served verbatim - * by /api/quota.json. */ + * by /api/quota.json. renewsAt must be null or a real ISO calendar + * date (#3513): invalid strings survive sanitization otherwise and + * render verbatim as renewal dates. */ export function isSubscriptionRow(v: unknown): v is { name: string; plan: string; renewsAt: string | null } { if (!isRecord(v)) return false; return ( - typeof v.name === "string" && typeof v.plan === "string" && (typeof v.renewsAt === "string" || v.renewsAt === null) + typeof v.name === "string" && typeof v.plan === "string" && (v.renewsAt === null || isIsoDate(v.renewsAt)) ); } diff --git a/pm-stack/aggregator/test/feed.test.ts b/pm-stack/aggregator/test/feed.test.ts index 60931a4a71..fb5cc3f20c 100644 --- a/pm-stack/aggregator/test/feed.test.ts +++ b/pm-stack/aggregator/test/feed.test.ts @@ -430,6 +430,21 @@ describe("feed subscriptions sanitization (#2446)", () => { expect(out.dropped).toBe(1); }); + test("invalid renewsAt strings drop; ISO dates and null survive (#3513)", async () => { + const bad = (renewsAt: string) => ({ name: "Bad", plan: "p", renewsAt }); + const out = sanitizeSubscriptions([ + SUB, + SUB_NULL_RENEW, + bad("banana"), + bad("2026-02-30"), + bad("2026-13-01"), + bad("12/01/2026"), + bad("2026-12-01banana"), + ]); + expect(out.rows).toEqual([SUB, SUB_NULL_RENEW]); + expect(out.dropped).toBe(5); + }); + test("a mixed valid/invalid array through loadFeed keeps only renderer-safe rows", async () => { const loaded = await loadWithSubs([SUB, null, "junk", { name: "Ok", plan: 7, renewsAt: null }, SUB_NULL_RENEW]); expect(loaded?.subscriptions).toEqual([SUB, SUB_NULL_RENEW]);