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
@@ -21,6 +21,7 @@
|
|||||||
"@types/jest": "^26.0.14",
|
"@types/jest": "^26.0.14",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"dayjs": "^1.10.4",
|
"dayjs": "^1.10.4",
|
||||||
|
"dompurify": "^2.2.6",
|
||||||
"emoji-mart": "^3.0.0",
|
"emoji-mart": "^3.0.0",
|
||||||
"enzyme": "^3.11.0",
|
"enzyme": "^3.11.0",
|
||||||
"enzyme-adapter-react-16": "^1.15.5",
|
"enzyme-adapter-react-16": "^1.15.5",
|
||||||
|
|||||||
@@ -37,6 +37,18 @@ InjectDebugData([
|
|||||||
app: 'TWITTER',
|
app: 'TWITTER',
|
||||||
method: 'fetchTweets',
|
method: 'fetchTweets',
|
||||||
data: [
|
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,
|
id: 2,
|
||||||
message: 'GCPhone will never die',
|
message: 'GCPhone will never die',
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
ListItem,
|
ListItem,
|
||||||
Typography,
|
Typography,
|
||||||
} from '@material-ui/core';
|
} from '@material-ui/core';
|
||||||
|
|
||||||
import { secondsToHumanReadable } from '../../utils/time';
|
import { secondsToHumanReadable } from '../../utils/time';
|
||||||
import LikeButton from '../buttons/LikeButton';
|
import LikeButton from '../buttons/LikeButton';
|
||||||
import ReplyButton from '../buttons/ReplyButton';
|
import ReplyButton from '../buttons/ReplyButton';
|
||||||
@@ -16,6 +15,7 @@ import Avatar from '../Avatar';
|
|||||||
import ShowMore from './ShowMore';
|
import ShowMore from './ShowMore';
|
||||||
import { QuoteButton } from '../buttons/QuoteButton';
|
import { QuoteButton } from '../buttons/QuoteButton';
|
||||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||||
|
import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -80,7 +80,16 @@ export const Tweet = (tweet) => {
|
|||||||
|
|
||||||
// this is a workaround to transfer string new lines and returns that
|
// this is a workaround to transfer string new lines and returns that
|
||||||
// are stored into the database into html for the UI to render
|
// 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 />');
|
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}` : '';
|
const profileName = profile_name ? `@${profile_name}` : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -106,7 +115,9 @@ export const Tweet = (tweet) => {
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={classes.message}
|
className={classes.message}
|
||||||
dangerouslySetInnerHTML={{ __html: formattedMessage }}
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: sanitizedMessage,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{enableImages && <ImageDisplay visible images={images} small />}
|
{enableImages && <ImageDisplay visible images={images} small />}
|
||||||
<div className={classes.buttonContainer}>
|
<div className={classes.buttonContainer}>
|
||||||
|
|||||||
@@ -4629,6 +4629,11 @@ domhandler@^2.3.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
domelementtype "1"
|
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]:
|
[email protected]:
|
||||||
version "1.5.1"
|
version "1.5.1"
|
||||||
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"
|
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"
|
||||||
|
|||||||
Reference in new issue
Block a user