mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
fix(phone/tweet): Fixed possible XSS vector
As we were parsing user input for \n in order to convert to <br> tags, a XSS vulnerability was introduced allowing for users to pass arbitrary script tags to be rendered in tweets.
This commit is contained in:
1 parent
c0509be2d1
commit
b73919c147
4 files changed
+31
-2
No files matched your search
@@ -7,7 +7,6 @@ import {
|
||||
ListItem,
|
||||
Typography,
|
||||
} from '@material-ui/core';
|
||||
|
||||
import { secondsToHumanReadable } from '../../utils/time';
|
||||
import LikeButton from '../buttons/LikeButton';
|
||||
import ReplyButton from '../buttons/ReplyButton';
|
||||
@@ -16,6 +15,7 @@ import Avatar from '../Avatar';
|
||||
import ShowMore from './ShowMore';
|
||||
import { QuoteButton } from '../buttons/QuoteButton';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
@@ -80,7 +80,16 @@ export const Tweet = (tweet) => {
|
||||
|
||||
// this is a workaround to transfer string new lines and returns that
|
||||
// are stored into the database into html for the UI to render
|
||||
|
||||
// We are replacing with <br /> to eventually render in HTML
|
||||
const formattedMessage = message.replace(/\n\r?/g, '<br />');
|
||||
|
||||
// Therefore we need to sanitize this message to protect against XSS
|
||||
const sanitizedMessage = DOMPurify.sanitize(formattedMessage, {
|
||||
// Be as strict as possible, whitelisting <br> tag
|
||||
ALLOWED_TAGS: ['br'],
|
||||
});
|
||||
|
||||
const profileName = profile_name ? `@${profile_name}` : '';
|
||||
|
||||
return (
|
||||
@@ -106,7 +115,9 @@ export const Tweet = (tweet) => {
|
||||
</div>
|
||||
<div
|
||||
className={classes.message}
|
||||
dangerouslySetInnerHTML={{ __html: formattedMessage }}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: sanitizedMessage,
|
||||
}}
|
||||
/>
|
||||
{enableImages && <ImageDisplay visible images={images} small />}
|
||||
<div className={classes.buttonContainer}>
|
||||
|
||||
Reference in new issue
Block a user