Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add DOMPurify to prevent XSS attacks in the way emojis are rendered #621

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"husky": "^9.0.11",
"lerna": "^6.6.2",
"typescript": "^5.1.3"
},
"dependencies": {
"dompurify": "^3.1.6"
}
}
3 changes: 2 additions & 1 deletion packages/markups/src/elements/Emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import emojione from 'emoji-toolkit';
import { Box } from '@embeddedchat/ui-elements';
import DOMPurify from 'dompurify';
import { EmojiStyles as styles } from './elements.styles';

const Emoji = ({ big = false, emoji }) => {
Expand All @@ -21,7 +22,7 @@ const Emoji = ({ big = false, emoji }) => {
<Box
is="span"
css={[styles.emojione, styles.emojiInMessage]}
dangerouslySetInnerHTML={{ __html: emojiHtml }}
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(emojiHtml) }}
/>
);
};
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/views/EmojiReaction/EmojiReaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import emojione from 'emoji-toolkit';
import { css } from '@emotion/react';
import { Box } from '@embeddedchat/ui-elements';
import DOMPurify from 'dompurify';

const EmojiReaction = ({ body }) => {
const emojiHtml = emojione.toImage(body);
Expand All @@ -12,7 +13,7 @@ const EmojiReaction = ({ body }) => {
css={css`
font-size: 1rem;
`}
dangerouslySetInnerHTML={{ __html: emojiHtml }}
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(emojiHtml) }}
/>
);
};
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15006,6 +15006,13 @@ __metadata:
languageName: node
linkType: hard

"dompurify@npm:^3.1.6":
version: 3.1.6
resolution: "dompurify@npm:3.1.6"
checksum: cc4fc4ccd9261fbceb2a1627a985c70af231274a26ddd3f643fd0616a0a44099bd9e4480940ce3655612063be4a1fe9f5e9309967526f8c0a99f931602323866
languageName: node
linkType: hard

"domutils@npm:^2.5.2, domutils@npm:^2.8.0":
version: 2.8.0
resolution: "domutils@npm:2.8.0"
Expand Down Expand Up @@ -15194,6 +15201,7 @@ __metadata:
resolution: "embeddedchat@workspace:."
dependencies:
"@changesets/cli": ^2.26.2
dompurify: ^3.1.6
esbuild: ^0.17.19
husky: ^9.0.11
lerna: ^6.6.2
Expand Down
Loading