From 9f5891025424539d63d0684ee1497c2a38f354be Mon Sep 17 00:00:00 2001 From: Willie Zutz Date: Sat, 19 Jul 2025 12:00:08 -0600 Subject: [PATCH] feat(markdown): Enhance ThinkBox and MarkdownRenderer for improved content handling and security --- src/components/MarkdownRenderer.tsx | 9 +++++++-- src/components/ThinkBox.tsx | 9 +++++---- src/components/dashboard/WidgetConfigModal.tsx | 11 ++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/components/MarkdownRenderer.tsx b/src/components/MarkdownRenderer.tsx index 205a0df..bbddde7 100644 --- a/src/components/MarkdownRenderer.tsx +++ b/src/components/MarkdownRenderer.tsx @@ -39,7 +39,7 @@ const ThinkTagProcessor = ({ if (isOverlayMode) { return null; } - return ; + return ; }; const CodeBlock = ({ @@ -149,6 +149,11 @@ const MarkdownRenderer = ({ pre: { component: ({ children }) => children, }, + // Prevent rendering of certain HTML elements for security + iframe: () => null, // Don't render iframes + script: () => null, // Don't render scripts + object: () => null, // Don't render objects + style: () => null, // Don't render styles }, }; @@ -170,7 +175,7 @@ const MarkdownRenderer = ({ 'prose prose-h1:mb-3 prose-h2:mb-2 prose-h2:mt-6 prose-h2:font-[800] prose-h3:mt-4 prose-h3:mb-1.5 prose-h3:font-[600] prose-invert prose-p:leading-relaxed prose-pre:p-0 font-[400]', 'prose-code:bg-transparent prose-code:p-0 prose-code:text-inherit prose-code:font-normal prose-code:before:content-none prose-code:after:content-none', 'prose-pre:bg-transparent prose-pre:border-0 prose-pre:m-0 prose-pre:p-0', - 'break-words text-black dark:text-white', + 'break-words text-black dark:text-white max-w-full', className, )} options={markdownOverrides} diff --git a/src/components/ThinkBox.tsx b/src/components/ThinkBox.tsx index 0125a4e..edfd7ab 100644 --- a/src/components/ThinkBox.tsx +++ b/src/components/ThinkBox.tsx @@ -1,18 +1,19 @@ 'use client'; -import { useState } from 'react'; +import { ReactNode, useState } from 'react'; import { cn } from '@/lib/utils'; import { ChevronDown, ChevronUp, BrainCircuit } from 'lucide-react'; interface ThinkBoxProps { - content: string; + content: ReactNode; expanded?: boolean; onToggle?: () => void; } const ThinkBox = ({ content, expanded, onToggle }: ThinkBoxProps) => { - // Don't render anything if content is empty or only whitespace - if (!content || content.trim().length === 0) { + // Don't render anything if content is empty + console.log('ThinkBox content:', content); + if (!content) { return null; } diff --git a/src/components/dashboard/WidgetConfigModal.tsx b/src/components/dashboard/WidgetConfigModal.tsx index 148e14d..42d6b52 100644 --- a/src/components/dashboard/WidgetConfigModal.tsx +++ b/src/components/dashboard/WidgetConfigModal.tsx @@ -137,6 +137,11 @@ const WidgetConfigModal = ({ } onSave(config); + handleClose(); + }; + + const handleClose = () => { + setPreviewContent(''); // Clear preview content when closing onClose(); }; @@ -218,7 +223,7 @@ const WidgetConfigModal = ({ return ( - + {editingWidget ? 'Edit Widget' : 'Create New Widget'}