Skip to content

Commit 6d1da9a

Browse files
authored
Merge pull request #4116 from maxceem/hotfix/sanitize-message-html
[HOTFIX] [PROD] Sanitze message text HTML
2 parents be3a830 + 3764218 commit 6d1da9a

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

package-lock.json

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@
147147
"redux-promise-middleware": "4.2.1",
148148
"redux-segment": "^1.6.2",
149149
"redux-thunk": "^2.1.0",
150-
"remarkable": "^1.7.1",
150+
"remarkable": "^1.7.4",
151+
"sanitize-html": "^1.27.4",
151152
"svg-react-loader": "^0.4.5",
152153
"tc-accounts": "git+https://github.com/appirio-tech/accounts-app.git#v1.0.4",
153154
"tc-ui": "git+https://github.com/appirio-tech/tc-ui.git#feature/connectv2",

src/helpers/markdownToState.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {convertFromRaw} from 'draft-js'
2+
import sanitizeHtml from 'sanitize-html'
23
const Remarkable = require('remarkable')
34

45
// Block level items, key is Remarkable's key for them, value returned is
@@ -218,7 +219,11 @@ export function markdownToHTML(markdown) {
218219
// typographer: true,
219220
})
220221
// Replace the BBCode [u][/u] to markdown '++' for underline style
221-
const _markdown = markdown.replace(new RegExp('\\[/?u\\]', 'g'), '++')
222+
let _markdown = markdown.replace(new RegExp('\\[/?u\\]', 'g'), '++')
223+
_markdown = sanitizeHtml(_markdown, {
224+
allowedTags: [ 'blockquote', 'p', 'a', 'ul', 'ol', 'li', 'b', 'i', 'strong', 'em', 'strike', 'abbr', 'code', 'br', 'pre' ],
225+
disallowedTagsMode: 'escape'
226+
})
222227
return md.render(_markdown, {}) // remarkable js takes markdown and makes it an array of style objects for us to easily parse
223228
}
224229

0 commit comments

Comments
 (0)