Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🧼 fix: Render Agent Description HTML Safely (#15951)

Danny Avila942c9598c0e9
diff --git a/client/src/components/Agents/AgentCard.tsx b/client/src/components/Agents/AgentCard.tsx
index cdaa9f9d44..4dcfba924c 100644
--- a/client/src/components/Agents/AgentCard.tsx
+++ b/client/src/components/Agents/AgentCard.tsx
@@ -1,6 +1,7 @@
import React, { useMemo, useState } from 'react';
import { Label, OGDialog, OGDialogTrigger } from '@librechat/client';
import type t from 'librechat-data-provider';
+import Description, { getPlainDescription } from '~/components/ui/Description';
import { useLocalize, TranslationKeys, useAgentCategories } from '~/hooks';
import AgentDetailContent from './AgentDetailContent';
import { cn, renderAgentAvatar } from '~/utils';
@@ -19,6 +20,7 @@ const AgentCard: React.FC<AgentCardProps> = ({ agent, onSelect, className = '' }
const localize = useLocalize();
const { categories } = useAgentCategories();
const [isOpen, setIsOpen] = useState(false);
+ const description = useMemo(() => getPlainDescription(agent.description), [agent.description]);
const categoryLabel = useMemo(() => {
if (!agent.category) return '';
@@ -55,9 +57,9 @@ const AgentCard: React.FC<AgentCardProps> = ({ agent, onSelect, className = '' }
)}
aria-label={localize('com_agents_agent_card_label', {
name: agent.name,
- description: agent.description ?? '',
+ description,
})}
- aria-describedby={agent.description ? `agent-${agent.id}-description` : undefined}
+ aria-describedby={description ? `agent-${agent.id}-description` : undefined}
tabIndex={0}
role="button"
onKeyDown={(e) => {
@@ -89,16 +91,17 @@ const AgentCard: React.FC<AgentCardProps> = ({ agent, onSelect, className = '' }
</Label>
{/* Agent description */}
- {agent.description && (
- <p
+ {description && (
+ <Description
+ as="p"
id={`agent-${agent.id}-description`}
className="mt-0.5 line-clamp-2 text-sm leading-snug text-text-secondary md:line-clamp-5"
aria-label={localize('com_agents_description_card', {
- description: agent.description,
+ description,
})}
- >
- {agent.description}
- </p>
+ description={description}
+ plainText
+ />
)}
<AgentContact
diff --git a/client/src/components/Agents/AgentDetail.tsx b/client/src/components/Agents/AgentDetail.tsx
index b32a0c879b..1925a0d48e 100644
--- a/client/src/components/Agents/AgentDetail.tsx
+++ b/client/src/components/Agents/AgentDetail.tsx
@@ -21,6 +21,7 @@ import {
import type t from 'librechat-data-provider';
import { renderAgentAvatar, clearMessagesCache, specDisplayFieldReset } from '~/utils';
import { useLocalize, useDefaultConvo, useFavorites } from '~/hooks';
+import Description from '~/components/ui/Description';
import { useChatContext } from '~/Providers';
interface SupportContact {
@@ -168,9 +169,10 @@ const AgentDetail: React.FC<AgentDetailProps> = ({ agent, isOpen, onClose }) =>
)}
{/* Agent description */}
- <div className="mt-4 whitespace-pre-wrap px-6 text-center text-base text-text-primary">
- {agent?.description}
- </div>
+ <Description
+ description={agent?.description}
+ className="mt-4 whitespace-pre-wrap px-6 text-center text-base text-text-primary [&_a]:underline [&_a]:underline-offset-2 [&_img]:inline-block [&_img]:max-w-full"
+ />
{/* Action button */}
<div className="mb-4 mt-6 flex justify-center gap-2">
diff --git a/client/src/components/Agents/AgentDetailContent.tsx b/client/src/components/Agents/AgentDetailContent.tsx
index 0ea51d4504..35a527d689 100644
--- a/client/src/components/Agents/AgentDetailContent.tsx
+++ b/client/src/components/Agents/AgentDetailContent.tsx
@@ -20,6 +20,7 @@ import {
import type t from 'librechat-data-provider';
import { renderAgentAvatar, clearMessagesCache, specDisplayFieldReset } from '~/utils';
import { useLocalize, useDefaultConvo, useFavorites } from '~/hooks';
+import Description from '~/components/ui/Description';
import { useChatContext } from '~/Providers';
import AgentContact from './AgentContact';
@@ -121,9 +122,10 @@ const AgentDetailContent: React.FC<AgentDetailContentProps> = ({ agent }) => {
<AgentContact agent={agent} className="mt-1 justify-center text-center text-sm" />
{/* Agent description */}
- <div className="mt-4 whitespace-pre-wrap px-6 text-center text-base text-text-primary">
- {agent?.description}
- </div>
+ <Description
+ description={agent?.description}
+ className="mt-4 whitespace-pre-wrap px-6 text-center text-base text-text-primary [&_a]:underline [&_a]:underline-offset-2 [&_img]:inline-block [&_img]:max-w-full"
+ />
{/* Action button */}
<div className="mb-4 mt-6 flex justify-center gap-2">
diff --git a/client/src/components/Agents/tests/AgentCard.spec.tsx b/client/src/components/Agents/tests/AgentCard.spec.tsx
index 0906920515..d3c5131ff9 100644
--- a/client/src/components/Agents/tests/AgentCard.spec.tsx
+++ b/client/src/components/Agents/tests/AgentCard.spec.tsx
@@ -185,6 +185,27 @@ describe('AgentCard', () => {
expect(screen.getByText('A test agent for testing purposes')).toBeInTheDocument();
});
+ it('renders an HTML description as plain text in the card and accessible label', () => {
+ render(
+ <Wrapper>
+ <AgentCard
+ agent={{
+ ...mockAgent,
+ description:
+ '<span>Assistant for projects. <a href="https://example.com">Read the guide</a></span>',
+ }}
+ />
+ </Wrapper>,
+ );
+
+ expect(screen.getByText('Assistant for projects. Read the guide')).toBeInTheDocument();
+ expect(screen.queryByRole('link', { name: 'Read the guide' })).not.toBeInTheDocument();
+ expect(screen.getByRole('button')).toHaveAttribute(
+ 'aria-label',
+ 'Test Agent agent. Assistant for projects. Read the guide',
+ );
+ });
+
it('displays avatar when provided as object', () => {
render(
<Wrapper>
diff --git a/client/src/components/Agents/tests/AgentDetailContent.spec.tsx b/client/src/components/Agents/tests/AgentDetailContent.spec.tsx
index f6e638bec8..13e927c541 100644
--- a/client/src/components/Agents/tests/AgentDetailContent.spec.tsx
+++ b/client/src/components/Agents/tests/AgentDetailContent.spec.tsx
@@ -143,6 +143,25 @@ describe('AgentDetailContent', () => {
expect(screen.queryByText('Owner User')).not.toBeInTheDocument();
});
+ it('renders sanitized HTML descriptions with safe links', () => {
+ renderWithClient(
+ <AgentDetailContent
+ agent={{
+ ...baseAgent,
+ description:
+ '<span onclick="alert(1)">Assistant. <a href="https://example.com">Read the guide</a><script>alert(1)</script></span>',
+ }}
+ />,
+ );
+
+ const link = screen.getByRole('link', { name: 'Read the guide' });
+ expect(link).toHaveAttribute('href', 'https://example.com');
+ expect(link).toHaveAttribute('target', '_blank');
+ expect(link).toHaveAttribute('rel', 'noopener noreferrer');
+ expect(document.querySelector('[onclick]')).not.toBeInTheDocument();
+ expect(document.querySelector('script')).not.toBeInTheDocument();
+ });
+
it('falls back to owner contact when support contact is missing', () => {
renderWithClient(
<AgentDetailContent
diff --git a/client/src/components/Chat/Landing.tsx b/client/src/components/Chat/Landing.tsx
index 607332f23b..12ad6de5a2 100644
--- a/client/src/components/Chat/Landing.tsx
+++ b/client/src/components/Chat/Landing.tsx
@@ -4,16 +4,10 @@ import { HatGlasses } from 'lucide-react';
import { easings } from '@react-spring/web';
import { EModelEndpoint } from 'librechat-data-provider';
import { BirthdayIcon, TooltipAnchor, SplitText } from '@librechat/client';
-import {
- getIconEndpoint,
- getEntity,
- getModelSpec,
- createConfigHtmlSanitizer,
- CONFIG_HTML_MEDIA_TAGS,
- CONFIG_HTML_MEDIA_ATTR,
-} from '~/utils';
import { useChatContext, useAgentsMapContext, useAssistantsMapContext } from '~/Providers';
+import Description, { isHtmlDescription } from '~/components/ui/Description';
import { useGetEndpointsQuery, useGetStartupConfig } from '~/data-provider';
+import { getIconEndpoint, getEntity, getModelSpec } from '~/utils';
import { useLocalize, useAuthContext, useGreeting } from '~/hooks';
import AgentContact from '~/components/Agents/AgentContact';
import ConvoIcon from '~/components/Endpoints/ConvoIcon';
@@ -89,16 +83,7 @@ export default function Landing({ centerFormOnLanding }: { centerFormOnLanding:
const description = isTemporary
? localize('com_ui_temporary_description')
: ((entity?.description || brandedSpecDescription || conversation?.greeting) ?? '');
- const descriptionIsHTML = description.trim().startsWith('<');
-
- const sanitizeDescription = useMemo(
- () =>
- createConfigHtmlSanitizer({
- allowedTags: CONFIG_HTML_MEDIA_TAGS,
- allowedAttr: CONFIG_HTML_MEDIA_ATTR,
- }),
- [],
- );
+ const descriptionIsHTML = isHtmlDescription(description);
const selectedAgent =
isAgent && conversation?.agent_id != null ? agentsMap?.[conversation.agent_id] : undefined;
@@ -216,19 +201,15 @@ export default function Landing({ centerFormOnLanding }: { centerFormOnLanding:
/>
)}
</div>
- {description &&
- (descriptionIsHTML ? (
- <div
- className="animate-fadeIn mt-4 flex max-w-md items-center justify-center gap-2 text-center text-sm font-normal text-text-primary [&_img]:inline-block [&_img]:h-4 [&_img]:w-4"
- dangerouslySetInnerHTML={{ __html: sanitizeDescription(description) }}
- />
- ) : (
- <div
- className={`animate-fadeIn mt-4 max-w-md text-center text-sm font-normal ${isTemporary ? 'text-text-secondary' : 'text-text-primary'}`}
- >
- {description}
- </div>
- ))}
+ <Description
+ allowMedia
+ description={description}
+ className={
+ descriptionIsHTML
+ ? 'animate-fadeIn mt-4 flex max-w-md items-center justify-center gap-2 text-center text-sm font-normal text-text-primary [&_img]:inline-block [&_img]:h-4 [&_img]:w-4'
+ : `animate-fadeIn mt-4 max-w-md text-center text-sm font-normal ${isTemporary ? 'text-text-secondary' : 'text-text-primary'}`
+ }
+ />
{selectedAgent && !isTemporary && (
<AgentContact
agent={selectedAgent}
diff --git a/client/src/components/ui/Description.tsx b/client/src/components/ui/Description.tsx
new file mode 100644
index 0000000000..b16b9f9834
--- /dev/null
+++ b/client/src/components/ui/Description.tsx
@@ -0,0 +1,95 @@
+import { useMemo } from 'react';
+import type { ReactElement } from 'react';
+import {
+ CONFIG_HTML_LINK_ATTR,
+ CONFIG_HTML_MEDIA_ATTR,
+ CONFIG_HTML_MEDIA_TAGS,
+ CONFIG_HTML_RICH_TEXT_TAGS,
+ createConfigHtmlSanitizer,
+ createConfigHtmlTextSanitizer,
+} from '~/utils/configHtml';
+
+const sanitizeDescription = createConfigHtmlSanitizer({
+ allowedTags: CONFIG_HTML_RICH_TEXT_TAGS,
+ allowedAttr: CONFIG_HTML_LINK_ATTR,
+});
+const sanitizeMediaDescription = createConfigHtmlSanitizer({
+ allowedTags: CONFIG_HTML_MEDIA_TAGS,
+ allowedAttr: CONFIG_HTML_MEDIA_ATTR,
+});
+const sanitizeDescriptionText = createConfigHtmlTextSanitizer();
+const descriptionHtmlTags = new Set<string>([
+ ...CONFIG_HTML_RICH_TEXT_TAGS,
+ ...CONFIG_HTML_MEDIA_TAGS,
+]);
+
+export function isHtmlDescription(description?: string | null): boolean {
+ const firstTag = description?.trim().match(/^<\s*\/?\s*([a-z][a-z0-9]*)\b/i)?.[1];
+ return firstTag ? descriptionHtmlTags.has(firstTag.toLowerCase()) : false;
+}
+
+export function getPlainDescription(description?: string | null): string {
+ if (!description) {
+ return '';
+ }
+
+ if (!isHtmlDescription(description)) {
+ return description;
+ }
+
+ return sanitizeDescriptionText(description);
+}
+
+interface DescriptionProps {
+ as?: 'div' | 'p';
+ 'aria-label'?: string;
+ className?: string;
+ description?: string | null;
+ id?: string;
+ allowMedia?: boolean;
+ plainText?: boolean;
+}
+
+export default function Description({
+ as: Element = 'div',
+ className,
+ description,
+ id,
+ allowMedia = false,
+ plainText = false,
+ 'aria-label': ariaLabel,
+}: DescriptionProps): ReactElement | null {
+ const isHtml = isHtmlDescription(description);
+ const content = useMemo(() => {
+ if (!isHtml) {
+ return description ?? '';
+ }
+
+ if (plainText) {
+ return getPlainDescription(description);
+ }
+
+ return allowMedia ? sanitizeMediaDescription(description) : sanitizeDescription(description);
+ }, [allowMedia, description, isHtml, plainText]);
+
+ if (!description) {
+ return null;
+ }
+
+ if (plainText || !isHtml) {
+ return (
+ <Element id={id} className={className} aria-label={ariaLabel}>
+ {content}
+ </Element>
+ );
+ }
+
+ return (
+ <Element
+ id={id}
+ className={className}
+ aria-label={ariaLabel}
+ dangerouslySetInnerHTML={{ __html: content }}
+ />
+ );
+}
diff --git a/client/src/components/ui/__tests__/Description.spec.tsx b/client/src/components/ui/__tests__/Description.spec.tsx
new file mode 100644
index 0000000000..e958afc844
--- /dev/null
+++ b/client/src/components/ui/__tests__/Description.spec.tsx
@@ -0,0 +1,83 @@
+import React from 'react';
+import { render, screen } from '@testing-library/react';
+import '@testing-library/jest-dom';
+import Description, { getPlainDescription } from '../Description';
+
+describe('Description', () => {
+ it('renders supported HTML with normalized safe links', () => {
+ render(
+ <Description description={'<span>Read <a href="https://example.com">the guide</a></span>'} />,
+ );
+
+ const link = screen.getByRole('link', { name: 'the guide' });
+ expect(link).toHaveAttribute('href', 'https://example.com');
+ expect(link).toHaveAttribute('target', '_blank');
+ expect(link).toHaveAttribute('rel', 'noopener noreferrer');
+ });
+
+ it('preserves safe block boundaries in rich descriptions', () => {
+ const { container } = render(
+ <Description description="<p>First</p><div>Second</div><ul><li>Third</li></ul>" />,
+ );
+
+ expect(container.querySelector('p')).toHaveTextContent('First');
+ expect(container.querySelector('div > div')).toHaveTextContent('Second');
+ expect(container.querySelector('li')).toHaveTextContent('Third');
+ });
+
+ it('removes executable markup and unsafe URLs', () => {
+ const { container } = render(
+ <Description
+ description={
+ '<span class="fixed inset-0" onclick="alert(1)">Safe</span><a class="fixed" href="javascript:alert(1)">Link</a><img src="https://tracker.example/pixel" onerror="alert(1)"><script>alert(1)</script>'
+ }
+ />,
+ );
+
+ expect(container.querySelector('script')).not.toBeInTheDocument();
+ expect(container.querySelector('[onclick]')).not.toBeInTheDocument();
+ expect(container.querySelector('[class]')).not.toBeInTheDocument();
+ expect(screen.getByText('Link')).not.toHaveAttribute('href');
+ expect(container.querySelector('img')).not.toBeInTheDocument();
+ });
+
+ it('retains sanitized media only when explicitly enabled', () => {
+ const { container } = render(
+ <Description
+ allowMedia
+ description={'<img class="brand" src="/assets/brand.svg" alt="Brand">'}
+ />,
+ );
+
+ expect(container.querySelector('img')).toHaveAttribute('src', '/assets/brand.svg');
+ expect(container.querySelector('img')).toHaveAttribute('class', 'brand');
+ });
+
+ it('renders HTML descriptions as inert plain text for previews', () => {
+ const description =
+ '<span>Assistant for projects.<br><a href="https://example.com">Read &amp; learn</a></span>';
+ const { container } = render(
+ <Description as="p" description={description} plainText aria-label="Description preview" />,
+ );
+
+ expect(screen.getByText('Assistant for projects. Read & learn')).toBeInTheDocument();
+ expect(screen.queryByRole('link')).not.toBeInTheDocument();
+ expect(container.querySelector('span')).not.toBeInTheDocument();
+ expect(screen.getByLabelText('Description preview')).toBeInTheDocument();
+ expect(getPlainDescription(description)).toBe('Assistant for projects. Read & learn');
+ });
+
+ it('preserves ordinary text without interpreting embedded angle brackets', () => {
+ render(<Description description="Use x < y safely" />);
+
+ expect(screen.getByText('Use x < y safely')).toBeInTheDocument();
+ });
+
+ it('preserves plain text that begins with an unsupported angle-bracketed term', () => {
+ const description = '<AI> assistant';
+ const { container } = render(<Description description={description} />);
+
+ expect(container).toHaveTextContent(description);
+ expect(getPlainDescription(description)).toBe(description);
+ });
+});
diff --git a/client/src/components/ui/index.ts b/client/src/components/ui/index.ts
index a1ac76edb5..07612b15e2 100644
--- a/client/src/components/ui/index.ts
+++ b/client/src/components/ui/index.ts
@@ -1,5 +1,7 @@
export { Button, FieldMessage } from '@librechat/client';
export { default as Collapse } from './Collapse';
+export { default as Description } from './Description';
+export { getPlainDescription, isHtmlDescription } from './Description';
export { default as CustomIcon } from './CustomIcon';
export { default as PanelFooter } from './PanelFooter';
export { default as PanelContent } from './PanelContent';
diff --git a/client/src/utils/__tests__/configHtml.test.ts b/client/src/utils/__tests__/configHtml.test.ts
index 70dd242785..4599068b5b 100644
--- a/client/src/utils/__tests__/configHtml.test.ts
+++ b/client/src/utils/__tests__/configHtml.test.ts
@@ -5,6 +5,7 @@ import {
CONFIG_HTML_MEDIA_ATTR,
CONFIG_HTML_MEDIA_TAGS,
createConfigHtmlSanitizer,
+ createConfigHtmlTextSanitizer,
sanitizeConfigHtml,
} from '../configHtml';
@@ -59,4 +60,14 @@ describe('configHtml', () => {
'<span>Powered by <img src="/assets/brand.svg" alt="Brand"> AI</span><img>',
);
});
+
+ it('extracts inert text from HTML without exposing markup or executable content', () => {
+ const sanitizeText = createConfigHtmlTextSanitizer();
+
+ expect(
+ sanitizeText(
+ '<span onclick="alert(1)">Read<br><a href="javascript:alert(1)">A &amp; B</a></span><script>alert(1)</script><p>Next</p><div>Last</div>',
+ ),
+ ).toBe('Read A & B Next Last');
+ });
});
diff --git a/client/src/utils/configHtml.ts b/client/src/utils/configHtml.ts
index 8c0cbddcd7..dec654acd8 100644
--- a/client/src/utils/configHtml.ts
+++ b/client/src/utils/configHtml.ts
@@ -3,6 +3,13 @@ import DOMPurify from 'dompurify';
export const CONFIG_HTML_INLINE_TAGS = ['a', 'strong', 'b', 'em', 'i', 'br', 'code'] as const;
export const CONFIG_HTML_TEXT_TAGS = [...CONFIG_HTML_INLINE_TAGS, 'span'] as const;
export const CONFIG_HTML_BLOCK_TAGS = [...CONFIG_HTML_TEXT_TAGS, 'p'] as const;
+export const CONFIG_HTML_RICH_TEXT_TAGS = [
+ ...CONFIG_HTML_BLOCK_TAGS,
+ 'div',
+ 'ul',
+ 'ol',
+ 'li',
+] as const;
export const CONFIG_HTML_MEDIA_TAGS = [...CONFIG_HTML_TEXT_TAGS, 'img'] as const;
export const CONFIG_HTML_LINK_ATTR = ['href', 'target', 'rel'] as const;
export const CONFIG_HTML_CLASS_ATTR = [...CONFIG_HTML_LINK_ATTR, 'class'] as const;
@@ -42,6 +49,29 @@ export function createConfigHtmlSanitizer({
};
}
+export function createConfigHtmlTextSanitizer() {
+ const sanitizer = DOMPurify();
+
+ return (html?: string | null): string => {
+ if (!html) {
+ return '';
+ }
+
+ const fragment = sanitizer.sanitize(html, {
+ ALLOWED_TAGS: [...CONFIG_HTML_RICH_TEXT_TAGS],
+ ALLOWED_ATTR: [],
+ ALLOW_DATA_ATTR: false,
+ ALLOW_ARIA_ATTR: false,
+ RETURN_DOM_FRAGMENT: true,
+ });
+ for (const element of fragment.querySelectorAll('br, p, div, ul, ol, li')) {
+ element.before(' ');
+ element.after(' ');
+ }
+ return (fragment.textContent ?? '').replace(/\s+/g, ' ').trim();
+ };
+}
+
export function sanitizeConfigHtml(html?: string | null, options?: ConfigHtmlSanitizerOptions) {
return createConfigHtmlSanitizer(options)(html);
}