Sanitize HTML rendered from Markdown (#39)

This commit is contained in:
Jonatan Kłosko 2021-02-17 17:16:16 +01:00 committed by GitHub
parent f2f121a63b
commit 13f9b2b509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import marked from "marked";
import morphdom from "morphdom";
import DOMPurify from 'dompurify';
/**
* Renders markdown content in the given container.
@ -28,9 +29,10 @@ class Markdown {
__getHtml() {
const html = marked(this.content);
const sanitizedHtml = DOMPurify.sanitize(html);
if (html) {
return html;
if (sanitizedHtml) {
return sanitizedHtml;
} else {
return `
<div class="text-gray-300">

View file

@ -4109,6 +4109,11 @@
}
}
},
"dompurify": {
"version": "2.2.6",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.2.6.tgz",
"integrity": "sha512-7b7ZArhhH0SP6W2R9cqK6RjaU82FZ2UPM7RO8qN1b1wyvC/NY1FNWcX1Pu00fFOAnzEORtwXe4bPaClg6pUybQ=="
},
"domutils": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-1.7.0.tgz",

View file

@ -10,6 +10,7 @@
"test:watch": "jest"
},
"dependencies": {
"dompurify": "^2.2.6",
"marked": "^1.2.8",
"monaco-editor": "^0.21.2",
"morphdom": "^2.6.1",