diff --git a/browser/lib/markdown-it-sanitize-html.js b/browser/lib/markdown-it-sanitize-html.js
new file mode 100644
index 00000000..beec9566
--- /dev/null
+++ b/browser/lib/markdown-it-sanitize-html.js
@@ -0,0 +1,23 @@
+'use strict'
+
+import sanitizeHtml from 'sanitize-html'
+
+module.exports = function sanitizePlugin (md, options) {
+ options = options || {}
+
+ md.core.ruler.after('linkify', 'sanitize_inline', state => {
+ for (let tokenIdx = 0; tokenIdx < state.tokens.length; tokenIdx++) {
+ if (state.tokens[tokenIdx].type === 'html_block') {
+ state.tokens[tokenIdx].content = sanitizeHtml(state.tokens[tokenIdx].content, options)
+ }
+ if (state.tokens[tokenIdx].type === 'inline') {
+ const inlineTokens = state.tokens[tokenIdx].children
+ for (let childIdx = 0; childIdx < inlineTokens.length; childIdx++) {
+ if (inlineTokens[childIdx].type === 'html_inline') {
+ inlineTokens[childIdx].content = sanitizeHtml(inlineTokens[childIdx].content, options)
+ }
+ }
+ }
+ }
+ })
+}
diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js
index d0801a1b..b97f9d56 100644
--- a/browser/lib/markdown.js
+++ b/browser/lib/markdown.js
@@ -1,4 +1,5 @@
import markdownit from 'markdown-it'
+import sanitize from './markdown-it-sanitize-html'
import emoji from 'markdown-it-emoji'
import math from '@rokt33r/markdown-it-math'
import _ from 'lodash'
@@ -46,6 +47,16 @@ var md = markdownit({
''
}
})
+// Sanitize use rinput before other plugins
+md.use(sanitize, {
+ allowedTags: ['img', 'iframe'],
+ allowedAttributes: {
+ '*': ['alt', 'style'],
+ 'img': ['src', 'width', 'height'],
+ 'iframe': ['src', 'width', 'height', 'frameborder', 'allowfullscreen']
+ },
+ allowedIframeHostnames: ['www.youtube.com']
+})
md.use(emoji, {
shortcuts: {}
})
diff --git a/package.json b/package.json
index ff2d280b..6b90ade9 100644
--- a/package.json
+++ b/package.json
@@ -85,6 +85,7 @@
"react-sortable-hoc": "^0.6.7",
"redux": "^3.5.2",
"sander": "^0.5.1",
+ "sanitize-html": "^1.18.2",
"striptags": "^2.2.1",
"superagent": "^1.2.0",
"superagent-promise": "^1.0.3"