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) => {
{enableImages && }
diff --git a/phone/yarn.lock b/phone/yarn.lock index 1598c19..34f5fc5 100644 --- a/phone/yarn.lock +++ b/phone/yarn.lock @@ -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== + domutils@1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"