Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): sanitize agent rerun modal HTML against stored XSS (#16516)

Harsh Kashyap572f1ea9f4eb
diff --git a/web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx b/web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx
new file mode 100644
index 0000000000..997923148c
--- /dev/null
+++ b/web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx
@@ -0,0 +1,13 @@
+import DOMPurify from 'dompurify';
+
+describe('rerun modal content sanitization', () => {
+ it('strips unsafe html from interpolated pipeline step names', () => {
+ const step = '<img src=x onerror="alert(1)"><script>alert(1)</script>';
+ const html = `You are about to rerun the process starting from the <span class="text-text-secondary">${step}</span> step.`;
+ const sanitized = DOMPurify.sanitize(html);
+
+ expect(sanitized).not.toMatch(/onerror/i);
+ expect(sanitized).not.toContain('<script');
+ expect(sanitized).toContain('img');
+ });
+});
diff --git a/web/src/pages/dataflow-result/components/rerun-button/index.tsx b/web/src/pages/dataflow-result/components/rerun-button/index.tsx
index 5b6015032c..c87a3e949d 100644
--- a/web/src/pages/dataflow-result/components/rerun-button/index.tsx
+++ b/web/src/pages/dataflow-result/components/rerun-button/index.tsx
@@ -2,6 +2,7 @@ import { TimelineNode } from '@/components/originui/timeline';
import SvgIcon from '@/components/svg-icon';
import { Button } from '@/components/ui/button';
import { Modal } from '@/components/ui/modal/modal';
+import DOMPurify from 'dompurify';
import { CircleAlert } from 'lucide-react';
import { useTranslation } from 'react-i18next';
interface RerunButtonProps {
@@ -11,7 +12,7 @@ interface RerunButtonProps {
loading?: boolean;
}
const RerunButton = (props: RerunButtonProps) => {
- const { className, step, onRerun, loading } = props;
+ const { step, onRerun, loading } = props;
const { t } = useTranslation();
const clickFunc = () => {
console.log('click rerun button');
@@ -22,9 +23,11 @@ const RerunButton = (props: RerunButtonProps) => {
children: (
<div
dangerouslySetInnerHTML={{
- __html: t('dataflowParser.confirmRerunModalContent', {
- step: step?.title,
- }),
+ __html: DOMPurify.sanitize(
+ t('dataflowParser.confirmRerunModalContent', {
+ step: step?.title,
+ }),
+ ),
}}
></div>
),