CVE-2021-41132 (published 2021-10-14T16:15Z)

OMERO.web provides a web based client and plugin infrastructure. In versions prior to 5.11.0, a variety of templates do not perform proper sanitization through HTML escaping. Due to the lack of sanitization and use of ``jQuery.html()``, there are a whole host of cross-site scripting possibilities with specially crafted input to a variety of fields. This issue is patched in version 5.11.0. There are no known workarounds aside from upgrading.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:P/A:N)
CVSS v3 base score: 6.1, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/ome/omero-web
commit_details: repo_url: https://github.com/ome/omero-web
author: Chris Allan
author_date: 2021-09-07 09:35:47+01:00
msg: Fix issues with inconsistency in input sanitisation leading to XSS vectors
repository: repo_url: https://github.com/ome/omero-web
repo_name: ome/omero-web
description: Django-based OMERO.web client
repo_language: Python
owner: ome
file_changes: filename: CHANGELOG.md
change_type: ModificationType.MODIFY
diff: @@ -1,4 +1,10 @@
 
+5.11.0 (October 2021)
+---------------------
+
+- Security vulnerability fixes for
+  [2021-SV3](https://www.openmicroscopy.org/security/advisories/2021-SV3)
+
 5.11.0.rc1 (September 2021)
 ---------------------------
 

programming_language: Markdown
filename: drivespaceStats.js
change_type: ModificationType.MODIFY
diff: @@ -18,7 +18,7 @@
                 for(i=0; i<chart_data.length; i++) {
                     rowData = chart_data[i];
                     rowId = typeof rowData.userId != 'undefined' ? rowData.userId : rowData.groupId;
-                    tableRows.push('<tr><td class="link">' + rowData.label + '(id:'+ rowId +')</td>');
+                    tableRows.push('<tr><td class="link">' + rowData.label.escapeHTML() + '(id:'+ rowId +')</td>');
                     tableRows.push('<td class="link">' + rowData.data.filesizeformat() + '</td></tr>');
                 }
                 
@@ -50,6 +50,7 @@
 
                     for(i=0; i<data.length; i++) {
                         var slice = data[i];
+                        slice.label = slice.label.escapeHTML();
                         if(i === MAX_SLICES){
                             chart_data.push({label:'Others', data:slice.data});
                         } else if (i > MAX_SLICES) {

programming_language: JavaScript
filename: ome.chgrp.js
change_type: ModificationType.MODIFY
diff: @@ -62,7 +62,7 @@ $(function() {
             data_owners = data.owners;  // save for later
             var ownernames = [];
             for (var o=0; o<data.owners.length; o++) {ownernames.push(data.owners[o][1]);}
-            var headerTxt = "<p>Move data owned by " + ownernames.join(", ") + ".</p>" +
+            var headerTxt = "<p>Move data owned by " + ownernames.join(", ").escapeHTML() + ".</p>" +
                             "<h1>Please choose target group below:</h1>";
             $group_chooser.append(headerTxt);
 
@@ -72,7 +72,7 @@ $(function() {
                 var g = data.groups[i];
                 html += "<div class='chgrpGroup' data-gid='"+ g.id + "'>";
                 html += "<img src='" + permsIcon(g.perms) + "'/>";
-                html += g.name + "<hr></div>";
+                html += g.name.escapeHTML() + "<hr></div>";
             }
             // If no target groups found...
             if (data.groups.length === 0) {
@@ -407,7 +407,7 @@ $(function() {
             if (count === 1) otype = otype.slice(0, -1);  // remove s
             var namesList = [], names;
             unlinked.forEach(function (u) {
-                namesList.push(u.name);
+                namesList.push(u.name.escapeHTML());
             });
             names = namesList.join(", ");
             names = " <i title='" + namesList.join("\n") + "'>(" + names.slice(0, 40) + (names.length > 40 ? "..." : "") + ")</i>";

programming_language: JavaScript
filename: ome.chown.js
change_type: ModificationType.MODIFY
diff: @@ -37,7 +37,7 @@ $(function() {
     var templateText = `
         <!-- Hidden fields for objects. e.g. name='Image' value='1,2,3' -->
         <% _.each(selobjs, function(obj, idx) { %>
-            <input name='<%= obj.split("=")[0] %>' value='<%= obj.split("=")[1] %>' hidden/>
+            <input name='<%- obj.split("=")[0] %>' value='<%- obj.split("=")[1] %>' hidden/>
         <% }) %>
 
         <!-- List target new owners -->
@@ -50,7 +50,7 @@ $(function() {
             <% _.each(exps, function(exp, idx) { %>
                 <label>
                     <input name='owner_id' type='radio' value='<%= exp['@id'] %>'/>
-                    <%= exp.FirstName%> <%= exp.LastName %> 
+                    <%- exp.FirstName%> <%- exp.LastName %>
                 </label>
                 <br/>
             <% }) %>

programming_language: JavaScript
filename: ome.right_panel_comments_pane.js
change_type: ModificationType.MODIFY
diff: @@ -110,7 +110,6 @@ var CommentsPane = function CommentsPane($element, opts) {
                         ann.link.owner = experimenters[ann.link.owner.id];
                     }
                     ann.addedBy = [ann.link.owner.id];
-                    ann.textValue = _.escape(ann.textValue);
                     return ann;
                 });
 

programming_language: JavaScript
filename: ome.right_panel_customanns_pane.js
change_type: ModificationType.MODIFY
diff: @@ -88,7 +88,7 @@ var CustomAnnsPane = function CustomAnnsPane($element, opts) {
                     var attrs = ['textValue', 'timeValue', 'termValue', 'longValue', 'doubleValue', 'boolValue'];
                     attrs.forEach(function(a){
                         if (ann[a] !== undefined){
-                            ann.value = _.escape(ann[a]);
+                            ann.value = ann[a];
                         }
                     });
                     if (objects.length > 1) {

programming_language: JavaScript
filename: ome.right_panel_fileanns_pane.js
change_type: ModificationType.MODIFY
diff: @@ -164,7 +164,6 @@ var FileAnnsPane = function FileAnnsPane($element, opts) {
                     }
                     // AddedBy IDs for filtering
                     ann.addedBy = [ann.link.owner.id];
-                    ann.description = _.escape(ann.description);
                     ann.file.size = ann.file.size !== null ? ann.file.size.filesizeformat() : "";
                     return ann;
                 });

programming_language: JavaScript
filename: ome.right_panel_tags_pane.js
change_type: ModificationType.MODIFY
diff: @@ -143,8 +143,8 @@ var TagPane = function TagPane($element, opts) {
                     }
                     // AddedBy IDs for filtering
                     tag.addedBy = [tag.link.owner.id];
-                    tag.textValue = _.escape(tag.textValue);
-                    tag.description = _.escape(tag.description);
+                    tag.textValue = tag.textValue;
+                    tag.description = tag.description;
                     tag.canRemove = tag.link.permissions.canDelete;
                     return tag;
                 });
@@ -158,7 +158,7 @@ var TagPane = function TagPane($element, opts) {
                         var tagId = tag.id,
                             linkOwner = tag.link.owner.id;
                         if (summary[tagId] === undefined) {
-                            summary[tagId] = {'textValue': tag.textValue,
+                            summary[tagId] = {'textValue': _.escape(tag.textValue),
                                               'id': tag.id,
                                               'canRemove': false,
                                               'canRemoveCount': 0,

programming_language: JavaScript
filename: ome.tagging_form.js
change_type: ModificationType.MODIFY
diff: @@ -98,8 +98,9 @@ var tagging_form = function(
         for (var id in all_tags) {
             var tag = all_tags[id];
             if (tag && !(id in child_tags)) {
-                html += create_tag_html(tag.t, tag.d, owners[tag.o], tag.i,
-                                        null, tag.s !== 0);
+                html += create_tag_html(
+                    tag.t, tag.d, tag.i, null, tag.s !== 0
+                );
                 tag.sort_key = tag.t.toLowerCase();
                 if (tag.s) {
                     for (var sid in tag.s) {
@@ -108,8 +109,8 @@ var tagging_form = function(
                             child.sort_key = (tag.t.toLowerCase() +
                                 child.t.toLowerCase());
                             html += create_tag_html(
-                                child.t, child.d, owners[child.o], child.i,
-                                tag.i);
+                                child.t, child.d, child.i, tag.i
+                            );
                         }
                     }
                 }
@@ -118,15 +119,7 @@ var tagging_form = function(
         div_all_tags.append(html);
         // TODO This tooltip application is used until the extra data has loaded
         // at which point the tooltips are updated and this handler is replaced?
-        $(".tag_selection div").on('click', tag_click).tooltip({
-            track: false,
-            show: false,
-            hide: false,
-            items: '[data-content]',
-            content: function() {
-                return $(this).data('content');
-            }
-        });
+        $(".tag_selection div").on('click', tag_click);
     };
 
     var update_selected_labels = function() {
@@ -145,7 +138,7 @@ var tagging_form = function(
         if (tagset) {
             $("#id_selected_tag_set").html(
                 "Add a new tag in <span class='tagset-title'>" +
-                tagset.text() + "</span> tag set and select it immediately:");
+                tagset.text().escapeHTML() + "</span> tag set and select it immediately:");
         } else {
             $("#id_selected_tag_set").text(
                 "Add a new tag and select it immediately:");
@@ -169,6 +162,7 @@ var tagging_form = function(
             track: false,
             show: false,
             hide: false,
+            items: '[data-id]',  // Just needs an attribute that exists
             content: title
         });
     };
@@ -369,45 +363,35 @@ var tagging_form = function(
         }
     };
 
-    var encode_html = function(text) {
-        return $('<div/>').text(text).html();
-    };
-
     var create_tag_title = function(description, owner, tagset, link_owner) {
         var title = "";
         if (owner) {
-            title += "<b>Owner:</b> " + owner + "<br />";
+            title += "<b>Owner:</b> " + owner.escapeHTML() + "<br />";
         }
         if (link_owner) {
-            title += "<b>Linked by:</b> " + link_owner + "<br />";
+            title += "<b>Linked by:</b> " + link_owner.escapeHTML() + "<br />";
         }
         if (description) {
-            title += "<b>Description:</b> " + description + "<br />";
+            title += "<b>Description:</b> " + description.escapeHTML() + "<br />";
         }
         if (tagset) {
-            title += "<b>Tag set:</b> " + tagset + "<br />";
+            title += "<b>Tag set:</b> " + tagset.escapeHTML() + "<br />";
         }
         return title;
     };
 
-    var create_tag_html = function(text, description, owner, id, parent_id,
+    var create_tag_html = function(text, description, id, parent_id,
                                    is_tagset) {
         var cls = is_tagset ? "alltags-tagset" :
             (parent_id ? "alltags-childtag" : "alltags-tag");
         var html = "<div class='" + cls + "' data-id='" + id + "'";
-        var tagset;
         if (parent_id) {
             html += " data-set='" + parent_id + "'";
-            tagset = all_tags[parent_id].t;
         }
         if (id < 0) { // new tag, save description
-            html += " data-description='" + encode_html(description) + "'";
+            html += " data-description='" + description.escapeHTML() + "'";
         }
-        var title = create_tag_title(description, owner, tagset);
-        // Add content even if it is empty
-        // and handle case for no tooltip in the tooltip code
-        html += " data-content='" + title.replace(/'/g, "&#39;") + "'";
-        html += ">" + encode_html(text) + "</div>";
+        html += ">" + text.escapeHTML() + "</div>";
         return html;
     };
 
@@ -633,7 +617,7 @@ var tagging_form = function(
             new_tag_counter -= 1;
             var tagset_id = (tagset ? parseInt(tagset.attr('data-id'), 10) :
                              false);
-            owners[me] = owners[me] || my_name;
+            owners[me] = owners[me] || _.unescape(my_name);
             all_tags[new_tag_counter] = {
                 i: new_tag_counter,
                 d: description,
@@ -644,16 +628,18 @@ var tagging_form = function(
                            '') + text.toLowerCase()
             };
             var div = $(create_tag_html(
-                text, description, my_name, new_tag_counter,
+                text, description, new_tag_counter,
                 tagset ? tagset.attr('data-id') : null));
+            var title = create_tag_title(
+                description, _.unescape(my_name),
+                tagset_id? all_tags[tagset_id].t : null
+            );
             div.addClass('ui-selected').on('click', tag_click).tooltip({
                 track: true,
                 show: false,
                 hide: false,
-                items: '[data-content]',
-                content: function() {
-                    return $(this).data('content');
-                }
+                items: '[data-id]',  // Just needs an attribute that exists
+                content: title
             });
             $("div.ui-selected", div_selected_tags).removeClass('ui-selected');
             div_selected_tags.append(div);

programming_language: JavaScript
filename: ome.thumbnail_figure.js
change_type: ModificationType.MODIFY
diff: @@ -201,7 +201,7 @@ $(document).ready(function() {
                         // start a new container...
                         topLevelTag = tagData.tags[0] || tagsText;      // Group under 1st tag (unless we have no tags)
 
-                        $tr = $('<tr><th><h2>' + topLevelTag + '</h2></th></tr>');
+                        $tr = $('<tr><th><h2>' + topLevelTag.escapeHTML() + '</h2></th></tr>');
                         $tr.appendTo($this);
                         $td = $('<td></td>').appendTo($tr);
                     }
@@ -263,4 +263,4 @@ $(document).ready(function() {
         }
     });
 
-});
\ No newline at end of file
+});

programming_language: JavaScript
filename: comments_underscore.html
change_type: ModificationType.MODIFY
diff: @@ -1,36 +1,36 @@
 <% _.each(anns, function(ann) { %>
-<div class="ann_comment_wrapper" data-added-by="<% print (ann.addedBy.join(',')) %>">
+<div class="ann_comment_wrapper" data-added-by="<% print(_.escape(ann.addedBy.join(','))) %>">
 
     <div class="avatar">
-        <img src="<%= webindex %>avatar/<%= ann.owner.id %>/"
-        alt="<%= ann.owner.firstName %> <%= ann.owner.lastName %>"
-        title="<%= ann.owner.firstName %> <%= ann.owner.lastName %>" />
+        <img src="<%= webindex %>avatar/<%- ann.owner.id %>/"
+        alt="<%- ann.owner.firstName %> <%- ann.owner.lastName %>"
+        title="<%- ann.owner.firstName %> <%- ann.owner.lastName %>" />
     </div>
 
     <div class="ann_comment_text tooltip">
         <div class="ann_comment_header">
             <strong>
-                <%= ann.owner.firstName %> <%= ann.owner.lastName %>
-            </strong> 
+                <%- ann.owner.firstName %> <%- ann.owner.lastName %>
+            </strong>
             at
             <% print(OME.formatDate(ann.link.date)) %>
         </div>
-    
+
         <% if (ann.permissions.canDelete) { %>
-            <img class='removeComment' id="<%= ann.id %>-comment"
+            <img class='removeComment' id="<%- ann.id %>-comment"
                 src="<%= static %>image/icon_basic_delete.png"
-                url='<%= webindex %>action/remove/comment/<%= ann.id %>/' 
+                url='<%= webindex %>action/remove/comment/<%- ann.id %>/'
                 title="Delete comment"/>
         <% } %>
 
-        <div class='commentText'><%= ann.textValue %></div>
+        <div class='commentText'><%- ann.textValue %></div>
     </div>
 
     <% if (ann.ns || ann.description) { %>
     <span class="tooltip_html" style='display:none'>
-        <b>ID:</b> <%= ann.id %><br />
-        <% if (ann.ns) { %><b>Namespace:</b> <%= ann.ns %><br /><% } %>
-        <% if (ann.description) { %><b>Description:</b> <%= ann.description %><br /><% } %>
+        <b>ID:</b> <%- ann.id %><br />
+        <% if (ann.ns) { %><b>Namespace:</b> <%- ann.ns %><br /><% } %>
+        <% if (ann.description) { %><b>Description:</b> <%- ann.description %><br /><% } %>
     </span>
     <% } %>
 

programming_language: HTML
filename: customanns_underscore.html
change_type: ModificationType.MODIFY
diff: @@ -1,31 +1,31 @@
 
 <% _.each(anns, function(ann) { %>
 
-<tr data-added-by="<% print (ann.addedBy.join(',')) %>">
-    <th><%= ann.type %></th>
+<tr data-added-by="<% print(_.escape(ann.addedBy.join(','))) %>">
+    <th><%- ann.type %></th>
     <td>
         <div class="tooltip">
         <% if (ann.type === 'Xml') { %>
-            <div><% print((ann.value + "").slice(0, 20)) %>...</div>
+            <div><% print(_.escape((ann.value + "").slice(0, 20))) %>...</div>
             <div class="show_xml">Open in new window</div>
-            <div style="display: none"><%= ann.value %></div>
+            <div style="display: none"><%- ann.value %></div>
         <% } else { %>
-            <div><%= ann.value %></div>
+            <div><%- ann.value %></div>
         <% } %>
         </div>
-        
+
         <span class="tooltip_html" style='display:none'>
-            <b>ID:</b> <%= ann.id %><br />
-            <% if (ann.ns) { %><b>Namespace:</b> <%= ann.ns %><br /><% } %>
-            <% if (ann.description) { %><b>Description:</b> <%= ann.description %><br /><% } %>
-            <b>Owner:</b> <%= ann.owner.firstName %> <%= ann.owner.lastName %><br />
+            <b>ID:</b> <%- ann.id %><br />
+            <% if (ann.ns) { %><b>Namespace:</b> <%- ann.ns %><br /><% } %>
+            <% if (ann.description) { %><b>Description:</b> <%- ann.description %><br /><% } %>
+            <b>Owner:</b> <%- ann.owner.firstName %> <%- ann.owner.lastName %><br />
             <b>Date:</b> <% print(OME.formatDate(ann.date)) %>
 
             <% if (ann.parent) { %>
             <br />
-            <b>Linked to:</b> <%= ann.parent.class %> <%= ann.parent.id %>
+            <b>Linked to:</b> <%- ann.parent.class %> <%- ann.parent.id %>
             <% } %>
         </span>
     </td>
 </tr>
-<% }) %>
\ No newline at end of file
+<% }) %>

programming_language: HTML
filename: fileanns_underscore.html
change_type: ModificationType.MODIFY
diff: @@ -1,26 +1,26 @@
 
 <% _.each(anns, function(ann) { %>
 <li class="file_ann_wrapper"
-    id="file_ann-<%= ann.id %>"
-    data-added-by="<% print (ann.addedBy.join(',')) %>">
+    id="file_ann-<%- ann.id %>"
+    data-added-by="<% print(_.escape(ann.addedBy.join(','))) %>">
 
     <a class='tooltip'
         href="<% if (ann.permissions.canDownload) { print(webindex + 'annotation/' + ann.id)} else {print('#') } %>">
-        <%= ann.file.name %>
+        <%- ann.file.name %>
         <% if (ann.file.size) { %>
-            <span>(<%= ann.file.size %>)</span>
+            <span>(<%- ann.file.size %>)</span>
         <% } %>
     </a>
 
     <span class="tooltip_html" style='display:none'>
         <!-- show different tooltip for batch_annotate panel -->
         <% if (ann.links) { %>
-            Can remove File from <b><%= ann.canRemoveCount %>
+            Can remove File from <b><%- ann.canRemoveCount %>
             object<% if(ann.canRemoveCount !== 1) {print('s')} %></b>:<br/>
             <% _.each(ann.links, function(link, idx) { %>
                 <div>
                     <% if (idx < 20) { %>
-                        <b><%= link.parent.class %> <%= link.parent.id %></b>
+                        <b><%- link.parent.class %> <%- link.parent.id %></b>
                         <% print(_.escape(link.parent.name).slice(0, 28)) %>
                         <% if (link.owner.id !== userId){
                             print("(" + link.owner.firstName.slice(0, 1) + " " + _.escape(link.owner.lastName) + ")")
@@ -31,18 +31,18 @@
                 </div>
             <% }) %>
         <% } else { %>
-            <b>Annotation ID:</b> <%= ann.id %><br />
-            <b>Owner:</b> <%= ann.owner.firstName %> <%= ann.owner.lastName %><br />
-            <b>Linked by:</b> <%= ann.link.owner.firstName %> <%= ann.link.owner.lastName %><br />
+            <b>Annotation ID:</b> <%- ann.id %><br />
+            <b>Owner:</b> <%- ann.owner.firstName %> <%- ann.owner.lastName %><br />
+            <b>Linked by:</b> <%- ann.link.owner.firstName %> <%- ann.link.owner.lastName %><br />
             <b>On:</b> <% print(OME.formatDate(ann.link.date)) %> <br />
-            <b>Description:</b> <%= ann.description %>
+            <b>Description:</b> <%- ann.description %>
             <% if (ann.ns){ %>
-                <br/><b>Namespace:</b> <%= ann.ns %>
+                <br/><b>Namespace:</b> <%- ann.ns %>
             <% } %>
             <% if (ann.file.mimetype){ %>
-                <br/><b>Mimetype:</b> <%= ann.file.mimetype %>
+                <br/><b>Mimetype:</b> <%- ann.file.mimetype %>
             <% } %>
-            <br/><b>File ID:</b> <%= ann.file.id %>
+            <br/><b>File ID:</b> <%- ann.file.id %>
         <% } %>
     </span>
 
@@ -50,19 +50,19 @@
         <input type="checkbox" style="display:none;"/>
         <% if ((ann.ns && ann.ns === 'openmicroscopy.org/omero/bulk_annotations') || ann.file.mimetype == 'OMERO.tables' ){ %>
             <a class='action btn_view' title="View OMERO.table" target="_blank"
-            href='<%= webindex %>omero_table/<%= ann.file.id %>/'>&nbsp;</a>
+            href='<%= webindex %>omero_table/<%- ann.file.id %>/'>&nbsp;</a>
         <% } %>
         <% if (ann.link.permissions.canDelete) { %> <!-- and not ann.isOriginalMetadata -->
-            <a class='removeFile action' id="<%= ann.id %>-file" title="Remove File"
-            href='<%= webindex %>action/remove/file/<%= ann.id %>/'>&#8211</a>
+            <a class='removeFile action' id="<%- ann.id %>-file" title="Remove File"
+            href='<%= webindex %>action/remove/file/<%- ann.id %>/'>&#8211</a>
         <% } %>
 
         <% if (ann.permissions.canDelete) { %> <!-- and not ann.isOriginalMetadata -->
-            <a id="<%= ann.id %>-file" type="image" class="deleteFile action" title="Delete File"
-                href="<%= webindex %>action/delete/file/<%= ann.id %>/"> &#215 </a>
+            <a id="<%- ann.id %>-file" type="image" class="deleteFile action" title="Delete File"
+                href="<%= webindex %>action/delete/file/<%- ann.id %>/"> &#215 </a>
         <% } %>
 
     </div>
 </li>
 
-<% }) %>
\ No newline at end of file
+<% }) %>

programming_language: R
filename: mapanns_underscore.html
change_type: ModificationType.MODIFY
diff: @@ -1,8 +1,8 @@
 <% _.each(anns, function(ann) { %>
 
 <table <% if (ann.id && ann.addedBy) { %>
-            data-annId="<%= ann.id %>"
-            data-added-by="<% print (ann.addedBy.join(',')) %>"
+            data-annId="<%- ann.id %>"
+            data-added-by="<% print(_.escape(ann.addedBy.join(','))) %>"
         <% } else { %>
             data-added-by="<%= WEBCLIENT.USER.id %>"
         <% } %>
@@ -11,56 +11,56 @@
             ">
     <thead>
       <% if (showNs && ann.ns) { %>
-      <tr title="<%= ann.ns %>">
+      <tr title="<%- ann.ns %>">
           <th colspan="2">
-              <%= ann.ns.slice(0, 50) %>
+              <%- ann.ns.slice(0, 50) %>
           </th>
       </tr>
       <% } %>
       <tr class="tooltip">
           <th colspan="2">
             <% if (ann.id) { %>
-                Added by: <%= ann.owner.firstName %> <%= ann.owner.lastName %>
+                Added by: <%- ann.owner.firstName %> <%- ann.owner.lastName %>
                 <% if (showParent && ann.link.parent.name){ %>
                   <br>
                   <% if (ann.parentNames) { %>
-                    <%= ann.parentNames.length %> Annotations linked to:
+                    <%- ann.parentNames.length %> Annotations linked to:
                   <% } else { %>
                     To:
                   <% } %>
-                  <%= ann.parentNames ? (ann.parentNames.length + " objects") : ann.link.parent.name %>
+                  <%- ann.parentNames ? (ann.parentNames.length + " objects") : ann.link.parent.name %>
                 <% } %>
 
                 <span class="tooltip_html" style='display:none'>
                     <% if (ann.parentNames) { %>
                       You are
                       <% print (ann.permissions.canEdit && clientMapAnn ? 'editing' : 'viewing') %>
-                      <b><%= ann.parentNames.length %></b> identical Key-Value annotations:
+                      <b><%- ann.parentNames.length %></b> identical Key-Value annotations:
                     <% } %>
                     <% if (!ann.parentNames && ann.link) { %>
                         <!-- If single object show e.g. Image ID: (slice ImageI -> Image) -->
-                        <b><%= ann.link.parent.class.slice(0, ann.link.parent.class.length-1) %>
-                            ID:</b> <%= ann.link.parent.id %><br />
+                        <b><%- ann.link.parent.class.slice(0, ann.link.parent.class.length-1) %>
+                            ID:</b> <%- ann.link.parent.id %><br />
                     <% } %>
                     <b>Annotation ID<% if (ann.parentNames) { %>s<% } %>:</b> <%= ann.id %><br />
                     <% if (ann.parentNames) { %>
                         <b>Linked to:</b><br>
                         <% _.each(ann.parentNames, function(pName) { %>
-                            &nbsp <%= pName %><br />
+                            &nbsp <%- pName %><br />
                         <% }) %>
                     <% } %>
                     <% if (ann.owner) { %>
-                        <b>Owner:</b> <%= ann.owner.firstName %> <%= ann.owner.lastName %>
+                        <b>Owner:</b> <%- ann.owner.firstName %> <%- ann.owner.lastName %>
                     <% } %>
                     <% if (ann.link) { %>
-                        <br /><b>Linked by:</b> <%= ann.link.owner.firstName %> <%= ann.link.owner.lastName %>
+                        <br /><b>Linked by:</b> <%- ann.link.owner.firstName %> <%- ann.link.owner.lastName %>
                         <% if (ann.link.date) { %>
                             <br /><b>On:</b> <% print(OME.formatDate(ann.link.date)) %>
                         <% } %>
                     <% } %>
                 </span>
             <% } else if (objCount && objCount > 1) { %>
-                Add annotations to <%= objCount %> objects
+                Add annotations to <%- objCount %> objects
                 <span class="tooltip_html" style='display:none'>
                     Identical Key-Value annotations will be added to each selected object.
                 </span>
@@ -80,8 +80,8 @@
     <% if (ann.id) { %>
       <% _.each(ann.values, function(row) { %>
         <tr>
-            <td><% print(_.escape(row['0'])) %></td>
-            <td><% print(_.escape(row['1'])) %></td>
+            <td><%- row['0'] %></td>
+            <td><%- row['1'] %></td>
         </tr>
       <% }) %>
     <% } else { %>

programming_language: HTML
filename: metadata_general.html
change_type: ModificationType.MODIFY
diff: @@ -359,10 +359,10 @@
                         var bulkAnnTooltip = "<span class='tooltip_html' style='display:none'>" +
                             "Data from tables file:<br />" +
                             "<b>File ID:</b> " + data.id + "<br />" +
-                            "<b>Owner:</b> " + data.owner + " <br />" +
+                            "<b>Owner:</b> " + data.owner.escapeHTML() + " <br />" +
                             "<b>Annotation ID:</b> " + data.annId + "<br />" +
                             "<b>Linked to:</b> " + data.parentType + " " + data.parentId + "<br />" +
-                            "<b>Linked by:</b> " + data.addedBy + " <br />" +
+                            "<b>Linked by:</b> " + data.addedBy.escapeHTML() + " <br />" +
                             "<b>On:</b> " + OME.formatDate(data.addedOn) + "</span>";
                         $("#bulk-annotations").append(bulkAnnTooltip);
                         $("#bulk-annotations").parent().tooltip({

programming_language: HTML
filename: tags_underscore.html
change_type: ModificationType.MODIFY
diff: @@ -1,17 +1,17 @@
 
 <% _.each(tags, function(tag) { %>
 <span class="tag_annotation_wrapper"
-    data-tag-id="<%= tag.id %>"
-    data-added-by="<% print (tag.addedBy.join(',')) %>">
-	
+    data-tag-id="<%- tag.id %>"
+    data-added-by="<% print(_.escape(tag.addedBy.join(','))) %>">
+
     <div class="tag">
-        <a class='tooltip tag_inner' href="?show=tag-<%= tag.id %>" target="_top">
-            <%= tag.textValue %>
+        <a class='tooltip tag_inner' href="?show=tag-<%- tag.id %>" target="_top">
+            <%- tag.textValue %>
         </a>
 
         <% if (tag.canRemove) { %>
-        <span class='removeTag' title="Remove Tag" id="<%= tag.id %>-tag"
-                url='<%= webindex %>action/remove/tag/<%= tag.id %>/'>
+        <span class='removeTag' title="Remove Tag" id="<%- tag.id %>-tag"
+                url='<%= webindex %>action/remove/tag/<%- tag.id %>/'>
                 -
         </span>
         <% } %>
@@ -19,13 +19,13 @@
         <span class="tooltip_html" style='display:none'>
         <!-- show different tooltip for batch_annotate panel -->
         <% if (tag.links) { %>
-            Can remove Tag from <b><%= tag.canRemoveCount %> object<% if(tag.canRemoveCount !== 1) {print('s')} %></b>:<br/>
+            Can remove Tag from <b><%- tag.canRemoveCount %> object<% if(tag.canRemoveCount !== 1) {print('s')} %></b>:<br/>
             <% _.each(tag.links, function(link, idx) { %>
                 <div>
                     <% if (idx < 20) { %>
-                        <b><%= link.parent.class %> <%= link.parent.id %></b>
-                        <% print(_.escape(link.parent.name).slice(0, 28)) %>
-                        <% if (link.owner.id !== userId){
+                        <b><%- link.parent.class %> <%- link.parent.id %></b>
+                        <%- link.parent.name.slice(0, 28) %>
+                        <% if (link.owner.id !== userId) {
                             print("(" + link.owner.firstName.slice(0, 1) + " " + _.escape(link.owner.lastName) + ")")
                         } %>
                     <% } else if (idx === 20) { %>
@@ -34,15 +34,15 @@
                 </div>
             <% }) %>
         <% } else { %>
-            <b>ID:</b> <%= tag.id %><br />
-            <b>Owner:</b> <%= tag.owner.firstName %> <%= tag.owner.lastName %><br />
-            <b>Linked by:</b> <%= tag.link.owner.firstName %> <%= tag.link.owner.lastName %><br />
+            <b>ID:</b> <%- tag.id %><br />
+            <b>Owner:</b> <%- tag.owner.firstName %> <%- tag.owner.lastName %><br />
+            <b>Linked by:</b> <%- tag.link.owner.firstName %> <%- tag.link.owner.lastName %><br />
             <b>On:</b> <% print(OME.formatDate(tag.link.date)) %><br />
-            <b>Description:</b> <%= tag.description %>
+            <b>Description:</b> <%- tag.description %>
         <% } %>
         </span>
     </div>
-    
+
 </span>
 
-<% }) %>
\ No newline at end of file
+<% }) %>

programming_language: R
filename: icon_thumbnails_underscore.html
change_type: ModificationType.MODIFY
diff: @@ -14,30 +14,30 @@
     <% _.each(images, function(img) { %>
         <li class="row <% if(img.selected) {print ('ui-selected')} %>
             <% if(img.fsSelected) {print ('fs-selected')} %> "
-            id="image_icon-<%= img.id %>"
-            data-fileset="<%= img.data.obj.filesetId %>"
+            id="image_icon-<%- img.id %>"
+            data-fileset="<%- img.data.obj.filesetId %>"
             data-type="image"
-            data-id="<%= img.id %>"
+            data-id="<%- img.id %>"
             data-perms="<%= img.data.obj.permsCss %>"
             tabindex="0"
-            <% if(img.shareId) { %> data-share="<%= img.shareId %>" <% }%>
+            <% if(img.shareId) { %> data-share="<%- img.shareId %>" <% }%>
             data-owned="">
 
             <div class="image">
                 <!-- we wrap img with <a> so you can right-click -> open link in new tab -->
-                <a href="<%= webindex %><% if(img.shareId) {print( img.shareId + '/')} %>img_detail/<%= img.id %>/<% if (dataset) print('?dataset=' + dataset) %>" >
+                <a href="<%= webindex %><% if(img.shareId) {print( img.shareId + '/')} %>img_detail/<%- img.id %>/<% if (dataset) print('?dataset=' + dataset) %>" >
                     <img/>
                 </a>
             </div>
             <!-- NB: '#image_icon-123 div.desc' etc is used to update name when changed in right panel via "editinplace" -->
             <div class="desc" valign="middle">
-                 <%= img.name %>
-                <span class="hidden_sort_text"> <%= img.name %> </span>
+                 <%- img.name %>
+                <span class="hidden_sort_text"> <%- img.name %> </span>
             </div>
-            <div class="date" valign="middle"><%= img.date %></div>
-            <div class="sizeX" valign="middle"><%= img.data.obj.sizeX %></div>
-            <div class="sizeY" valign="middle"><%= img.data.obj.sizeY %></div>
-            <div class="sizeZ" valign="middle"><%= img.data.obj.sizeZ %></div>
+            <div class="date" valign="middle"><%- img.date %></div>
+            <div class="sizeX" valign="middle"><%- img.data.obj.sizeX %></div>
+            <div class="sizeY" valign="middle"><%- img.data.obj.sizeY %></div>
+            <div class="sizeZ" valign="middle"><%- img.data.obj.sizeZ %></div>
         </li>
     <% }) %>
 </ul>
@@ -62,4 +62,4 @@
 
 </div>
 <div class="clear"> </div>
-<% } %>
\ No newline at end of file
+<% } %>

programming_language: HTML
filename: center_plugin.thumbs.js.html
change_type: ModificationType.MODIFY
diff: @@ -642,7 +642,7 @@ $(document).ready(function() {
             var html = tagList.map(function(t){
                 // don't show tags we're filtering by
                 if (filter_tag_ids.indexOf(t.id) > -1) return "";
-                return "<option value='" + t.id + "'>" + t.text + "</option>";
+                return "<option value='" + t.id + "'>" + t.text.escapeHTML() + "</option>";
             }).join("");
             html = "<option value='0'>Choose Tag</option>" + html;
             $("#filter_by_tag").html(html);
@@ -663,7 +663,7 @@ $(document).ready(function() {
             });
             // show tags
             var html = filter_tag_ids.map(function(tagId){
-                var tagText = usedTags[tagId].textValue;
+                var tagText = usedTags[tagId].textValue.escapeHTML();
                 return "<div class='tag' data-tagId='" + tagId + "'><a class='tag_inner' href='#'>" + tagText + "</a><span class='removeTag removefilter' title='Remove Tag'>-</span></div>";
             }).join("");
             $("#currentFilterTags").html(html);

programming_language: JavaScript
filename: plate.html
change_type: ModificationType.MODIFY
diff: @@ -267,7 +267,7 @@
                             if (selectImageIds && selectImageIds.indexOf(w.id) > -1) {
                                 cls = 'class="ui-selected"';
                             }
-                            html += '<li ' + cls + ' title="' + w.name + '" data-imageId="' + w.id + '">';
+                            html += '<li ' + cls + ' title="' + w.name.escapeHTML() + '" data-imageId="' + w.id + '">';
                             html += '<a href="{% url 'webindex' %}img_detail/' + w.id + '/">';
                             html += '<div class="wellSize"><img /></div>';
                             html += '</a></li>';

programming_language: JavaScript
filename: upload_script.html
change_type: ModificationType.MODIFY
diff: @@ -123,7 +123,7 @@
                 }
                 $('#targetInfo').show();
                 if (!chosen_file.endsWith(".py")) {
-                    $("#targetMessage").html("File: " + chosen_file + " not valid.<br/>File must be Python script (.py)");
+                    $("#targetMessage").html("File: " + chosen_file.escapeHTML() + " not valid.<br/>File must be Python script (.py)");
                     return;
                 }
 

programming_language: HTML
filename: views.py
change_type: ModificationType.MODIFY
diff: @@ -35,6 +35,7 @@ import sys
 import warnings
 from past.builtins import unicode
 from future.utils import bytes_to_native_str
+from django.utils.html import escape
 from django.utils.http import is_safe_url
 
 from time import time
@@ -1793,7 +1794,7 @@ def load_metadata_preview(request, c_type, c_id, conn=None, share_id=None, **kwa
         rdefQueries.append(
             {
                 "id": r["id"],
-                "owner": r["owner"],
+                "owner": escape(r["owner"]),  # May be used unsafe later
                 "c": ",".join(chs),
                 "m": r["model"] == "greyscale" and "g" or "c",
             }

programming_language: Python
filename: ome.popup.js
change_type: ModificationType.MODIFY
diff: @@ -169,7 +169,9 @@ String.prototype.escapeHTML = function(){
         switch(s) {
             case "&": return "&amp;";
             case "\\": return "&#92;";
-            case '"': return '\"';
+            case "`": return '&#x60;';
+            case "'": return '&#x27;';
+            case '"': return '&quot;';
             case "<": return "&lt;";
             case ">": return "&gt;";
             default: return s;

programming_language: JavaScript
filename: ome.roidisplay.js
change_type: ModificationType.MODIFY
diff: @@ -796,12 +796,12 @@ $.fn.roi_display = function(options) {
                                     var bb = newShape.getBBox();
                                     var textx = bb.x + (bb.width/2);
                                     var texty = bb.y + (bb.height/2);
-                                    var text_string = formatShapeText(shape['textValue'].escapeHTML())
+                                    var text_string = formatShapeText(shape['textValue'])
                                     var txt = paper.text(textx, texty, text_string);    // draw a 'dummy' paragraph to work out it's dimensions
                                     var newY = (texty-txt.getBBox().height/2)+9;
                                     // moving the existing text to newY doesn't seem to work - instead, remove and draw a new one
                                     txt.remove();
-                                    txt = paper.text(textx, newY, formatShapeText(shape['textValue'].escapeHTML()))
+                                    txt = paper.text(textx, newY, formatShapeText(shape['textValue']))
                                                .attr({'cursor':'default', 'fill': shape['strokeColor']}); // this is Insight's behavior
                                     txt_box = txt.getBBox();
                                     var txt_w = txt_box.width*1.3;

programming_language: JavaScript
filename: ome.spwgridview.js
change_type: ModificationType.MODIFY
diff: @@ -127,7 +127,7 @@ $(function(){
                     // check if min===max to avoid zero-division error
                     var x = (maxX === minX) ? 0.5 : (ws.position.x.value - minX)/(maxX - minX);
                     var y = (maxY === minY) ? 0.5 : (ws.position.y.value - minY)/(maxY - minY);
-                    return '<img style="left: ' + (x * 100) + '%; top: ' + (y * 100) + '%" title="' + ws.name + '" data-imageId="' + ws.id + '" />';
+                    return '<img style="left: ' + (x * 100) + '%; top: ' + (y * 100) + '%" title="' + ws.name.escapeHTML() + '" data-imageId="' + ws.id + '" />';
                 }, "");
                 $well_birds_eye.append(html.join(""));
             }

programming_language: JavaScript
filename: omero_image.js
change_type: ModificationType.MODIFY
diff: @@ -314,10 +314,10 @@
 
         /* Image details */
         var tmp = viewport.getMetadata();
-        $('#wblitz-image-name').html(tmp.imageName);
-        $('#wblitz-image-description-content').html(tmp.imageDescription.replace(/\n/g, '<br />'));
-        $('#wblitz-image-author').html(tmp.imageAuthor);
-        $('#wblitz-image-pub').html(tmp.projectName);
+        $('#wblitz-image-name').html(tmp.imageName.escapeHTML());
+        $('#wblitz-image-description-content').html(tmp.imageDescription.escapeHTML().replace(/\n/g, '<br />'));
+        $('#wblitz-image-author').html(tmp.imageAuthor.escapeHTML());
+        $('#wblitz-image-pub').html(tmp.projectName.escapeHTML());
         $('#wblitz-image-pubid').html(tmp.projectId);
         $('#wblitz-image-timestamp').html(tmp.imageTimestamp);
 
@@ -392,8 +392,8 @@
             $('<button id="wblitz-ch'+i+
                 '" class="squared' + (channels[i].active?' pressed':'') +
                 '" style="background-color: #'+ channels[i].color +
-                '" title="' + channels[i].label +
-                '"><div class="lutBackground"></div><div class="btnLabel">'+channels[i].label+'</div></button>')
+                '" title="' + channels[i].label.escapeHTML() +
+                '"><div class="lutBackground"></div><div class="btnLabel">'+channels[i].label.escapeHTML()+'</div></button>')
             .appendTo(box)
             .on('click', doToggle(i));
         }
@@ -542,11 +542,11 @@
             tmp.after(template
                 .replace(/\$class/g, btnClass)
                 .replace(/\$col/g, '#' + channels[i].color)
-                .replace(/\$label/g, channels[i].label)
-                .replace(/\$l/g, lbl)
+                .replace(/\$label/g, channels[i].label.escapeHTML())
+                .replace(/\$l/g, lbl.escapeHTML())
                 .replace(/\$idx0/g, i) // Channel Index, 0 based
                 .replace(/\$idx1/g, i+1) // Channel Index, 1 based
-                .replace(/\$cwl/g, channels[i].label) // Wavelength
+                .replace(/\$cwl/g, channels[i].label.escapeHTML()) // Wavelength
                 .replace(/\$cls/g, i/2!=parseInt(i/2, 10)?'even':'odd') // class
             );
 

programming_language: JavaScript
filename: omero_image.html
change_type: ModificationType.MODIFY
diff: @@ -544,7 +544,7 @@
               var theT =
                   typeof shape.theT === "undefined"? NOZT : shape.theT + 1;
               shapesHtml += "<td class='shape_cell'>" + theT + "</td>";
-              shapesHtml += "<td class='shape_cell shape_text' title=\""+ text +"\"><p>"+ truncate_text(text.escapeHTML()) + "</p></td>";
+              shapesHtml += "<td class='shape_cell shape_text' title=\""+ text.escapeHTML() +"\"><p>"+ truncate_text(text.escapeHTML()) + "</p></td>";
               shapesHtml += "<td class='shape_cell'>" + shapeThumbHtml + "</td>";
               shapesHtml += "<td class='shape_cell'>" + shapeVisibilityHtml + "</td>";
               shapesHtml += "</tr>";
@@ -563,7 +563,7 @@
           roi_html += "<th>" + roi['id'] + "</th>";
           roi_html += "<th style='white-space: nowrap'> "+ tRange +" </th>"; // no Z for ROI
           roi_html += "<th style='white-space: nowrap'> "+ zRange +" </th>"; // no T for ROI
-          roi_html += "<th class='shape_text' title=\""+ roiText +"\"><p>"+ truncate_text(roiText) +"</p></th>";
+          roi_html += "<th class='shape_text' title=\""+ roiText.escapeHTML() +"\"><p>"+ truncate_text(roiText).escapeHTML() +"</p></th>";
           roi_html += "<th>"+ roiThumbHtml +"</th>";
           roi_html += "<th>" + roiVisibilityHtml + "</th>";
           roi_html += "</tr></thead>";

programming_language: HTML