mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
fix(security): sanitize user-controlled HTML in chat & username sinks
Several dangerouslySetInnerHTML sinks rendered user-controlled strings (chat messages, usernames, chat history) without sanitisation, relying implicitly on upstream formatting or server-side charset limits. Route them all through the existing SanitizeHtml (DOMPurify) helper so the security guarantee is local to each render site. Sinks fixed: ChatWidgetWindowView (name/message/original/translated), ChatHistoryView (name/message), AvatarInfoWidgetNameView + AvatarInfoWidgetAvatarView (username), SelectReportedUserView (username). Add regression suites: SanitizeHtml.test.ts (XSS neutralised, chat markup preserved) and RoomChatFormatter.test.ts (pins the existing encodeHTML defence). No behaviour change: SanitizeHtml's allow-list keeps the b/i/u/span/strong/em/br markup the chat/profile UI relies on.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { GetSessionDataManager, RoomObjectType } from '@nitrots/nitro-renderer';
|
||||
import { FC, useMemo, useState } from 'react';
|
||||
import { ChatEntryType, IReportedUser, LocalizeText, ReportState } from '../../../api';
|
||||
import { ChatEntryType, IReportedUser, LocalizeText, ReportState, SanitizeHtml } from '../../../api';
|
||||
import { AutoGrid, Button, Column, Flex, LayoutGridItem, Text } from '../../../common';
|
||||
import { useChatHistory, useHelp } from '../../../hooks';
|
||||
|
||||
@@ -66,7 +66,7 @@ export const SelectReportedUserView: FC<{}> = props =>
|
||||
{
|
||||
return (
|
||||
<LayoutGridItem key={ user.id } itemActive={ (selectedUserId === user.id) } onClick={ event => selectUser(user.id) }>
|
||||
<span dangerouslySetInnerHTML={ { __html: (user.username) } } />
|
||||
<span dangerouslySetInnerHTML={ { __html: SanitizeHtml(user.username) } } />
|
||||
</LayoutGridItem>
|
||||
);
|
||||
}) }
|
||||
|
||||
Reference in New Issue
Block a user