From 378a1d7d08bd0ac5c75eaadc075a0f35211fcb8e Mon Sep 17 00:00:00 2001 From: veganmosfet <152803318+veganmosfet@users.noreply.github.com> Date: Wed, 11 Feb 2026 07:22:30 +0100 Subject: [PATCH] Merge commit from fork Removed the dangerous `new function` call during echarts parsing and replaced with an error message. Co-authored-by: Byron Wang --- .../base/markdown-blocks/code-block.tsx | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) 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) {