Skip to content

Commit 0e9e7d6

Browse files
authored
Merge pull request #2191 from BoostIO/fix-codefence-xss
Add sanitization for code fence
2 parents aebed4a + 1d9b3ac commit 0e9e7d6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

browser/components/MarkdownPreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ export default class MarkdownPreview extends React.Component {
449449
value = value.replace(codeBlock, htmlTextHelper.encodeEntities(codeBlock))
450450
})
451451
}
452-
let renderedHTML = this.markdown.render(value)
452+
const renderedHTML = this.markdown.render(value)
453453
attachmentManagement.migrateAttachments(renderedHTML, storagePath, noteKey)
454454
this.refs.root.contentWindow.document.body.innerHTML = attachmentManagement.fixLocalURLS(renderedHTML, storagePath)
455455

browser/lib/markdown-it-sanitize-html.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module.exports = function sanitizePlugin (md, options) {
1010
if (state.tokens[tokenIdx].type === 'html_block') {
1111
state.tokens[tokenIdx].content = sanitizeHtml(state.tokens[tokenIdx].content, options)
1212
}
13+
if (state.tokens[tokenIdx].type === 'fence') {
14+
state.tokens[tokenIdx].content = state.tokens[tokenIdx].content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
15+
}
1316
if (state.tokens[tokenIdx].type === 'inline') {
1417
const inlineTokens = state.tokens[tokenIdx].children
1518
for (let childIdx = 0; childIdx < inlineTokens.length; childIdx++) {

0 commit comments

Comments
 (0)