Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

use PurifyDom before using dangerouslySetInnerHTML

ali-inkcoe994013919e9
diff --git a/packages/app/package.json b/packages/app/package.json
index c329ac3a..55fe53e4 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -58,6 +58,7 @@
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"date-fns": "^3.6.0",
+ "dompurify": "^3.2.7",
"dotenv": "^16.3.1",
"dotenv-expand": "^12.0.3",
"dotenv-flow": "^4.1.0",
@@ -125,6 +126,7 @@
"@types/axios": "^0.14.0",
"@types/compression": "^1.7.5",
"@types/cookie-parser": "^1.4.8",
+ "@types/dompurify": "^3.2.0",
"@types/express": "^4.17.17",
"@types/express-session": "^1.18.1",
"@types/he": "^1.2.1",
@@ -137,6 +139,7 @@
"@types/react-toastify": "^4.1.0",
"@types/uuid": "^9.0.4",
"@vitejs/plugin-react-swc": "^3.8.0",
+ "autoprefixer": "^10.4.16",
"concurrently": "^8.2.1",
"cross-env": "^7.0.3",
"esbuild": "^0.20.2",
@@ -147,7 +150,6 @@
"flowbite": "^1.8.1",
"globals": "^16.0.0",
"knip": "^5.59.1",
- "autoprefixer": "^10.4.16",
"nodemon": "^2.0.22",
"prettier": "^3.0.0",
"rollup": "^3.29.4",
diff --git a/packages/app/src/builder-ui/ui/form/createFormField.ts b/packages/app/src/builder-ui/ui/form/createFormField.ts
index 10100cd6..24bb67a2 100644
--- a/packages/app/src/builder-ui/ui/form/createFormField.ts
+++ b/packages/app/src/builder-ui/ui/form/createFormField.ts
@@ -590,7 +590,8 @@ export default function createFormField(entry, displayType = 'block', entryIndex
if (entry.validateMessage) {
const span = document.createElement('span');
span.classList.add('invalid_feedback');
- span.innerHTML = entry.validateMessage;
+ // Use textContent instead of innerHTML for validation messages (no HTML needed)
+ span.textContent = entry.validateMessage;
div.appendChild(span);
}
diff --git a/packages/app/src/builder-ui/ui/form/fields.ts b/packages/app/src/builder-ui/ui/form/fields.ts
index dd748c94..414e81da 100644
--- a/packages/app/src/builder-ui/ui/form/fields.ts
+++ b/packages/app/src/builder-ui/ui/form/fields.ts
@@ -1,3 +1,4 @@
+import DOMPurify from 'dompurify';
import { Tooltip } from 'flowbite-react';
import React from 'react';
import { createRoot } from 'react-dom/client';
@@ -217,6 +218,11 @@ export function createInfoButton(
src: '/img/icons/Info.svg',
});
+ // Sanitize the HTML content to prevent XSS attacks
+ // DOMPurify's default configuration already allows all safe HTML tags
+ // and blocks dangerous elements like <script>, event handlers, etc.
+ const sanitizedText = DOMPurify.sanitize(text);
+
// Render the Tooltip component
const root = createRoot(tooltipContainer);
root.render(
@@ -224,11 +230,14 @@ export function createInfoButton(
Tooltip,
{
content: React.createElement('div', {
- dangerouslySetInnerHTML: { __html: text },
+ dangerouslySetInnerHTML: { __html: sanitizedText },
}),
placement: position as any,
className:
- clsHint + ' whitespace-normal text-xs ' + (tooltipClasses || (hasLinks ? `min-w-52 max-w-96` : `w-${estimatedWidth}`)) + ' [&_a]:whitespace-nowrap [&_a]:inline-block',
+ clsHint +
+ ' whitespace-normal text-xs ' +
+ (tooltipClasses || (hasLinks ? `min-w-52 max-w-96` : `w-${estimatedWidth}`)) +
+ ' [&_a]:whitespace-nowrap [&_a]:inline-block',
style: 'dark',
arrow: true,
},
@@ -373,10 +382,21 @@ export function createTagInput({ maxTags, value }: { maxTags: number; value: str
return input;
}
+/**
+ * Creates a hint element with sanitized HTML content
+ * @param text - The HTML text content to display in the hint
+ * @returns HTMLElement - The hint element with sanitized content
+ */
export function createHint(text: string) {
const elm = document.createElement('small');
elm.classList.add('field-hint');
- elm.innerHTML = text;
+
+ // Sanitize the HTML content to prevent XSS attacks
+ // DOMPurify's default configuration already allows all safe HTML tags
+ // and blocks dangerous elements like <script>, event handlers, etc.
+ const sanitizedText = DOMPurify.sanitize(text);
+
+ elm.innerHTML = sanitizedText;
return elm;
}
diff --git a/packages/app/src/react/features/account/modal/block-account-delete.tsx b/packages/app/src/react/features/account/modal/block-account-delete.tsx
index 0dec93a6..f375d4d1 100644
--- a/packages/app/src/react/features/account/modal/block-account-delete.tsx
+++ b/packages/app/src/react/features/account/modal/block-account-delete.tsx
@@ -9,6 +9,7 @@ import {
CardTitle,
} from '@src/react/shared/components/ui/card';
import { SMYTHOS_DOCS_URL } from '@src/shared/constants/general';
+import DOMPurify from 'dompurify';
import { AlertCircle, Crown, Info, Users } from 'lucide-react';
import { useNavigate } from 'react-router-dom';
@@ -36,10 +37,12 @@ const containsHTML = (str: string): boolean => {
*/
const renderStep = (step: string, index: number): JSX.Element => {
if (containsHTML(step)) {
+ // Sanitize HTML to prevent XSS attacks
+ const sanitizedStep = DOMPurify.sanitize(step);
return (
<li
key={index}
- dangerouslySetInnerHTML={{ __html: step }}
+ dangerouslySetInnerHTML={{ __html: sanitizedStep }}
className="[&_a]:text-[#3C89F9] [&_a]:hover:underline"
/>
);
@@ -49,10 +52,12 @@ const renderStep = (step: string, index: number): JSX.Element => {
const renderDescription = (description: string) => {
if (containsHTML(description)) {
+ // Sanitize HTML to prevent XSS attacks
+ const sanitizedDescription = DOMPurify.sanitize(description);
return (
<CardDescription
className="text-gray-600 leading-relaxed text-[14px] font-inter font-normal [&_a]:text-[#3C89F9] [&_a]:hover:underline"
- dangerouslySetInnerHTML={{ __html: description }}
+ dangerouslySetInnerHTML={{ __html: sanitizedDescription }}
></CardDescription>
);
}
@@ -148,11 +153,21 @@ export default function BlockAccountDeleteModal({ handleToggle, deleteAccRequire
<div className="text-center">
<p className="text-xs text-gray-500 font-inter font-normal">
Need help? Visit our{' '}
- <a href={SMYTHOS_DOCS_URL} className="text-[#3C89F9] hover:underline" target="_blank" rel="noopener noreferrer">
+ <a
+ href={SMYTHOS_DOCS_URL}
+ className="text-[#3C89F9] hover:underline"
+ target="_blank"
+ rel="noopener noreferrer"
+ >
documentation
</a>{' '}
or{' '}
- <a href="https://discord.gg/smythos" className="text-[#3C89F9] hover:underline" target="_blank" rel="noopener noreferrer">
+ <a
+ href="https://discord.gg/smythos"
+ className="text-[#3C89F9] hover:underline"
+ target="_blank"
+ rel="noopener noreferrer"
+ >
contact support
</a>
</p>
diff --git a/packages/app/src/react/features/vault/components/create-enterprise-modal.tsx b/packages/app/src/react/features/vault/components/create-enterprise-modal.tsx
index ad64f52b..9ac2bc01 100644
--- a/packages/app/src/react/features/vault/components/create-enterprise-modal.tsx
+++ b/packages/app/src/react/features/vault/components/create-enterprise-modal.tsx
@@ -34,6 +34,7 @@ import {
CUSTOM_LLM_FEATURES,
CUSTOM_LLM_PROVIDERS,
} from '@src/shared/constants/custom-llm.constants';
+import DOMPurify from 'dompurify';
import { useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
import { FaCircleExclamation } from 'react-icons/fa6';
@@ -272,7 +273,7 @@ export function CreateEnterpriseModal({
placement="right"
>
<div
- dangerouslySetInnerHTML={{ __html: infoIcon }}
+ dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(infoIcon) }}
className="w-4 h-4 text-gray-400"
/>
</ToolTip>
diff --git a/packages/app/src/react/shared/components/_legacy/ui/tooltip/tooltip.tsx b/packages/app/src/react/shared/components/_legacy/ui/tooltip/tooltip.tsx
index 9fd23c26..2783916a 100644
--- a/packages/app/src/react/shared/components/_legacy/ui/tooltip/tooltip.tsx
+++ b/packages/app/src/react/shared/components/_legacy/ui/tooltip/tooltip.tsx
@@ -1,3 +1,4 @@
+import DOMPurify from 'dompurify';
import { PropsWithChildren, ReactNode, useEffect, useRef, useState } from 'react';
/**
@@ -150,7 +151,7 @@ export default function ToolTip({
{content !== undefined ? (
content
) : html ? (
- <div dangerouslySetInnerHTML={{ __html: html }} />
+ <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(html) }} />
) : isMultiLine && Array.isArray(text) ? (
text?.filter((txt) => txt?.trim()).map((txt, i) => <p key={i}>{txt}</p>)
) : (