File tree Expand file tree Collapse file tree
src/components/Calendar/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,10 +135,28 @@ const buildOutlookCalendarUrl = (eventData: CalendarEventData): string => {
135135 return `https://outlook.office.com/calendar/0/deeplink/compose?${ params . toString ( ) } `
136136}
137137
138+ const createCalendarUid = ( now : Date ) : string => {
139+ // Use Web Crypto instead of Math.random() to avoid insecure-randomness findings.
140+ const cryptoApi = globalThis . crypto
141+
142+ if ( cryptoApi && 'randomUUID' in cryptoApi && typeof cryptoApi . randomUUID === 'function' ) {
143+ return cryptoApi . randomUUID ( )
144+ }
145+
146+ if ( cryptoApi && 'getRandomValues' in cryptoApi && typeof cryptoApi . getRandomValues === 'function' ) {
147+ const bytes = new Uint8Array ( 16 )
148+ cryptoApi . getRandomValues ( bytes )
149+ return Array . from ( bytes , ( value ) => value . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' )
150+ }
151+
152+ // Extremely old/non-browser environment fallback: unique-enough without randomness.
153+ return `${ now . getTime ( ) } `
154+ }
155+
138156const buildIcsText = ( eventData : CalendarEventData ) : string => {
139157 const now = new Date ( )
140158 const dtStamp = formatUtcDateTimeForCalendar ( now )
141- const uid = ` ${ now . getTime ( ) } - ${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } `
159+ const uid = createCalendarUid ( now )
142160
143161 const start = parseIsoUtcDate ( eventData . startDate , eventData . startTime )
144162 const end = ( ( ) : Date => {
You can’t perform that action at this time.
0 commit comments