Skip to content
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
23 changes: 23 additions & 0 deletions browser/lib/markdown-it-sanitize-html.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
})
}
11 changes: 11 additions & 0 deletions browser/lib/markdown.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -46,6 +47,16 @@ var md = markdownit({
'</code></pre>'
}
})
// 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: {}
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"react-sortable-hoc": "^0.6.7",
"redux": "^3.5.2",
"sander": "^0.5.1",
"sanitize-html": "^1.18.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Redsandro

yarn.lock was not updated, could you please update to keep everyone in sync?

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rayou this branch was merged 2 days ago. You'll have to create a PR upstream.

Please note that I am using the npm workflow. I don't know what yarn is. I just git push what was updated. If this creates a mismatch, perhaps some automation should be written.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take care of it.

"striptags": "^2.2.1",
"superagent": "^1.2.0",
"superagent-promise": "^1.0.3"
Expand Down