From 84c37d2eeb6cbd4f4f64c6bc593d8e209e134ac1 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Mon, 2 Dec 2024 23:06:28 +0000 Subject: [PATCH 1/2] Sanitize markdown when previewing report header/footer Signed-off-by: Joshua Li --- .../report_definitions/report_settings/report_settings.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/components/report_definitions/report_settings/report_settings.tsx b/public/components/report_definitions/report_settings/report_settings.tsx index f81826ee..2eb0b4b9 100644 --- a/public/components/report_definitions/report_settings/report_settings.tsx +++ b/public/components/report_definitions/report_settings/report_settings.tsx @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import createDOMPurify from 'dompurify'; import React, { useEffect, useState } from 'react'; import { i18n } from '@osd/i18n'; import { @@ -340,6 +341,8 @@ export function ReportSettings(props: ReportSettingProps) { setCheckboxIdSelectHeaderFooter(newCheckboxIdToSelectedMap); }; + const DOMPurify = createDOMPurify(window); + const showFooter = checkboxIdSelectHeaderFooter.footer ? ( - Promise.resolve(converter.makeHtml(markdown)) + Promise.resolve(DOMPurify.sanitize(converter.makeHtml(markdown))) } /> @@ -380,7 +383,7 @@ export function ReportSettings(props: ReportSettingProps) { ['unordered-list', 'ordered-list', 'checked-list'], ]} generateMarkdownPreview={(markdown) => - Promise.resolve(converter.makeHtml(markdown)) + Promise.resolve(DOMPurify.sanitize(converter.makeHtml(markdown))) } /> From c9466b7fc11fec8409105ddb99303da95c337843 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Mon, 2 Dec 2024 23:22:22 +0000 Subject: [PATCH 2/2] update snapshots Signed-off-by: Joshua Li --- .../__tests__/__snapshots__/main.test.tsx.snap | 16 ++++++++-------- .../__snapshots__/reports_table.test.tsx.snap | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/public/components/main/__tests__/__snapshots__/main.test.tsx.snap b/public/components/main/__tests__/__snapshots__/main.test.tsx.snap index c64ee236..d9a0821d 100644 --- a/public/components/main/__tests__/__snapshots__/main.test.tsx.snap +++ b/public/components/main/__tests__/__snapshots__/main.test.tsx.snap @@ -73,7 +73,7 @@ exports[`
panel render component 1`] = ` />
panel render component 1`] = `
panel render component after create success 1`] = ` />
panel render component after create success 1`] = `
panel render component after delete success 1`] = ` />
panel render component after delete success 1`] = `
panel render component after edit success 1`] = ` />
panel render component after edit success 1`] = `
panel render component 1`] = `
panel render component 1`] = `
panel render component 1`] = ` exports[` panel render empty component 1`] = `
panel render empty component 1`] = `