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:
Taso committed 2021-02-09 11:14:52 -05:00
1 parent c0509be2d1
commit b73919c147
4 files changed
+31 -2

No files matched your search

+1
View File
@@ -21,6 +21,7 @@
"@types/jest": "^26.0.14",
"core-js": "^3.6.5",
"dayjs": "^1.10.4",
"dompurify": "^2.2.6",
"emoji-mart": "^3.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
@@ -37,6 +37,18 @@ InjectDebugData([
app: 'TWITTER',
method: 'fetchTweets',
data: [
{
id: 59,
message: 'XSS\n<script src="test.js">Test</script>\nBro',
avatar_url: 'http://i.tasoagc.dev/jtKL',
seconds_since_tweet: 500,
isMine: false,
updateAt: '2021-02-08 14:37:46',
visible: 1,
likes: 50000,
profile_name: 'jQuery Main',
images: 'http://i.tasoagc.dev/0xdp',
},
{
id: 2,
message: 'GCPhone will never die',
@@ -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}>
+5
View File
@@ -4629,6 +4629,11 @@ domhandler@^2.3.0:
dependencies:
domelementtype "1"
dompurify@^2.2.6:
version "2.2.6"
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.2.6.tgz#54945dc5c0b45ce5ae228705777e8e59d7b2edc4"
integrity sha512-7b7ZArhhH0SP6W2R9cqK6RjaU82FZ2UPM7RO8qN1b1wyvC/NY1FNWcX1Pu00fFOAnzEORtwXe4bPaClg6pUybQ==
[email protected]:
version "1.5.1"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"