Skip to content

Commit

Permalink
Sanitize markdown when previewing report header/footer
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Dec 2, 2024
1 parent deb8b59 commit 84c37d2
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -340,6 +341,8 @@ export function ReportSettings(props: ReportSettingProps) {
setCheckboxIdSelectHeaderFooter(newCheckboxIdToSelectedMap);
};

const DOMPurify = createDOMPurify(window);

const showFooter = checkboxIdSelectHeaderFooter.footer ? (
<EuiCompressedFormRow
label={i18n.translate('opensearch.reports.reportSettingProps.footer', {
Expand All @@ -357,7 +360,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)))
}
/>
</EuiCompressedFormRow>
Expand All @@ -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)))
}
/>
</EuiCompressedFormRow>
Expand Down

0 comments on commit 84c37d2

Please sign in to comment.