From 9ac31de49f747f2d0c7f2abc0c0da296de98fe36 Mon Sep 17 00:00:00 2001 From: Padreug Date: Wed, 20 May 2026 01:24:01 +0200 Subject: [PATCH] fix(activities): reject malformed NIP-52 kind 31922 events at parse time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parseCalendarDateEvent accepted any non-empty `start` string, letting events with embedded times (e.g. "2026-05-25T10:00") through. Downstream parseIsoDate then split on "-" and produced an Invalid Date, crashing the renderer with "RangeError: Invalid time value". Validate `start` and `end` against YYYY-MM-DD at parse time so bad events are dropped before reaching the view — symmetric with how the time-event parser rejects unparseable timestamps. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/modules/activities/types/nip52.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/modules/activities/types/nip52.ts b/src/modules/activities/types/nip52.ts index 2a57a71..332d054 100644 --- a/src/modules/activities/types/nip52.ts +++ b/src/modules/activities/types/nip52.ts @@ -181,6 +181,14 @@ export function parseCalendarDateEvent(event: NostrEvent): CalendarDateEvent | n if (!dTag || !title || !start) return null + // NIP-52 kind 31922 requires YYYY-MM-DD. Reject anything else (including + // accidentally-published datetimes) so downstream parseIsoDate cannot + // produce an Invalid Date and crash the renderer. + const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/ + if (!ISO_DATE.test(start)) return null + const end = getTagValue(event.tags, 'end') + if (end && !ISO_DATE.test(end)) return null + const participants: Participant[] = event.tags .filter(t => t[0] === 'p') .map(t => ({ @@ -197,7 +205,7 @@ export function parseCalendarDateEvent(event: NostrEvent): CalendarDateEvent | n content: event.content, image: getTagValue(event.tags, 'image'), start, - end: getTagValue(event.tags, 'end'), + end, location: getTagValue(event.tags, 'location'), geohash: getTagValue(event.tags, 'g'), hashtags: getTagValues(event.tags, 't'),