diff --git a/web/app/components/base/markdown-blocks/code-block.tsx b/web/app/components/base/markdown-blocks/code-block.tsx index b9b3074351..744a578ff6 100644 --- a/web/app/components/base/markdown-blocks/code-block.tsx +++ b/web/app/components/base/markdown-blocks/code-block.tsx @@ -204,23 +204,10 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any } } catch { - try { - // eslint-disable-next-line no-new-func - const result = new Function(`return ${trimmedContent}`)() - if (typeof result === 'object' && result !== null) { - setFinalChartOption(result) - setChartState('success') - processedRef.current = true - return - } - } - catch { - // If we have a complete JSON structure but it doesn't parse, - // it's likely an error rather than incomplete data - setChartState('error') - processedRef.current = true - return - } + // Avoid executing arbitrary code; require valid JSON for chart options. + setChartState('error') + processedRef.current = true + return } } @@ -249,19 +236,9 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any } } catch { - try { - // eslint-disable-next-line no-new-func - const result = new Function(`return ${trimmedContent}`)() - if (typeof result === 'object' && result !== null) { - setFinalChartOption(result) - isValidOption = true - } - } - catch { - // Both parsing methods failed, but content looks complete - setChartState('error') - processedRef.current = true - } + // Only accept JSON to avoid executing arbitrary code from the message. + setChartState('error') + processedRef.current = true } if (isValidOption) {