@flamingo-stack/openframe-frontend-core 0.0.200 → 0.0.201-snapshot.20260521220457

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 (70) hide show
  1. package/dist/{chunk-V2FNIPZJ.cjs → chunk-3B43AHYE.cjs} +2 -2
  2. package/dist/{chunk-TMD44IKJ.js.map → chunk-3B43AHYE.cjs.map} +1 -1
  3. package/dist/{chunk-TMD44IKJ.js → chunk-55HF462A.js} +2 -2
  4. package/dist/chunk-55HF462A.js.map +1 -0
  5. package/dist/{chunk-ZOM75JOY.js → chunk-IDULPYOU.js} +4458 -4245
  6. package/dist/chunk-IDULPYOU.js.map +1 -0
  7. package/dist/{chunk-C3M6R6JH.cjs → chunk-JIKTMXTZ.cjs} +1277 -1064
  8. package/dist/chunk-JIKTMXTZ.cjs.map +1 -0
  9. package/dist/components/chat/approval-request-message.d.ts.map +1 -1
  10. package/dist/components/chat/chat-container.d.ts.map +1 -1
  11. package/dist/components/chat/chat-message-enhanced.d.ts.map +1 -1
  12. package/dist/components/chat/chat-message-list.d.ts.map +1 -1
  13. package/dist/components/chat/types/message.types.d.ts +34 -0
  14. package/dist/components/chat/types/message.types.d.ts.map +1 -1
  15. package/dist/components/features/index.cjs +13 -3
  16. package/dist/components/features/index.cjs.map +1 -1
  17. package/dist/components/features/index.d.ts +1 -1
  18. package/dist/components/features/index.d.ts.map +1 -1
  19. package/dist/components/features/index.js +16 -6
  20. package/dist/components/index.cjs +15 -3
  21. package/dist/components/index.cjs.map +1 -1
  22. package/dist/components/index.js +16 -4
  23. package/dist/components/layout/title-block.d.ts.map +1 -1
  24. package/dist/components/navigation/index.cjs +3 -3
  25. package/dist/components/navigation/index.js +2 -2
  26. package/dist/components/providers/theme-provider.d.ts +69 -0
  27. package/dist/components/providers/theme-provider.d.ts.map +1 -0
  28. package/dist/components/ui/entity-image.d.ts +9 -0
  29. package/dist/components/ui/entity-image.d.ts.map +1 -0
  30. package/dist/components/ui/file-manager/index.cjs +50 -50
  31. package/dist/components/ui/file-manager/index.js +1 -1
  32. package/dist/components/ui/index.cjs +5 -3
  33. package/dist/components/ui/index.cjs.map +1 -1
  34. package/dist/components/ui/index.d.ts +1 -0
  35. package/dist/components/ui/index.d.ts.map +1 -1
  36. package/dist/components/ui/index.js +4 -2
  37. package/dist/components/ui/organization-card.d.ts.map +1 -1
  38. package/dist/components/ui/simple-markdown-renderer.d.ts.map +1 -1
  39. package/dist/index.cjs +15 -3
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.js +16 -4
  42. package/package.json +2 -1
  43. package/src/components/chat/approval-request-message.tsx +106 -92
  44. package/src/components/chat/chat-container.tsx +8 -4
  45. package/src/components/chat/chat-message-enhanced.tsx +51 -9
  46. package/src/components/chat/chat-message-list.tsx +27 -19
  47. package/src/components/chat/types/message.types.ts +35 -0
  48. package/src/components/features/index.ts +15 -1
  49. package/src/components/layout/title-block.tsx +6 -30
  50. package/src/components/providers/theme-provider.tsx +130 -0
  51. package/src/components/ui/button/button.tsx +1 -1
  52. package/src/components/ui/checkbox-block.tsx +13 -13
  53. package/src/components/ui/entity-image.tsx +56 -0
  54. package/src/components/ui/index.ts +1 -0
  55. package/src/components/ui/organization-card.tsx +4 -8
  56. package/src/components/ui/simple-markdown-renderer.tsx +248 -2
  57. package/src/stories/CheckboxBlock.stories.tsx +1 -3
  58. package/src/stories/OrganizationCard.stories.tsx +14 -0
  59. package/src/stories/Theme.stories.tsx +350 -0
  60. package/src/styles/README.md +271 -174
  61. package/src/styles/dark_theme.tokens.json +982 -0
  62. package/src/styles/light_theme.tokens.json +982 -0
  63. package/src/styles/ods-colors.css +225 -146
  64. package/src/styles/ods_color_tokens.json +1 -300
  65. package/dist/chunk-C3M6R6JH.cjs.map +0 -1
  66. package/dist/chunk-V2FNIPZJ.cjs.map +0 -1
  67. package/dist/chunk-ZOM75JOY.js.map +0 -1
  68. package/dist/components/features/organization-icon.d.ts +0 -80
  69. package/dist/components/features/organization-icon.d.ts.map +0 -1
  70. package/src/components/features/organization-icon.tsx +0 -175
@@ -0,0 +1,130 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ ThemeProvider as NextThemesProvider,
6
+ useTheme as useNextTheme,
7
+ } from "next-themes";
8
+ import type { ThemeProviderProps as NextThemesProviderProps } from "next-themes/dist/types";
9
+
10
+ /**
11
+ * ODS theme system — thin wrapper over `next-themes`.
12
+ *
13
+ * We deliberately do NOT hand-roll a provider/no-flash script: `next-themes`
14
+ * is already a dependency, is battle-tested in Next.js (App & Pages router),
15
+ * injects its own pre-paint anti-flash script, handles SSR + localStorage +
16
+ * cross-tab sync, and also works in plain React (Vite/Tauri).
17
+ *
18
+ * Product model (locked): a MANUAL light/dark switch, default DARK,
19
+ * persisted to localStorage. No "system" mode (`enableSystem={false}`).
20
+ *
21
+ * Drives styling by setting `data-theme="light|dark"` on <html>;
22
+ * `src/styles/ods-colors.css` swaps the `--ods-*` primitives accordingly.
23
+ *
24
+ * Public API exposed by this module:
25
+ * • `<ThemeProvider>` — preconfigured next-themes provider.
26
+ * • `useTheme()` — raw next-themes hook (advanced cases).
27
+ * • `useThemeToggle()`— headless convenience hook for building toggle UI
28
+ * in consumer apps (no styled component on purpose;
29
+ * apps own their button visuals via the lib's
30
+ * existing `<Button>`).
31
+ */
32
+
33
+ export type Theme = "light" | "dark";
34
+
35
+ export const THEME_STORAGE_KEY = "ods-theme";
36
+ export const THEME_ATTRIBUTE = "data-theme";
37
+ export const DEFAULT_THEME: Theme = "dark";
38
+
39
+ export type ThemeProviderProps = Partial<NextThemesProviderProps>;
40
+
41
+ /**
42
+ * Pre-configured provider. Wrap the app once (Next.js: in the root layout;
43
+ * apps must keep `suppressHydrationWarning` on <html> — already the case).
44
+ * No `<ThemeScript>` needed — next-themes handles the no-flash script.
45
+ *
46
+ * All next-themes props are overridable, but the ODS defaults below encode
47
+ * the product decision.
48
+ */
49
+ export function ThemeProvider({ children, ...overrides }: ThemeProviderProps) {
50
+ return (
51
+ <NextThemesProvider
52
+ attribute={THEME_ATTRIBUTE}
53
+ defaultTheme={DEFAULT_THEME}
54
+ enableSystem={false}
55
+ themes={["light", "dark"]}
56
+ storageKey={THEME_STORAGE_KEY}
57
+ disableTransitionOnChange={false}
58
+ {...overrides}
59
+ >
60
+ {children}
61
+ </NextThemesProvider>
62
+ );
63
+ }
64
+
65
+ /**
66
+ * Re-export of next-themes' `useTheme` (no custom logic on top).
67
+ * Returns `{ theme, setTheme, resolvedTheme, themes, ... }`.
68
+ */
69
+ export const useTheme = useNextTheme;
70
+
71
+ /* ------------------------------------------------------------------ */
72
+ /* useThemeToggle — headless convenience for building toggle UIs */
73
+ /* ------------------------------------------------------------------ */
74
+
75
+ export interface UseThemeToggleResult {
76
+ /** Becomes `true` after the client has hydrated and resolved the stored
77
+ * preference. Until then, `theme`/`isDark`/`isLight` reflect the SSR
78
+ * default (`DEFAULT_THEME`) — handy for rendering a stable placeholder. */
79
+ mounted: boolean;
80
+ /** Resolved active theme (`"dark"` until mounted, then real value). */
81
+ theme: Theme;
82
+ isDark: boolean;
83
+ isLight: boolean;
84
+ /** Flip dark↔light and persist. */
85
+ toggle: () => void;
86
+ /** Set explicitly to `"light"` or `"dark"` and persist. */
87
+ setTheme: (theme: Theme) => void;
88
+ }
89
+
90
+ /**
91
+ * Headless toggle helper. Build any button you like:
92
+ *
93
+ * const { isDark, toggle, mounted } = useThemeToggle()
94
+ * <Button size="icon" variant="transparent" onClick={toggle} aria-label="…">
95
+ * {mounted && (isDark ? <Sun01Icon /> : <MoonIcon />)}
96
+ * </Button>
97
+ *
98
+ * The mount gate avoids hydration mismatch (next-themes only knows the
99
+ * persisted preference on the client after mount).
100
+ */
101
+ export function useThemeToggle(): UseThemeToggleResult {
102
+ const { resolvedTheme, theme, setTheme } = useTheme();
103
+ const [mounted, setMounted] = React.useState(false);
104
+ React.useEffect(() => setMounted(true), []);
105
+
106
+ const active: Theme = mounted
107
+ ? resolvedTheme === "light" || theme === "light"
108
+ ? "light"
109
+ : "dark"
110
+ : DEFAULT_THEME;
111
+
112
+ const setOdsTheme = React.useCallback(
113
+ (next: Theme) => setTheme(next),
114
+ [setTheme],
115
+ );
116
+
117
+ const toggle = React.useCallback(
118
+ () => setTheme(active === "dark" ? "light" : "dark"),
119
+ [active, setTheme],
120
+ );
121
+
122
+ return {
123
+ mounted,
124
+ theme: active,
125
+ isDark: active === "dark",
126
+ isLight: active === "light",
127
+ toggle,
128
+ setTheme: setOdsTheme,
129
+ };
130
+ }
@@ -27,7 +27,7 @@ const buttonVariants = cva(
27
27
  destructive: buttonSurfaceClasses.destructive,
28
28
  },
29
29
  size: {
30
- default: "py-[var(--spacing-system-sf)] px-[var(--spacing-system-m)] text-h3 h-12",
30
+ default: "py-[var(--spacing-system-sf)] px-[var(--spacing-system-m)] text-h3 md:h-12 h-10",
31
31
  small: "p-[var(--spacing-system-xs)] text-h5 h-6 md:h-8",
32
32
  "small-legacy": "py-[var(--spacing-system-xs)] px-[var(--spacing-system-m)] h-10 text-[14px] font-bold", // Temporary alias for "small" to avoid breaking changes in AnnouncementBar's CTA button; will be removed in the future
33
33
  icon: "p-[var(--spacing-system-sf)] h-11 w-11 md:h-12 md:w-12 [&_svg]:h-4 [&_svg]:w-4 md:[&_svg]:h-6 md:[&_svg]:w-6",
@@ -28,14 +28,15 @@ const CheckboxBlock = React.forwardRef<
28
28
  <label
29
29
  htmlFor={id}
30
30
  className={cn(
31
- "flex items-center gap-[var(--spacing-system-s)] rounded-[6px] border w-full",
31
+ "flex items-center gap-[var(--spacing-system-s)] rounded-md ring-1 ring-inset w-full",
32
32
  "p-[var(--spacing-system-sf)]",
33
- !description && "h-11 md:h-12",
34
- "bg-ods-card border-ods-border",
33
+ !description && "min-h-[44px] md:min-h-[48px]",
34
+ description && "min-h-[60px] md:min-h-[64px]",
35
+ "bg-ods-card ring-ods-border",
35
36
  "cursor-pointer transition-colors duration-200",
36
- "hover:border-ods-accent/30",
37
- disabled && "opacity-50 cursor-not-allowed hover:border-ods-border",
38
- error && "border-ods-error",
37
+ "hover:ring-ods-accent/30",
38
+ disabled && "opacity-50 cursor-not-allowed hover:ring-ods-border",
39
+ error && "ring-ods-error",
39
40
  )}
40
41
  >
41
42
  <CheckboxPrimitive.Root
@@ -46,7 +47,7 @@ const CheckboxBlock = React.forwardRef<
46
47
  onCheckedChange={onCheckedChange}
47
48
  disabled={disabled}
48
49
  className={cn(
49
- "h-6 w-6 shrink-0",
50
+ "h-4 w-4 md:h-6 md:w-6 shrink-0",
50
51
  "rounded-[6px] border-2",
51
52
  error ? "border-ods-error" : "border-[var(--color-border-strong)]",
52
53
  "bg-ods-card",
@@ -58,21 +59,20 @@ const CheckboxBlock = React.forwardRef<
58
59
  <CheckboxPrimitive.Indicator
59
60
  className="flex items-center justify-center text-ods-text-on-accent"
60
61
  >
61
- <CheckboxCheckmarkIcon size={10} />
62
+ <CheckboxCheckmarkIcon className="w-2 h-2 md:w-2.5 md:h-2.5" />
62
63
  </CheckboxPrimitive.Indicator>
63
64
  </CheckboxPrimitive.Root>
64
65
  <div className="flex flex-1 flex-col justify-center min-w-0">
65
66
  <span className={cn(
66
- "text-h4",
67
- "text-ods-text-primary select-none",
68
- !description && "truncate"
67
+ "text-h4 !leading-5 md:!leading-6",
68
+ "text-ods-text-primary select-none break-words"
69
69
  )}>
70
70
  {label}
71
71
  </span>
72
72
  {description && (
73
73
  <span className={cn(
74
- "text-h6",
75
- "text-ods-text-secondary select-none"
74
+ "text-h6 !leading-4",
75
+ "text-ods-text-secondary select-none break-words"
76
76
  )}>
77
77
  {description}
78
78
  </span>
@@ -0,0 +1,56 @@
1
+ 'use client'
2
+
3
+ import React from 'react'
4
+ import { cn } from '../../utils/cn'
5
+
6
+ function getInitials(name?: string): string {
7
+ if (!name) return ''
8
+ const words = name.trim().split(/\s+/)
9
+ if (words.length === 1) return words[0].charAt(0).toUpperCase()
10
+ return (words[0].charAt(0) + words[words.length - 1].charAt(0)).toUpperCase()
11
+ }
12
+
13
+ export interface EntityImageProps {
14
+ src?: string | null
15
+ alt?: string
16
+ /** Overrides the initials source. Defaults to `alt`. */
17
+ fallbackText?: string
18
+ className?: string
19
+ }
20
+
21
+ export function EntityImage({ src, alt, fallbackText, className }: EntityImageProps) {
22
+ const [imageFailed, setImageFailed] = React.useState(false)
23
+
24
+ React.useEffect(() => {
25
+ setImageFailed(false)
26
+ }, [src])
27
+
28
+ const showFallback = imageFailed || !src
29
+ const initials = getInitials(fallbackText ?? alt)
30
+
31
+ if (showFallback) {
32
+ return (
33
+ <div
34
+ aria-label={alt}
35
+ className={cn(
36
+ 'size-[52px] md:size-[60px] shrink-0 rounded-md border border-ods-border bg-ods-bg flex items-center justify-center text-ods-text-secondary text-h4 select-none',
37
+ className,
38
+ )}
39
+ >
40
+ {initials || '?'}
41
+ </div>
42
+ )
43
+ }
44
+
45
+ return (
46
+ <img
47
+ src={src ?? undefined}
48
+ alt={alt ?? ''}
49
+ onError={() => setImageFailed(true)}
50
+ className={cn(
51
+ 'size-[52px] md:size-[60px] shrink-0 rounded-md border border-ods-border object-cover',
52
+ className,
53
+ )}
54
+ />
55
+ )
56
+ }
@@ -72,6 +72,7 @@ export { CheckIcon, CheckCircleIcon as LucideCheckCircleIcon, XIcon as LucideXIc
72
72
  export * from './dashboard-info-card'
73
73
  export * from './device-card'
74
74
  export * from './device-card-compact'
75
+ export * from './entity-image'
75
76
  export * from './feature-card'
76
77
  export * from './feature-list'
77
78
  export { FloatingTooltip } from './floating-tooltip'
@@ -4,7 +4,7 @@ import React from "react"
4
4
  import Link from "next/link"
5
5
  import { Monitor } from "lucide-react"
6
6
  import { cn } from "../../utils/cn"
7
- import { OrganizationIcon } from "../features/organization-icon"
7
+ import { EntityImage } from "./entity-image"
8
8
 
9
9
  export interface Organization {
10
10
  id: string
@@ -98,13 +98,9 @@ export function OrganizationCard({
98
98
 
99
99
  {/* Header */}
100
100
  <div className="flex items-start gap-3 w-full">
101
- <OrganizationIcon
102
- imageUrl={fetchedImageUrl || organization.imageUrl}
103
- organizationName={organization.name}
104
- size="xl"
105
- backgroundStyle="dark"
106
- showBackground={true}
107
- className="w-[60px] h-[60px]"
101
+ <EntityImage
102
+ src={fetchedImageUrl || organization.imageUrl}
103
+ alt={organization.name}
108
104
  />
109
105
 
110
106
  <div className="flex-1 flex flex-col justify-center py-2 min-w-0">
@@ -7,10 +7,153 @@ import remarkGfm from 'remark-gfm';
7
7
  import remarkBreaks from 'remark-breaks';
8
8
  import rehypeHighlight from 'rehype-highlight';
9
9
  import rehypeRaw from 'rehype-raw';
10
+ import { visit } from 'unist-util-visit';
10
11
  import Image from 'next/image';
11
12
  import { AlertCircleIcon } from '../icons-v2-generated';
12
13
  import { cn } from '../../utils/cn';
13
14
 
15
+ // ---------------------------------------------------------------------------
16
+ // rehype HAST sanitizer — runs AFTER rehype-raw to strip XSS vectors
17
+ // ---------------------------------------------------------------------------
18
+ /**
19
+ * Minimal HAST sanitizer. Runs AFTER `rehype-raw` (which parses raw HTML
20
+ * embedded in markdown) and BEFORE `rehype-highlight`. Strips the
21
+ * attack surfaces that rehype-raw leaves wide open:
22
+ *
23
+ * - `on*` event handlers (onerror, onload, onclick, …) on ANY element
24
+ * - href / src / formaction / xlink:href / poster pointing at
25
+ * `javascript:` (case + whitespace tolerant)
26
+ * - `iframe srcdoc` (full-document XSS)
27
+ * - `<script>`, `<style>`, `<noscript>`, `<noembed>` elements (drop)
28
+ * - `data:` URIs on src-ish attrs (SVG-with-embedded-JS class of bug)
29
+ *
30
+ * Why custom (vs `rehype-sanitize`): the OSS-lib build environment
31
+ * doesn't have `rehype-sanitize` in its `node_modules` (sandbox
32
+ * restriction), but `unist-util-visit` is already a transitive dep of
33
+ * `rehype-raw`. This plugin is ~60 lines, ships nothing new, and is
34
+ * tighter than the default sanitize schema for our threat model
35
+ * (we want LLM-emitted markdown to be safe; we don't need full HTML5
36
+ * fidelity).
37
+ *
38
+ * The text-level `escapeUnknownHtmlTags` pre-pass below is still useful
39
+ * for catching `<their>`-style accidental tag emissions that React 19
40
+ * rejects, but it is NOT a security boundary. THIS is.
41
+ */
42
+ const EVENT_HANDLER_ATTR_RE = /^on[a-z]+$/i
43
+ const JAVASCRIPT_URL_RE = /^[\s\x00-\x1f]*javascript:/i
44
+ const DATA_URL_RE = /^[\s\x00-\x1f]*data:/i
45
+ const URL_ATTRS = new Set([
46
+ 'href',
47
+ 'src',
48
+ // `srcset` accepts `javascript:` on legacy browsers — same guard
49
+ // as the canonical hast-util-sanitize default schema's attr set.
50
+ // Multi-candidate scanning lives in `srcsetHasUnsafeCandidate` below;
51
+ // a single-URL check would miss a malicious second candidate like
52
+ // `"https://safe.png 1x, javascript:alert(1) 2x"`.
53
+ 'srcset',
54
+ 'formaction',
55
+ 'xlink:href',
56
+ 'poster',
57
+ 'data',
58
+ 'action',
59
+ 'background',
60
+ ])
61
+
62
+ /**
63
+ * Returns true if any candidate in an `srcset` attribute has a dangerous
64
+ * URL scheme. Per the HTML spec, srcset is a comma-separated list of
65
+ * candidates; each candidate is `<url> <descriptor>?` (e.g.
66
+ * `"https://x/a.png 2x"`). The single-URL `JAVASCRIPT_URL_RE.test(v)`
67
+ * check only inspects the FIRST candidate — so a malicious second
68
+ * candidate (`"https://safe 1x, javascript:alert(1) 2x"`) would slip
69
+ * through. This helper splits on `,`, trims each candidate, takes the
70
+ * leading whitespace-delimited token (the URL), and tests that.
71
+ *
72
+ * Splitting on every comma over-matches the rare-in-practice case of
73
+ * commas inside URL paths. That's the correct error bias for a
74
+ * sanitizer: over-strip is safe, under-strip is not.
75
+ */
76
+ function srcsetHasUnsafeCandidate(srcset: string): boolean {
77
+ for (const candidate of srcset.split(',')) {
78
+ const url = candidate.trim().split(/\s+/)[0] ?? ''
79
+ if (JAVASCRIPT_URL_RE.test(url) || DATA_URL_RE.test(url)) return true
80
+ }
81
+ return false
82
+ }
83
+ // Element-level drop list. The text-pre-pass `escapeUnknownHtmlTags`
84
+ // already escapes any `<tag>` whose name isn't on its allow-list, so
85
+ // `<object>`, `<embed>`, `<applet>`, `<base>`, `<meta>` normally never
86
+ // reach `rehype-raw` as elements. Re-stripping at the HAST layer
87
+ // removes the cross-layer dependency: this sanitizer is sufficient
88
+ // on its own even if the text pre-pass is bypassed.
89
+ const STRIP_ELEMENTS = new Set([
90
+ 'script',
91
+ 'style',
92
+ 'noscript',
93
+ 'noembed',
94
+ 'object',
95
+ 'embed',
96
+ 'applet',
97
+ 'base',
98
+ 'meta',
99
+ ])
100
+
101
+ function rehypeStripUnsafe() {
102
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
+ return (tree: any) => {
104
+ visit(tree, 'element', (node: any, index: number | undefined, parent: any) => {
105
+ const tag = String(node.tagName ?? '').toLowerCase()
106
+ if (STRIP_ELEMENTS.has(tag)) {
107
+ if (parent && typeof index === 'number') {
108
+ parent.children.splice(index, 1)
109
+ // Return the numeric index (`unist-util-visit` treats it as
110
+ // `[CONTINUE, index]`) so the walker resumes at the slot the
111
+ // removed node vacated. Don't return `[SKIP, index]`:
112
+ // skip-descendants is meaningless for a node we just removed,
113
+ // and SKIP+index conflates two signals.
114
+ return index
115
+ }
116
+ // Root-level strip element (parent undefined). Rare, but
117
+ // possible if `rehype-raw` ever lifts one. Neutralize in
118
+ // place by clearing children + retagging as a blank span.
119
+ node.children = []
120
+ node.tagName = 'span'
121
+ node.properties = {}
122
+ return
123
+ }
124
+ if (!node.properties || typeof node.properties !== 'object') return
125
+ for (const key of Object.keys(node.properties)) {
126
+ // 1. event handlers
127
+ if (EVENT_HANDLER_ATTR_RE.test(key)) {
128
+ delete node.properties[key]
129
+ continue
130
+ }
131
+ // 2. dangerous URL schemes on URL-bearing attrs. `srcset` is
132
+ // multi-candidate so it routes through `srcsetHasUnsafeCandidate`
133
+ // which inspects every URL in the list (not just the first).
134
+ if (URL_ATTRS.has(key.toLowerCase())) {
135
+ const raw = node.properties[key]
136
+ const v = Array.isArray(raw) ? raw[0] : raw
137
+ if (typeof v === 'string') {
138
+ const unsafe =
139
+ key.toLowerCase() === 'srcset'
140
+ ? srcsetHasUnsafeCandidate(v)
141
+ : JAVASCRIPT_URL_RE.test(v) || DATA_URL_RE.test(v)
142
+ if (unsafe) {
143
+ delete node.properties[key]
144
+ continue
145
+ }
146
+ }
147
+ }
148
+ // 3. iframe srcdoc — full-document XSS vector
149
+ if (tag === 'iframe' && key.toLowerCase() === 'srcdoc') {
150
+ delete node.properties[key]
151
+ }
152
+ }
153
+ })
154
+ }
155
+ }
156
+
14
157
  /**
15
158
  * URL transformer that extends react-markdown's default safe-protocol
16
159
  * allowlist with `card://` — the non-standard scheme `remarkCardLinks`
@@ -35,6 +178,90 @@ function cardAwareUrlTransform(url: string, key: string): string {
35
178
  return defaultUrlTransform(url);
36
179
  }
37
180
 
181
+ // ---------------------------------------------------------------------------
182
+ // LLM-output sanitizer — escape unknown HTML-style tags
183
+ // ---------------------------------------------------------------------------
184
+ /**
185
+ * Tags `rehype-raw` is allowed to forward to React as-is. Anything
186
+ * outside this set gets its angle brackets escaped so it renders as
187
+ * plain text rather than reaching React as an unrecognized custom
188
+ * element.
189
+ *
190
+ * Why this matters: chat output is LLM-generated markdown. An LLM that
191
+ * accidentally wraps a word in angle brackets ("share <their> settings")
192
+ * or echoes a system-prompt XML tag ("the <ticket> element above")
193
+ * makes `rehype-raw` mint a `<their>` / `<ticket>` JSX element. React
194
+ * 18 logs "tag is unrecognized in this browser" for every unknown tag;
195
+ * React 19 throws on tags with reserved kebab-case forms. We pre-escape
196
+ * to keep the renderer pristine without losing legitimate inline HTML
197
+ * (details/summary, video, iframe, kbd, mark, etc.).
198
+ *
199
+ * The allow-list mirrors HTML5 + the elements the chat shell wires
200
+ * component overrides for. Kept lower-case; matched case-insensitively.
201
+ */
202
+ const SAFE_HTML_TAGS = new Set([
203
+ // Block + inline text
204
+ 'a', 'abbr', 'address', 'article', 'aside', 'b', 'bdi', 'bdo', 'blockquote',
205
+ 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'dd', 'del',
206
+ 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'figcaption', 'figure', 'footer',
207
+ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'i', 'ins',
208
+ 'kbd', 'li', 'main', 'mark', 'nav', 'ol', 'p', 'pre', 'q', 'rp', 'rt',
209
+ 'ruby', 's', 'samp', 'section', 'small', 'span', 'strong', 'sub', 'summary',
210
+ 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', 'tr', 'u',
211
+ 'ul', 'var', 'wbr',
212
+ // Media
213
+ 'img', 'picture', 'source', 'audio', 'video', 'iframe', 'track',
214
+ // Forms (rehype-raw allows them; mostly harmless for chat output)
215
+ 'button', 'input', 'label', 'select', 'option', 'optgroup', 'textarea', 'form', 'fieldset', 'legend',
216
+ ])
217
+
218
+ /**
219
+ * Match an opening / closing HTML tag in markdown source. Captures:
220
+ * 1 — optional `/` for closing tags
221
+ * 2 — tag name (must start with a letter)
222
+ * 3 — everything between the name and the closing `>` (attrs etc.)
223
+ * 4 — optional `/` for void-element self-close
224
+ */
225
+ const TAG_LIKE_REGEX = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)([^>]*?)(\/?)>/g
226
+
227
+ function escapeUnknownHtmlTags(text: string): string {
228
+ if (!text || text.indexOf('<') === -1) return text
229
+ // Carve out fenced code blocks AND inline-backtick spans so we don't
230
+ // corrupt `<their>` examples that legitimately live inside code. The
231
+ // regex matches in priority order: triple-fence first (greediest),
232
+ // then inline single-backtick. Each protected span is preserved
233
+ // verbatim; everything between/around them runs through
234
+ // `escapeOutsideFences`.
235
+ const parts: string[] = []
236
+ let cursor = 0
237
+ // Triple-fence ``` … ``` OR single-backtick `…` (one line, no
238
+ // embedded newlines). Backtick group is non-greedy and forbids
239
+ // inner newlines per CommonMark inline-code semantics.
240
+ const PROTECTED_SPAN_RE = /```[\s\S]*?```|`[^`\n]+`/g
241
+ let span: RegExpExecArray | null
242
+ while ((span = PROTECTED_SPAN_RE.exec(text)) !== null) {
243
+ if (span.index > cursor) {
244
+ parts.push(escapeOutsideFences(text.slice(cursor, span.index)))
245
+ }
246
+ parts.push(span[0])
247
+ cursor = span.index + span[0].length
248
+ }
249
+ if (cursor < text.length) {
250
+ parts.push(escapeOutsideFences(text.slice(cursor)))
251
+ }
252
+ return parts.join('')
253
+ }
254
+
255
+ function escapeOutsideFences(segment: string): string {
256
+ return segment.replace(TAG_LIKE_REGEX, (match, slash, tag, rest, selfClose) => {
257
+ const lower = (tag as string).toLowerCase()
258
+ if (SAFE_HTML_TAGS.has(lower)) return match
259
+ // Unknown tag — escape so it renders as text instead of reaching
260
+ // React as a custom element.
261
+ return `&lt;${slash}${tag}${rest}${selfClose}&gt;`
262
+ })
263
+ }
264
+
38
265
  // ---------------------------------------------------------------------------
39
266
  // Mermaid styles (responsive)
40
267
  // ---------------------------------------------------------------------------
@@ -396,7 +623,19 @@ export const SimpleMarkdownRenderer: React.FC<SimpleMarkdownRendererProps> = ({
396
623
  }, [sectionIds, sectionIdMap]);
397
624
 
398
625
  // ---- preprocess ----
399
- const processedContent = preprocessContent ? preprocessContent(content) : content;
626
+ // Run the optional caller-supplied transform first, then defensively
627
+ // escape unknown HTML-style tags so an LLM that wrote `<their>` or
628
+ // accidentally echoed a system-prompt XML tag like `<ticket>` doesn't
629
+ // make `rehype-raw` hand React an unrecognized custom element (which
630
+ // logs a noisy "tag is unrecognized in this browser" warning AND can
631
+ // crash the SimpleMarkdownRenderer when the tag has a kebab-case
632
+ // form React rejects outright). Allow-listed tags pass through
633
+ // unchanged so legitimate inline HTML (details/summary, video,
634
+ // iframe, etc.) still renders.
635
+ const processedContent = useMemo(
636
+ () => escapeUnknownHtmlTags(preprocessContent ? preprocessContent(content) : content),
637
+ [preprocessContent, content],
638
+ );
400
639
 
401
640
  // ---- heading factory ----
402
641
  const makeHeading = useCallback(
@@ -499,7 +738,7 @@ export const SimpleMarkdownRenderer: React.FC<SimpleMarkdownRendererProps> = ({
499
738
  return (
500
739
  <span className="text-ods-accent cursor-not-allowed">
501
740
  {children}
502
- <sup className="ml-1 text-xs font-bold text-red-500">[BROKEN]</sup>
741
+ <sup className="ml-1 text-xs font-bold text-ods-attention-red-error">[BROKEN]</sup>
503
742
  </span>
504
743
  );
505
744
  }
@@ -617,7 +856,14 @@ export const SimpleMarkdownRenderer: React.FC<SimpleMarkdownRendererProps> = ({
617
856
  <ReactMarkdown
618
857
  remarkPlugins={[remarkGfm, remarkBreaks, ...(additionalRemarkPlugins ?? [])]}
619
858
  rehypePlugins={[
859
+ // ORDER MATTERS: rehype-raw parses the raw HTML embedded
860
+ // in the source markdown into HAST nodes; rehypeStripUnsafe
861
+ // then walks the HAST tree and drops XSS vectors (on*
862
+ // event handlers, javascript: URLs, script/style/iframe-srcdoc,
863
+ // data: URIs). Reversing the order would have nothing to
864
+ // sanitize (raw HTML would still be strings).
620
865
  rehypeRaw,
866
+ rehypeStripUnsafe,
621
867
  [rehypeHighlight, { detect: true, ignoreMissing: true }],
622
868
  ]}
623
869
  urlTransform={cardAwareUrlTransform}
@@ -186,9 +186,7 @@ export const FlamingoError: Story = {
186
186
  },
187
187
  decorators: [
188
188
  (Story) => (
189
- <div data-app-type="flamingo" style={{ width: '320px' }}>
190
- <Story />
191
- </div>
189
+ <Story />
192
190
  ),
193
191
  ],
194
192
  };
@@ -59,6 +59,20 @@ export const Default: Story = {
59
59
  },
60
60
  }
61
61
 
62
+ /**
63
+ * Card with an organization logo image.
64
+ */
65
+ export const WithImage: Story = {
66
+ args: {
67
+ organization: {
68
+ ...baseOrg,
69
+ imageUrl: 'https://picsum.photos/seed/acme/120/120',
70
+ },
71
+ href: '/organizations/details/1',
72
+ deviceCount: 142,
73
+ },
74
+ }
75
+
62
76
  /**
63
77
  * Card as a clickable link.
64
78
  */