Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

[Metabot] Do not render images in markdown (#76280)

Sloan Spargera7ff8b0c5549
diff --git a/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx b/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx
index e567a4e1916..4ec557604e5 100644
--- a/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx
+++ b/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx
@@ -27,6 +27,9 @@ type AIMarkdownProps = MarkdownProps & {
singleNewlinesAreParagraphs?: boolean;
};
+// SEC-505: block all images; to support them we'll need detection for valid/allowed image sources
+const DISALLOWED_ELEMENTS = ["img"];
+
const splitMessageLinesAsParagraphs = (message: string) =>
message.replaceAll(/\r?\n|\r/g, "\n\n");
@@ -151,6 +154,8 @@ export const AIMarkdown = memo(
<Markdown
className={cx(S.aiMarkdown, className)}
components={components}
+ disallowedElements={DISALLOWED_ELEMENTS}
+ unwrapDisallowed
{...props}
>
{normalizedChildren}
diff --git a/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.unit.spec.tsx b/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.unit.spec.tsx
index 8e68ac3e175..3e96cd138d7 100644
--- a/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.unit.spec.tsx
+++ b/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.unit.spec.tsx
@@ -61,6 +61,16 @@ describe("AIMarkdown", () => {
expect(screen.getByRole("cell", { name: "$42" })).toBeInTheDocument();
});
+ it("should not render images", async () => {
+ setup({
+ children: `start ![remote](https://example.com/cat.png) ![data](data:image/png;base64,iVBORw0KGgo=) end`,
+ });
+
+ expect(await screen.findByText(/start/)).toBeInTheDocument();
+ expect(screen.getByText(/end/)).toBeInTheDocument();
+ expect(screen.queryByRole("img")).not.toBeInTheDocument();
+ });
+
it("should copy fenced code blocks", async () => {
setup({
children: `