Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/ui/MessageInput/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import MentionUserLabel from '../MentionUserLabel';
import Icon, { IconTypes, IconColors } from '../Icon';
import Label, { LabelTypography, LabelColors } from '../Label';
import { LocalizationContext } from '../../lib/LocalizationContext';
import { sanitizeString } from './utils';
import {
arrayEqual,
getClassName,
Expand Down Expand Up @@ -114,6 +115,7 @@ const MessageInput = React.forwardRef((props, ref) => {
}
), []);

// #Edit mode
// for easilly initialize input value from outside, but
// useEffect(_, [channelUrl]) erase it
const initialValue = props?.value;
Expand All @@ -136,7 +138,7 @@ const MessageInput = React.forwardRef((props, ref) => {
}
}, [channelUrl]);

// #Mention | Fill message input values
// #Mention & #Edit | Fill message input values
useEffect(() => {
if (isEdit && message?.messageId) {
// const textField = document.getElementById(textFieldId);
Expand All @@ -150,9 +152,7 @@ const MessageInput = React.forwardRef((props, ref) => {
textField.innerHTML = message?.mentionedMessageTemplate?.split(' ').map((word) => (
convertWordToStringObj(word, mentionedUsers).map((stringObj) => {
const { type, value, userId } = stringObj;
if (type === StringObjType.mention
&& mentionedUsers.some((user) => user?.userId === userId)
) {
if (type === StringObjType.mention && mentionedUsers.some((user) => user?.userId === userId)) {
return renderToString(
<MentionUserLabel userId={userId}>
{
Expand All @@ -164,13 +164,13 @@ const MessageInput = React.forwardRef((props, ref) => {
</MentionUserLabel>,
);
}
return value;
return sanitizeString(value);
}).join('')
)).join(' ');
} else {
/* mention disabled */
try {
textField.innerHTML = message?.message;
textField.innerHTML = sanitizeString(message?.message);
} catch { }
setMentionedUserIds([]);
}
Expand Down Expand Up @@ -428,7 +428,7 @@ const MessageInput = React.forwardRef((props, ref) => {
}}
onPaste={(e) => {
e.preventDefault();
document.execCommand("insertHTML", false, e?.clipboardData.getData('text'));
document.execCommand("insertHTML", false, sanitizeString(e?.clipboardData.getData('text')));
}}
/>
{/* placeholder */}
Expand Down
5 changes: 5 additions & 0 deletions src/ui/MessageInput/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export function debounce(func, wait, immediate) {
};
}

// Sanitize that special characters of HTML tags cause XSS issue
export const sanitizeString = (str) => (
str?.replace(/[\u00A0-\u9999<>]/gim, (i) => ''.concat('&#', i.charCodeAt(0), ';'))
);

export default debounce;