diff --git a/phone/package.json b/phone/package.json
index 1e6e99a..834dbe5 100644
--- a/phone/package.json
+++ b/phone/package.json
@@ -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",
diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx
index 446ef13..11c2573 100644
--- a/phone/src/apps/twitter/components/TwitterApp.tsx
+++ b/phone/src/apps/twitter/components/TwitterApp.tsx
@@ -37,6 +37,18 @@ InjectDebugData([
app: 'TWITTER',
method: 'fetchTweets',
data: [
+ {
+ id: 59,
+ message: 'XSS\n\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',
diff --git a/phone/src/apps/twitter/components/tweet/Tweet.tsx b/phone/src/apps/twitter/components/tweet/Tweet.tsx
index 5e99f83..d382a36 100644
--- a/phone/src/apps/twitter/components/tweet/Tweet.tsx
+++ b/phone/src/apps/twitter/components/tweet/Tweet.tsx
@@ -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
to eventually render in HTML
const formattedMessage = message.replace(/\n\r?/g, '
');
+
+ // Therefore we need to sanitize this message to protect against XSS
+ const sanitizedMessage = DOMPurify.sanitize(formattedMessage, {
+ // Be as strict as possible, whitelisting
tag
+ ALLOWED_TAGS: ['br'],
+ });
+
const profileName = profile_name ? `@${profile_name}` : '';
return (
@@ -106,7 +115,9 @@ export const Tweet = (tweet) => {