mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
fix(security): sanitize server-pushed notification HTML (alert + bubble)
NotificationDefaultAlertView / NotificationDefaultBubbleView injected the server notification message (newline->br only) via dangerouslySetInnerHTML. Route through SanitizeHtml — the allow-list keeps the br/link/formatting these alerts use and strips anything else. Left Nitropedia (rich fetched HTML w/ tags outside the allow-list) and NitrobubbleHidden (<style> block) untouched on purpose: SanitizeHtml would break them.
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { FC, useMemo, useState } from 'react';
|
||||
import { DispatchUiEvent, LocalizeText, NotificationAlertItem, NotificationAlertType, OpenUrl, RoomWidgetUpdateChatInputContentEvent } from '../../../../api';
|
||||
import { DispatchUiEvent, LocalizeText, NotificationAlertItem, NotificationAlertType, OpenUrl, RoomWidgetUpdateChatInputContentEvent, SanitizeHtml } from '../../../../api';
|
||||
import { Button, Column, Flex, LayoutNotificationAlertView, LayoutNotificationAlertViewProps } from '../../../../common';
|
||||
|
||||
interface NotificationDefaultAlertViewProps extends LayoutNotificationAlertViewProps
|
||||
@@ -97,7 +97,7 @@ export const NotificationDefaultAlertView: FC<NotificationDefaultAlertViewProps>
|
||||
{
|
||||
const htmlText = message.replace(/\r\n|\r|\n/g, '<br />');
|
||||
|
||||
return <div key={ index } dangerouslySetInnerHTML={ { __html: htmlText } } />;
|
||||
return <div key={ index } dangerouslySetInnerHTML={ { __html: SanitizeHtml(htmlText) } } />;
|
||||
}) }
|
||||
{ item.clickUrl && (item.clickUrl.length > 0) && (item.imageUrl && !imageFailed) && <>
|
||||
<hr className="my-2 w-full" />
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { FC } from 'react';
|
||||
import { NotificationBubbleItem, OpenUrl } from '../../../../api';
|
||||
import { NotificationBubbleItem, OpenUrl, SanitizeHtml } from '../../../../api';
|
||||
import { Flex, LayoutNotificationBubbleView, LayoutNotificationBubbleViewProps, Text } from '../../../../common';
|
||||
|
||||
export interface NotificationDefaultBubbleViewProps extends LayoutNotificationBubbleViewProps
|
||||
@@ -19,7 +19,7 @@ export const NotificationDefaultBubbleView: FC<NotificationDefaultBubbleViewProp
|
||||
{ (item.iconUrl && item.iconUrl.length) &&
|
||||
<img alt="" className="no-select" src={ item.iconUrl } /> }
|
||||
</Flex>
|
||||
<Text wrap dangerouslySetInnerHTML={ { __html: htmlText } } variant="white" />
|
||||
<Text wrap dangerouslySetInnerHTML={ { __html: SanitizeHtml(htmlText) } } variant="white" />
|
||||
</LayoutNotificationBubbleView>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user