Skip to content

Commit

Permalink
Sanitize markdown when previewing report header/footer (#476)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <joshuali925@gmail.com>
(cherry picked from commit 2973562)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Dec 10, 2024
1 parent 583e6ce commit 5063c70
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 ? (
<EuiFormRow
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)))
}
/>
</EuiFormRow>
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)))
}
/>
</EuiFormRow>
Expand Down

0 comments on commit 5063c70

Please sign in to comment.