Ghost/ghost/admin/helpers/gh-format-markdown.js
Sebastian Gierlinger d40f545106 Add XSS prevention
closes #3387
- added placeholder for <script> and <iframe>
- added google-caja sanitizer
- changed title in posts overview to ‚double-stash‘
2014-07-27 23:03:01 +02:00

21 lines
814 B
JavaScript

/* global Showdown, Handlebars, html_sanitize*/
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
var showdown = new Showdown.converter({extensions: ['ghostimagepreview', 'ghostgfm']});
var formatMarkdown = Ember.Handlebars.makeBoundHelper(function (markdown) {
var html = '';
// replace script and iFrame
markdown = markdown.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '```\nEmbedded JavaScript\n```');
markdown = markdown.replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi, '```\nEmbedded IFrame\n```');
// convert markdown to HTML
html = showdown.makeHtml(markdown || '');
// sanitize html
html = html_sanitize(html, cajaSanitizers.url, cajaSanitizers.id);
return new Handlebars.SafeString(html);
});
export default formatMarkdown;