Don't render non HTTP links, images and quotes

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-12-15 17:07:07 +01:00
parent 832007a993
commit a21dfdf8e7
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
1 changed files with 47 additions and 1 deletions

View File

@ -19,6 +19,8 @@ Handlebars.registerHelper('level', function() {
OC.Settings = OC.Settings || {}; OC.Settings = OC.Settings || {};
OC.Settings.Apps = OC.Settings.Apps || { OC.Settings.Apps = OC.Settings.Apps || {
markedOptions: {},
setupGroupsSelect: function($elements) { setupGroupsSelect: function($elements) {
OC.Settings.setupGroupsSelect($elements, { OC.Settings.setupGroupsSelect($elements, {
placeholder: t('core', 'All') placeholder: t('core', 'All')
@ -187,7 +189,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
} }
// Parse markdown in app description // Parse markdown in app description
app.description = marked(app.description.trim()); app.description = marked(app.description.trim(), OC.Settings.Apps.markedOptions);
var html = template(app); var html = template(app);
if (selector) { if (selector) {
@ -636,6 +638,50 @@ OC.Settings.Apps = OC.Settings.Apps || {
* Initializes the apps list * Initializes the apps list
*/ */
initialize: function($el) { initialize: function($el) {
var renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
try {
var prot = decodeURIComponent(unescape(href))
.replace(/[^\w:]/g, '')
.toLowerCase();
} catch (e) {
return '';
}
if (prot.indexOf('http:') !== 0 && prot.indexOf('https:') !== 0) {
return '';
}
var out = '<a href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
}
out += '>' + text + '</a>';
return out;
};
renderer.image = function(href, title, text) {
if (text) {
return text;
}
return title;
};
renderer.blockquote = function(quote) {
return quote;
};
OC.Settings.Apps.markedOptions = {
renderer: renderer,
gfm: false,
highlight: false,
tables: false,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
};
OC.Plugins.register('OCA.Search', OC.Settings.Apps.Search); OC.Plugins.register('OCA.Search', OC.Settings.Apps.Search);
OC.Settings.Apps.loadCategories(); OC.Settings.Apps.loadCategories();
OC.Util.History.addOnPopStateHandler(_.bind(this._onPopState, this)); OC.Util.History.addOnPopStateHandler(_.bind(this._onPopState, this));