Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-ui): r4-b1 sanitize identity Markdown preview

Josuéb776e0cc898e
diff --git a/control-ui/components/MarkdownContent/index.tsx b/control-ui/components/MarkdownContent/index.tsx
index 923696caa..7c131fc4c 100644
--- a/control-ui/components/MarkdownContent/index.tsx
+++ b/control-ui/components/MarkdownContent/index.tsx
@@ -2,6 +2,7 @@
import React from 'react'
import dynamic from 'next/dynamic'
+import rehypeSanitize from 'rehype-sanitize'
import { cn } from '@lib/cn'
import { safeMarkdownHref } from '@lib/vanillaMarkdown'
@@ -73,6 +74,7 @@ export function MarkdownContent({
className={cn('cu-gfs-markdown-preview__content', className)}
components={components}
disableCopy
+ rehypePlugins={[rehypeSanitize]}
skipHtml
source={source}
urlTransform={url => safeMarkdownHref(url) ?? ''}
diff --git a/control-ui/components/__tests__/HostIdentityTab.test.tsx b/control-ui/components/__tests__/HostIdentityTab.test.tsx
index cd6346694..ff53b9848 100644
--- a/control-ui/components/__tests__/HostIdentityTab.test.tsx
+++ b/control-ui/components/__tests__/HostIdentityTab.test.tsx
@@ -84,6 +84,42 @@ describe('HostIdentityTab', () => {
expect(screen.getByText('[Image: Remote image]')).toBeInTheDocument()
})
+ it('does not render raw HTML as active content in identity documents', async () => {
+ vi.mocked(api.getHostPersonalization).mockResolvedValue({
+ ...initialFiles,
+ identity: [
+ '## Safe heading',
+ '<script>window.identityPreviewPwned = true</script>',
+ '<iframe src="https://example.invalid/frame" srcdoc="<script>parent.pwned=1</script>"></iframe>',
+ '<object data="https://example.invalid/object"></object>',
+ '<embed src="https://example.invalid/embed">',
+ '<style>@import url(https://example.invalid/style.css)</style>',
+ '<meta http-equiv="refresh" content="0;url=https://example.invalid">',
+ '<link rel="stylesheet" href="https://example.invalid/style.css">',
+ '<base href="https://example.invalid/">',
+ '<form action="https://example.invalid"><input name="x" onfocus="alert(1)"></form>',
+ '<div onclick="alert(1)" onmouseover="alert(2)">Harmless text</div>',
+ ].join('\n\n'),
+ })
+ renderTab()
+
+ await screen.findByRole('heading', { name: 'Safe heading' })
+ const document = screen.getByRole('article', { name: 'Rendered Identity document' })
+ expect(document).toHaveTextContent('Harmless text')
+ expect(
+ document.querySelectorAll(
+ 'script, iframe, object, embed, style, meta, link, base, form, input:not([disabled][type="checkbox"]), [onfocus], [onclick], [onmouseover]'
+ )
+ ).toHaveLength(0)
+ const sanitizedTaskListInput = document.querySelector('input')
+ if (sanitizedTaskListInput) {
+ expect(sanitizedTaskListInput).toBeDisabled()
+ expect(sanitizedTaskListInput).toHaveAttribute('type', 'checkbox')
+ expect(sanitizedTaskListInput).not.toHaveAttribute('onfocus')
+ expect(sanitizedTaskListInput?.getAttribute('name')).toBe('user-content-x')
+ }
+ })
+
it('renders GitHub-flavored Markdown tables in the read-only document view', async () => {
vi.mocked(api.getHostPersonalization).mockResolvedValue({
...initialFiles,
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index af235ada0..6c918a878 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.643",
+ "version": "0.1.644",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.643",
+ "version": "0.1.644",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
@@ -18,6 +18,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"recharts": "^3.8.1",
+ "rehype-sanitize": "6.0.0",
"yaml": "^2.8.3"
},
"devDependencies": {
@@ -43,11 +44,16 @@
"name": "@clerum/frontend-components",
"version": "0.1.0",
"devDependencies": {
+ "@testing-library/jest-dom": "^7.0.1",
+ "@testing-library/react": "^16.3.3",
+ "@testing-library/user-event": "^14.6.7",
"@types/react": "18.3.28",
"@types/react-dom": "18.3.7",
+ "jsdom": "^29.1.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
- "typescript": "^5.9.2"
+ "typescript": "^5.9.2",
+ "vitest": "^5.0.1"
},
"peerDependencies": {
"react": "^18.3.1",
@@ -2624,6 +2630,21 @@
"url": "https://github.com/inikulin/parse5?sponsor=1"
}
},
+ "node_modules/hast-util-sanitize": {
+ "version": "5.0.2",
+ "resolved": "https://registry.npmjs.org/hast-util-sanitize/-/hast-util-sanitize-5.0.2.tgz",
+ "integrity": "sha512-3yTWghByc50aGS7JlGhk61SPenfE/p1oaFeNwkOOyrscaOkMGrcW9+Cy/QAIOBpZxP1yqDIzFMR0+Np0i0+usg==",
+ "license": "MIT",
+ "dependencies": {
+ "@types/hast": "^3.0.0",
+ "@ungap/structured-clone": "^1.0.0",
+ "unist-util-position": "^5.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/unified"
+ }
+ },
"node_modules/hast-util-select": {
"version": "6.0.4",
"resolved": "https://registry.npmjs.org/hast-util-select/-/hast-util-select-6.0.4.tgz",
@@ -4734,6 +4755,20 @@
"url": "https://jaywcjlove.github.io/#/sponsor"
}
},
+ "node_modules/rehype-sanitize": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/rehype-sanitize/-/rehype-sanitize-6.0.0.tgz",
+ "integrity": "sha512-CsnhKNsyI8Tub6L4sm5ZFsme4puGfc6pYylvXo1AeqaGbjOYyzNv3qZPwvs0oMJ39eryyeOdmxwUIo94IpEhqg==",
+ "license": "MIT",
+ "dependencies": {
+ "@types/hast": "^3.0.0",
+ "hast-util-sanitize": "^5.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/unified"
+ }
+ },
"node_modules/rehype-slug": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/rehype-slug/-/rehype-slug-6.0.0.tgz",
diff --git a/control-ui/package.json b/control-ui/package.json
index 0552c340e..3723679a8 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.643",
+ "version": "0.1.644",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
@@ -72,6 +72,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"recharts": "^3.8.1",
+ "rehype-sanitize": "6.0.0",
"yaml": "^2.8.3"
},
"overrides": {
diff --git a/docs/agents/frontend-style-rules.md b/docs/agents/frontend-style-rules.md
index ae9092172..1cbafbfcc 100644
--- a/docs/agents/frontend-style-rules.md
+++ b/docs/agents/frontend-style-rules.md
@@ -38,12 +38,14 @@ application guidance that must be combined with this shared document.
Next.js surfaces that cannot server-render the editor/renderer must use the
established client-only dynamic import pattern. Do not copy framework
loading behavior into another application without checking its runtime.
-- Preserve Markdown semantics and the content's security boundary. Keep raw
- HTML disabled unless a reviewed, sanitized use case explicitly requires it;
- apply the owning app's safe URL policy to links and other URL-bearing nodes;
- and do not cause untrusted Markdown to fetch remote images or embed active
- content by default. Do not bypass these protections through custom renderers
- or URL transforms.
+- Preserve Markdown semantics and the content's security boundary. Treat
+ Markdown as untrusted input: if the selected library pipeline parses raw HTML,
+ sanitize the resulting syntax tree after raw-HTML parsing and before rendering.
+ A `skipHtml` prop is not sufficient unless the exact selected renderer is
+ verified to honor it. Apply the owning app's safe URL policy to links and
+ other URL-bearing nodes, and do not cause untrusted Markdown to fetch remote
+ images or embed active content by default. Do not bypass these protections
+ through custom renderers or URL transforms.
- Display-only output must retain semantic headings, lists, links, and other
supported document structure. Links and controls inside Markdown remain
independently operable; they must not be swallowed by a clickable/fake