Skip to content

Commit

Permalink
[FIX] Server-side marked parsing (#20665)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Feb 10, 2021
1 parent a06735f commit a875da3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/markdown/lib/parser/marked/marked.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import _ from 'underscore';
import _marked from 'marked';
Expand Down Expand Up @@ -106,7 +107,15 @@ export const marked = (message, {
highlight,
});

message.html = dompurify.sanitize(message.html, { ADD_ATTR: ['target'] });
if (Meteor.isServer) {
const { JSDOM } = require('jsdom');
const createDOMPurify = require('dompurify');
const { window } = new JSDOM('');
const serverDomPurify = createDOMPurify(window);
message.html = serverDomPurify.sanitize(message.html, { ADD_ATTR: ['target'] });
} else {
message.html = dompurify.sanitize(message.html, { ADD_ATTR: ['target'] });
}

return message;
};

0 comments on commit a875da3

Please sign in to comment.