Commit 2e07ba05 authored by Dheeraj Joshi's avatar Dheeraj Joshi Committed by Simon Knox

Sanitize emojis when reading from LocalStorage

This adds dompurify to sanitize emoji map
to prevent any potential xss vulnerability

Changelog: security
parent 1eb18749
import { escape, minBy } from 'lodash'; import { escape, minBy } from 'lodash';
import emojiAliases from 'emojis/aliases.json'; import emojiAliases from 'emojis/aliases.json';
import { sanitize } from '~/lib/dompurify';
import AccessorUtilities from '../lib/utils/accessor'; import AccessorUtilities from '../lib/utils/accessor';
import axios from '../lib/utils/axios_utils'; import axios from '../lib/utils/axios_utils';
import { CATEGORY_ICON_MAP, FREQUENTLY_USED_KEY } from './constants'; import { CATEGORY_ICON_MAP, FREQUENTLY_USED_KEY } from './constants';
...@@ -34,7 +35,7 @@ async function loadEmoji() { ...@@ -34,7 +35,7 @@ async function loadEmoji() {
async function loadEmojiWithNames() { async function loadEmojiWithNames() {
return Object.entries(await loadEmoji()).reduce((acc, [key, value]) => { return Object.entries(await loadEmoji()).reduce((acc, [key, value]) => {
acc[key] = { ...value, name: key }; acc[key] = { ...value, name: key, e: sanitize(value.e) };
return acc; return acc;
}, {}); }, {});
......
...@@ -49,6 +49,11 @@ export const emojiFixtureMap = { ...@@ -49,6 +49,11 @@ export const emojiFixtureMap = {
unicodeVersion: '5.1', unicodeVersion: '5.1',
description: 'white medium star', description: 'white medium star',
}, },
xss: {
moji: '<img src=x onerror=prompt(1)>',
unicodeVersion: '5.1',
description: 'xss',
},
}; };
export const mockEmojiData = Object.keys(emojiFixtureMap).reduce((acc, k) => { export const mockEmojiData = Object.keys(emojiFixtureMap).reduce((acc, k) => {
......
...@@ -9,6 +9,7 @@ import isEmojiUnicodeSupported, { ...@@ -9,6 +9,7 @@ import isEmojiUnicodeSupported, {
isHorceRacingSkinToneComboEmoji, isHorceRacingSkinToneComboEmoji,
isPersonZwjEmoji, isPersonZwjEmoji,
} from '~/emoji/support/is_emoji_unicode_supported'; } from '~/emoji/support/is_emoji_unicode_supported';
import { sanitize } from '~/lib/dompurify';
const emptySupportMap = { const emptySupportMap = {
personZwj: false, personZwj: false,
...@@ -379,7 +380,7 @@ describe('emoji', () => { ...@@ -379,7 +380,7 @@ describe('emoji', () => {
describe('searchEmoji', () => { describe('searchEmoji', () => {
const emojiFixture = Object.keys(mockEmojiData).reduce((acc, k) => { const emojiFixture = Object.keys(mockEmojiData).reduce((acc, k) => {
const { name, e, u, d } = mockEmojiData[k]; const { name, e, u, d } = mockEmojiData[k];
acc[k] = { name, e, u, d }; acc[k] = { name, e: sanitize(e), u, d };
return acc; return acc;
}, {}); }, {});
...@@ -397,6 +398,7 @@ describe('emoji', () => { ...@@ -397,6 +398,7 @@ describe('emoji', () => {
'heart', 'heart',
'custard', 'custard',
'star', 'star',
'xss',
].map((name) => { ].map((name) => {
return { return {
emoji: emojiFixture[name], emoji: emojiFixture[name],
...@@ -620,4 +622,13 @@ describe('emoji', () => { ...@@ -620,4 +622,13 @@ describe('emoji', () => {
expect(sortEmoji(scoredItems)).toEqual(expected); expect(sortEmoji(scoredItems)).toEqual(expected);
}); });
}); });
describe('sanitize emojis', () => {
it('should return sanitized emoji', () => {
expect(getEmojiInfo('xss')).toEqual({
...mockEmojiData.xss,
e: '<img src="x">',
});
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment