fix(ui) Sanitize V1 UI sidebar description section (#13203)

This commit is contained in:
Chris Collins 2025-04-14 13:34:15 -04:00 committed by GitHub
parent 319b849532
commit 3fd0e37111
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ import { Typography } from 'antd';
import React, { useState } from 'react'; import React, { useState } from 'react';
import styled from 'styled-components/macro'; import styled from 'styled-components/macro';
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import DOMPurify from 'dompurify';
import CompactContext from '../../../../../../shared/CompactContext'; import CompactContext from '../../../../../../shared/CompactContext';
import MarkdownViewer, { MarkdownView } from '../../../../components/legacy/MarkdownViewer'; import MarkdownViewer, { MarkdownView } from '../../../../components/legacy/MarkdownViewer';
import NoMarkdownViewer, { removeMarkdown } from '../../../../components/styled/StripMarkdownText'; import NoMarkdownViewer, { removeMarkdown } from '../../../../components/styled/StripMarkdownText';
@ -68,12 +69,15 @@ export default function DescriptionSection({ description, baDescription, isExpan
} }
} }
const sanitizedDescription = DOMPurify.sanitize(description);
const sanitizedBADescription = DOMPurify.sanitize(baDescription || '');
return ( return (
<> <>
<ContentWrapper> <ContentWrapper>
{isExpanded && ( {isExpanded && (
<> <>
<MarkdownViewer source={description} ignoreLimit /> <MarkdownViewer source={sanitizedDescription} ignoreLimit />
{isOverLimit && ( {isOverLimit && (
<Typography.Link onClick={() => setIsExpanded(false)}>Read Less</Typography.Link> <Typography.Link onClick={() => setIsExpanded(false)}>Read Less</Typography.Link>
)} )}
@ -89,14 +93,14 @@ export default function DescriptionSection({ description, baDescription, isExpan
} }
shouldWrap shouldWrap
> >
{description} {sanitizedDescription}
</NoMarkdownViewer> </NoMarkdownViewer>
)} )}
</ContentWrapper> </ContentWrapper>
<BaContentWrapper> <BaContentWrapper>
{isBaExpanded && ( {isBaExpanded && (
<> <>
<MarkdownViewer source={baDescription || ''} ignoreLimit /> <MarkdownViewer source={sanitizedBADescription || ''} ignoreLimit />
{isBaOverLimit && ( {isBaOverLimit && (
<Typography.Link onClick={() => setIsBaExpanded(false)}>Read Less</Typography.Link> <Typography.Link onClick={() => setIsBaExpanded(false)}>Read Less</Typography.Link>
)} )}
@ -112,7 +116,7 @@ export default function DescriptionSection({ description, baDescription, isExpan
} }
shouldWrap shouldWrap
> >
{baDescription} {sanitizedBADescription}
</NoMarkdownViewer> </NoMarkdownViewer>
)} )}
</BaContentWrapper> </BaContentWrapper>