- Security fix (Imagelib): Avoid XSS (fixes #288)

- Fix (Imagelib): `dropXMLInternalSubset` misspelled
This commit is contained in:
Brett Zamir
2018-09-25 02:06:51 +08:00
parent 11baad0402
commit a22895c53a
2 changed files with 19 additions and 8 deletions

View File

@@ -5,6 +5,7 @@
messages in case from untrusted sources messages in case from untrusted sources
- Security fix/Breaking change (xdomain): Namespace xdomain file to avoid - Security fix/Breaking change (xdomain): Namespace xdomain file to avoid
it being used to modify non-xdomain storage it being used to modify non-xdomain storage
- Security fix (Imagelib): Avoid XSS
- Security fix (Imagelib): Expose `dropXMLInternalSubset` to extensions - Security fix (Imagelib): Expose `dropXMLInternalSubset` to extensions
for preventing billion laughs attack (and use in Imagelib) for preventing billion laughs attack (and use in Imagelib)
- Security fix (minor): For embedded API, avoid chance for arbitrary - Security fix (minor): For embedded API, avoid chance for arbitrary

View File

@@ -9,7 +9,7 @@
*/ */
export default { export default {
name: 'imagelib', name: 'imagelib',
async init ({decode64, importLocale, dropXMLInteralSubset}) { async init ({decode64, importLocale, dropXMLInternalSubset}) {
const imagelibStrings = await importLocale(); const imagelibStrings = await importLocale();
const svgEditor = this; const svgEditor = this;
@@ -107,7 +107,7 @@ export default {
$('#dialog_box').hide(); $('#dialog_box').hide();
}); });
} else { } else {
entry = $('<div>' + message + '</div>').data('id', curMeta.id); entry = $('<div>').text(message).data('id', curMeta.id);
preview.append(entry); preview.append(entry);
curMeta.entry = entry; curMeta.entry = entry;
} }
@@ -173,15 +173,20 @@ export default {
title = curMeta.name; title = curMeta.name;
} else { } else {
// Try to find a title // Try to find a title
// `dropXMLInteralSubset` is to help prevent the billion laughs attack // `dropXMLInternalSubset` is to help prevent the billion laughs attack
const xml = new DOMParser().parseFromString(dropXMLInteralSubset(response), 'text/xml').documentElement; // lgtm [js/xml-bomb] const xml = new DOMParser().parseFromString(dropXMLInternalSubset(response), 'text/xml').documentElement; // lgtm [js/xml-bomb]
title = $(xml).children('title').first().text() || '(SVG #' + response.length + ')'; title = $(xml).children('title').first().text() || '(SVG #' + response.length + ')';
} }
if (curMeta) { if (curMeta) {
preview.children().each(function () { preview.children().each(function () {
if ($(this).data('id') === id) { if ($(this).data('id') === id) {
if (curMeta.preview_url) { if (curMeta.preview_url) {
$(this).html('<img src="' + curMeta.preview_url + '">' + title); $(this).html(
$('<span>').append(
$('<img>').attr('src', curMeta.preview_url),
document.createTextNode(title)
)
);
} else { } else {
$(this).text(title); $(this).text(title);
} }
@@ -189,7 +194,9 @@ export default {
} }
}); });
} else { } else {
preview.append('<div>' + title + '</div>'); preview.append(
$('<div>').text(title)
);
submit.removeAttr('disabled'); submit.removeAttr('disabled');
} }
} else { } else {
@@ -197,9 +204,12 @@ export default {
title = curMeta.name || ''; title = curMeta.name || '';
} }
if (curMeta && curMeta.preview_url) { if (curMeta && curMeta.preview_url) {
entry = '<img src="' + curMeta.preview_url + '">' + title; entry = $('<span>').append(
$('<img>').attr('src', curMeta.preview_url),
document.createTextNode(title)
);
} else { } else {
entry = '<img src="' + response + '">'; entry = $('<img>').attr('src', response);
} }
if (curMeta) { if (curMeta) {