Skip to content

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

TypeScript

fix(ui): block remote preview images and cover guardrail routes

M8f566910ecf9
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 207197ff2..20844f82c 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -8168,7 +8168,7 @@ td.cu-registry-description {
panel, so this edit flow keeps its margins inside the panel like its
siblings instead of sitting flush against the panel edges. */
.cu-channel-edit-form {
- padding: 1.9rem 2.35rem 1.1rem;
+ padding: var(--cu-space-7) var(--cu-space-7) var(--cu-space-4);
}
.cu-channel-edit-form .cu-create-actions {
diff --git a/control-ui/app/guardrails/[name]/__tests__/page.test.tsx b/control-ui/app/guardrails/[name]/__tests__/page.test.tsx
new file mode 100644
index 000000000..e9ababe15
--- /dev/null
+++ b/control-ui/app/guardrails/[name]/__tests__/page.test.tsx
@@ -0,0 +1,119 @@
+import type { ReactNode } from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import GuardrailTabPage from '../[tab]/page'
+import GuardrailDetailPage from '../page'
+
+const navigation = vi.hoisted(() => ({
+ params: { name: 'sample-hook', tab: 'details' as string | undefined },
+ push: vi.fn(),
+ notFound: vi.fn(() => {
+ throw new Error('NOT_FOUND')
+ }),
+}))
+const api = vi.hoisted(() => ({
+ getLlmHook: vi.fn(),
+ getHosts: vi.fn(),
+}))
+
+vi.mock('next/navigation', () => ({
+ useParams: () => navigation.params,
+ useRouter: () => ({ push: navigation.push }),
+ notFound: navigation.notFound,
+}))
+vi.mock('@lib/api', () => ({
+ getLlmHook: api.getLlmHook,
+ getHosts: api.getHosts,
+ deleteLlmHook: vi.fn(),
+ isSilentApiError: () => false,
+}))
+vi.mock('@components/ConfirmDialog', () => ({
+ useConfirmDialog: () => ({ confirm: vi.fn(), confirmDialog: null }),
+}))
+vi.mock('@components/Toast', () => ({ useToast: () => ({ showToast: vi.fn() }) }))
+vi.mock('@components/DetailPageShell', () => ({
+ DetailPageShell: ({
+ activeTab,
+ children,
+ tabs,
+ }: {
+ activeTab: string
+ children: ReactNode
+ tabs: Array<{ href: string; label: string; value: string }>
+ }) => (
+ <main>
+ <nav aria-label="Guardrail detail sections">
+ {tabs.map(tab => (
+ <a
+ key={tab.value}
+ aria-current={tab.value === activeTab ? 'page' : undefined}
+ href={tab.href}
+ >
+ {tab.label}
+ </a>
+ ))}
+ </nav>
+ {children}
+ </main>
+ ),
+}))
+
+beforeEach(() => {
+ vi.clearAllMocks()
+ navigation.params.tab = 'details'
+ api.getLlmHook.mockResolvedValue({
+ metadata: { name: 'sample-hook' },
+ spec: { path: '/check', lifecyclePoints: ['preCall'] },
+ status: { conditions: [{ type: 'Ready', status: 'True' }] },
+ })
+ api.getHosts.mockResolvedValue({
+ items: [
+ {
+ metadata: { name: 'sample-agent' },
+ spec: { guardrails: { hooks: { preCall: [{ id: 'sample-hook' }] } } },
+ },
+ ],
+ })
+})
+afterEach(cleanup)
+
+describe('guardrail detail routes', () => {
+ it.each(['details', 'agents'])('opens the %s tab directly', async tab => {
+ navigation.params.tab = tab
+ const page = await GuardrailTabPage({ params: Promise.resolve({ tab }) })
+ render(page)
+
+ expect(
+ await screen.findByText(
+ tab === 'details' ? 'Runtime configuration reported by the installed hook.' : 'sample-agent'
+ )
+ ).toBeInTheDocument()
+ expect(
+ screen.getByRole('link', { name: tab === 'details' ? 'Details' : 'Agents with access' })
+ ).toHaveAttribute('aria-current', 'page')
+ expect(screen.getByRole('link', { name: 'Agents with access' })).toHaveAttribute(
+ 'href',
+ '/guardrails/sample-hook/agents'
+ )
+ })
+
+ it('rejects unknown tab routes', async () => {
+ await expect(GuardrailTabPage({ params: Promise.resolve({ tab: 'unknown' }) })).rejects.toThrow(
+ 'NOT_FOUND'
+ )
+ expect(navigation.notFound).toHaveBeenCalledOnce()
+ })
+
+ it('opens the agent guardrails route by keyboard', async () => {
+ navigation.params.tab = 'agents'
+ render(<GuardrailDetailPage />)
+ const agent = await screen.findByRole('link', { name: 'Open agent sample-agent guardrails' })
+ fireEvent.keyDown(agent, { key: 'Enter' })
+ await waitFor(() =>
+ expect(navigation.push).toHaveBeenCalledWith('/agents/sample-agent/guardrails')
+ )
+ navigation.push.mockClear()
+ fireEvent.keyDown(agent, { key: ' ' })
+ expect(navigation.push).toHaveBeenCalledWith('/agents/sample-agent/guardrails')
+ })
+})
diff --git a/control-ui/components/GfsMarkdownPreview/index.tsx b/control-ui/components/GfsMarkdownPreview/index.tsx
index d55fc4419..96b6e8b12 100644
--- a/control-ui/components/GfsMarkdownPreview/index.tsx
+++ b/control-ui/components/GfsMarkdownPreview/index.tsx
@@ -7,7 +7,7 @@
// focusable scrollable table region (here through the shared
// TableViewport/DataTable primitives), which `MDEditor.Markdown` cannot
// preserve without regressing that behavior. Guarantees: no rehype-raw, so raw
-// HTML stays inert; urlTransform restricts `src` to https:/data:image URIs and
+// HTML stays inert; urlTransform restricts `src` to inline data:image URIs and
// link hrefs to http(s):/mailto:/# fragments; code blocks render as plain
// `pre` > `code`. Covered by components/__tests__/GfsMarkdownPreview.test.tsx.
import { useEffect, useId, useRef, useState } from 'react'
@@ -27,7 +27,7 @@ import type { GfsMarkdownPreviewProps } from './types'
function transformMarkdownUrl(url: string, key: string): string {
const value = url.trim()
if (key === 'src') {
- return /^(?:https:\/\/|data:image\/(?:png|gif|jpe?g|webp);base64,)/i.test(value) ? value : ''
+ return /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(value) ? value : ''
}
return /^(?:https?:\/\/|mailto:|#)/i.test(value) ? value : ''
}
diff --git a/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx b/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx
index b4a94a07e..a1cbac668 100644
--- a/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx
+++ b/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx
@@ -70,10 +70,8 @@ describe('GfsMarkdownPreview', () => {
)
expect(within(article).getByRole('heading', { name: 'Inventory' })).toBeInTheDocument()
expect(within(article).getByRole('checkbox')).toBeDisabled()
- expect(within(article).getByRole('img', { name: 'Trend chart' })).toHaveAttribute(
- 'referrerpolicy',
- 'no-referrer'
- )
+ expect(within(article).queryByRole('img', { name: 'Trend chart' })).toBeNull()
+ expect(article).toHaveTextContent('Trend chart')
expect(within(article).getByRole('link', { name: 'Documentation' })).toHaveAttribute(
'target',
'_blank'
@@ -94,4 +92,20 @@ describe('GfsMarkdownPreview', () => {
expect(article).toHaveTextContent('Broken')
expect(article).toHaveTextContent('not a separator')
})
+
+ it('renders inline raster images without allowing remote image requests', async () => {
+ renderMarkdownPreview(
+ '![Inline](data:image/png;base64,aGVsbG8=) ![Remote](https://example.com/private.png)'
+ )
+
+ const article = await screen.findByRole('article', {
+ name: 'Markdown preview of inventory.md',
+ })
+ expect(within(article).getByRole('img', { name: 'Inline' })).toHaveAttribute(
+ 'src',
+ 'data:image/png;base64,aGVsbG8='
+ )
+ expect(within(article).queryByRole('img', { name: 'Remote' })).toBeNull()
+ expect(article).toHaveTextContent('Remote')
+ })
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 1b2699b63..064217612 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.656",
+ "version": "0.1.657",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.656",
+ "version": "0.1.657",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index 1cc1b65f7..9b3807f93 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.656",
+ "version": "0.1.657",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/desktop-app/ui/src/components/GfsMarkdownPreview/Body.tsx b/desktop-app/ui/src/components/GfsMarkdownPreview/Body.tsx
index 785f4bfb9..fb13b8d20 100644
--- a/desktop-app/ui/src/components/GfsMarkdownPreview/Body.tsx
+++ b/desktop-app/ui/src/components/GfsMarkdownPreview/Body.tsx
@@ -4,7 +4,7 @@
// because the preview must render GFM tables inside a labelled, keyboard-
// focusable scrollable table region, which `MDEditor.Markdown` cannot preserve
// without regressing that behavior. Guarantees: no rehype-raw, so raw HTML
-// stays inert; urlTransform restricts `src` to https:/data:image URIs and link
+// stays inert; urlTransform restricts `src` to inline data:image URIs and link
// hrefs to http(s):/mailto:/# fragments; code blocks render as plain `pre` >
// `code`. Covered by the GfsMarkdownPreview and GfsMarkdownPreviewBody suites.
import { useEffect, useId, useRef, useState } from 'react'
@@ -25,7 +25,7 @@ function isPlainTextName(fileName: string): boolean {
function transformMarkdownUrl(url: string, key: string): string {
const value = url.trim()
if (key === 'src') {
- return /^(?:https:\/\/|data:image\/(?:png|gif|jpe?g|webp);base64,)/i.test(value) ? value : ''
+ return /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(value) ? value : ''
}
return /^(?:https?:\/\/|mailto:|#)/i.test(value) ? value : ''
}
diff --git a/desktop-app/ui/src/components/GfsMarkdownPreview/GfsMarkdownPreviewBody.gfm.test.tsx b/desktop-app/ui/src/components/GfsMarkdownPreview/GfsMarkdownPreviewBody.gfm.test.tsx
index 7b2ef77b1..7f40513c7 100644
--- a/desktop-app/ui/src/components/GfsMarkdownPreview/GfsMarkdownPreviewBody.gfm.test.tsx
+++ b/desktop-app/ui/src/components/GfsMarkdownPreview/GfsMarkdownPreviewBody.gfm.test.tsx
@@ -61,9 +61,8 @@ describe('GfsMarkdownPreviewBody GFM rendering', () => {
expect(within(article).getByRole('heading', { name: 'Inventory', level: 1 })).toBeTruthy()
expect((within(article).getByRole('checkbox') as HTMLInputElement).disabled).toBe(true)
expect(within(article).getByText('outdated').tagName).toBe('DEL')
- expect(
- within(article).getByRole('img', { name: 'Trend chart' }).getAttribute('referrerpolicy')
- ).toBe('no-referrer')
+ expect(within(article).queryByRole('img', { name: 'Trend chart' })).toBeNull()
+ expect(article.textContent).toContain('Trend chart')
expect(
within(article).getByRole('link', { name: 'Documentation' }).getAttribute('target')
).toBe('_blank')
@@ -91,4 +90,25 @@ describe('GfsMarkdownPreviewBody GFM rendering', () => {
expect(article.textContent).toContain('not a separator')
expect(container.querySelector('script')).toBeNull()
})
+
+ it('renders inline raster images without allowing remote image requests', async () => {
+ const markdown =
+ '![Inline](data:image/png;base64,aGVsbG8=) ![Remote](https://example.com/private.png)'
+ stubDownload(markdown)
+
+ render(
+ <GfsMarkdownPreviewBody
+ byteLength={new TextEncoder().encode(markdown).byteLength}
+ fileName="inline.md"
+ gfsUri="gfs://main/inline"
+ />
+ )
+
+ const article = await screen.findByRole('article', { name: 'Markdown preview of inline.md' })
+ expect(within(article).getByRole('img', { name: 'Inline' }).getAttribute('src')).toBe(
+ 'data:image/png;base64,aGVsbG8='
+ )
+ expect(within(article).queryByRole('img', { name: 'Remote' })).toBeNull()
+ expect(article.textContent).toContain('Remote')
+ })
})
diff --git a/docs/agents/frontend-style-rules.md b/docs/agents/frontend-style-rules.md
index bb4531ef0..28df7cbd8 100644
--- a/docs/agents/frontend-style-rules.md
+++ b/docs/agents/frontend-style-rules.md
@@ -72,7 +72,7 @@ GFS Markdown/text file previews with ReactMarkdown + remark-gfm instead of
tables inside a labelled, keyboard-focusable scrollable table region, which
`MDEditor.Markdown` cannot preserve without regressing that behavior.
Guarantees: no rehype-raw, so raw HTML stays inert; `urlTransform` restricts
-image `src` to `https:`/inline `data:image` URIs and link hrefs to
+image `src` to inline `data:image` URIs and link hrefs to
`http(s):`/`mailto:`/`#` fragments; code blocks render as plain `pre` > `code`.
The behavior is covered by the GfsMarkdownPreview test suites in both
applications. This exception is scoped to these preview components only.