CVE-2019-14331 (published 2019-07-28T14:15Z)

An issue was discovered in EspoCRM before 5.6.6. Stored XSS exists due to lack of filtration of user-supplied data in Create User. A malicious attacker can modify the firstName and lastName to contain JavaScript code.

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.0/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/espocrm/espocrm
commit_details: repo_url: https://github.com/espocrm/espocrm
author: yuri
author_date: 2019-07-23 17:50:02+03:00
msg: xss fixes
repository: repo_url: https://github.com/espocrm/espocrm
repo_name: espocrm/espocrm
description: EspoCRM – Open Source CRM Application
repo_language: PHP
owner: espocrm
file_changes: filename: email-address-varchar.js
change_type: ModificationType.MODIFY
diff: @@ -203,6 +203,10 @@ Espo.define('views/email/fields/email-address-varchar', ['views/fields/varchar',
         },
 
         addAddress: function (address, name, type, id) {
+            if (name) {
+                name = this.getHelper().escapeString(name);
+            }
+
             if (this.justAddedAddress) {
                 this.deleteAddress(this.justAddedAddress);
             }
@@ -236,6 +240,13 @@ Espo.define('views/email/fields/email-address-varchar', ['views/fields/varchar',
         },
 
         addAddressHtml: function (address, name) {
+            if (name) {
+                name = this.getHelper().escapeString(name);
+            }
+            if (address) {
+                name = this.getHelper().escapeString(address);
+            }
+
             var conteiner = this.$el.find('.link-container');
             var html =
             '<div data-address="'+address+'" class="list-group-item">' +
@@ -288,6 +299,10 @@ Espo.define('views/email/fields/email-address-varchar', ['views/fields/varchar',
 
             var addressHtml = '<span>' + address + '</span>';
 
+            if (name) {
+                name = this.getHelper().escapeString(name);
+            }
+
             var lineHtml;
             if (id) {
                 lineHtml = '<div>' + '<a href="#' + entityType + '/view/' + id + '">' + name + '</a> <span class="text-muted">&#187;</span> ' + addressHtml + '</div>';

programming_language: JavaScript
filename: from-address-varchar.js
change_type: ModificationType.MODIFY
diff: @@ -106,6 +106,11 @@ Espo.define('views/email/fields/from-address-varchar', 'views/fields/varchar', f
             var fromString = this.model.get('fromString') || this.model.get('fromName');
 
             var name = this.nameHash[address] || this.parseNameFromStringAddress(fromString) || null;
+
+            if (name) {
+                name = this.getHelper().escapeString(name);
+            }
+
             var entityType = this.typeHash[address] || null;
             var id = this.idHash[address] || null;
 
@@ -129,6 +134,8 @@ Espo.define('views/email/fields/from-address-varchar', 'views/fields/varchar', f
         },
 
         getCreateHtml: function (address) {
+            address = this.getHelper().escapeString(address);
+
             var html = '<span class="dropdown email-address-create-dropdown pull-right">' +
                 '<button class="dropdown-toggle btn btn-link btn-sm" data-toggle="dropdown">' +
                     '<span class="caret text-muted"></span>' +
@@ -179,6 +186,10 @@ Espo.define('views/email/fields/from-address-varchar', 'views/fields/varchar', f
                 }
             }
 
+            if (name) {
+                name = this.getHelper().escapeString(name);
+            }
+
             var attributes = {
                 emailAddress: address
             };
@@ -240,6 +251,10 @@ Espo.define('views/email/fields/from-address-varchar', 'views/fields/varchar', f
                 }
             }
 
+            if (name) {
+                name = this.getHelper().escapeString(name);
+            }
+
             var attributes = {
                 emailAddress: address
             };

programming_language: JavaScript
filename: link-multiple-with-primary.js
change_type: ModificationType.MODIFY
diff: @@ -130,7 +130,7 @@ Espo.define('views/fields/link-multiple-with-primary', 'views/fields/link-multip
             var $container = this.$el.find('.link-container');
             var $el = $('<div class="form-inline list-group-item link-with-role clearfix link-group-item-with-primary">').addClass('link-' + id).attr('data-id', id);
 
-            var nameHtml = '<div>' + name + '&nbsp;' + '</div>';
+            var nameHtml = '<div>' + this.getHelper().escapeString(name) + '&nbsp;' + '</div>';
             var removeHtml = '<a href="javascript:" class="pull-right" data-id="' + id + '" data-action="clearLink"><span class="fas fa-times"></a>';
 
             $left = $('<div>');

programming_language: JavaScript
filename: assign.js
change_type: ModificationType.MODIFY
diff: @@ -40,7 +40,7 @@ Espo.define('views/notification/items/assign', 'views/notification/items/base',
             this.userId = data.userId;
 
             this.messageData['entityType'] = Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase());
-            this.messageData['entity'] = '<a href="#' + data.entityType + '/view/' + data.entityId + '">' + data.entityName + '</a>';
+            this.messageData['entity'] = '<a href="#' + this.getHelper().escapeString(data.entityType) + '/view/' + this.getHelper().escapeString(data.entityId) + '">' + this.getHelper().escapeString(data.entityName) + '</a>';
 
             this.createMessage();
         },

programming_language: JavaScript
filename: email-received.js
change_type: ModificationType.MODIFY
diff: @@ -46,19 +46,18 @@ Espo.define('views/notification/items/email-received', 'views/notification/items
 
             this.userId = data.userId;
 
-            this.messageData['entityType'] = Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase());
+            this.messageData['entityType'] = this.getHelper().escapeString(Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase()));
             if (data.personEntityId) {
-                this.messageData['from'] = '<a href="#' + data.personEntityType + '/view/' + data.personEntityId + '">' + data.personEntityName + '</a>';
+                this.messageData['from'] = '<a href="#' + this.getHelper().escapeString(data.personEntityType) + '/view/' + this.getHelper().escapeString(data.personEntityId) + '">' + this.getHelper().escapeString(data.personEntityName) + '</a>';
             } else {
-                this.messageData['from'] = data.fromString || this.translate('empty address');
+                this.messageData['from'] = this.getHelper().escapeString(data.fromString || this.translate('empty address'));
             }
 
-            this.emailId = data.emailId;
-            this.emailName = data.emailName;
+            this.emailId = this.getHelper().escapeString(data.emailId);
+            this.emailName = this.getHelper().escapeString(data.emailName);
 
             this.createMessage();
         }
 
     });
 });
-

programming_language: JavaScript
filename: entity-removed.js
change_type: ModificationType.MODIFY
diff: @@ -39,10 +39,10 @@ Espo.define('views/notification/items/entity-removed', 'views/notification/items
 
             this.userId = data.userId;
 
-            this.messageData['entityType'] = (this.translate(data.entityType, 'scopeNames') || '').toLowerCase();
+            this.messageData['entityType'] = this.getHelper().escapeString((this.translate(data.entityType, 'scopeNames') || '').toLowerCase());
 
-            this.messageData['user'] = '<a href="#User/view/' + data.userId + '">' + data.userName + '</a>';
-            this.messageData['entity'] = '<a href="#'+data.entityType+'/view/' + data.entityId + '">' + data.entityName + '</a>';
+            this.messageData['user'] = '<a href="#User/view/' + this.getHelper().escapeString(data.userId) + '">' + this.getHelper().escapeString(data.userName) + '</a>';
+            this.messageData['entity'] = '<a href="#'+this.getHelper().escapeString(data.entityType)+'/view/' + this.getHelper().escapeString(data.entityId) + '">' + this.getHelper().escapeString(data.entityName) + '</a>';
 
             this.createMessage();
         }

programming_language: JavaScript
filename: message.js
change_type: ModificationType.MODIFY
diff: @@ -47,10 +47,10 @@ Espo.define('views/notification/items/message', 'views/notification/items/base',
 
             this.userId = data.userId;
 
-            this.messageData['entityType'] = Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase());
+            this.messageData['entityType'] = this.getHelper().escapeString(Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase()));
 
-            this.messageData['user'] = '<a href="#User/view/' + data.userId + '">' + data.userName + '</a>';
-            this.messageData['entity'] = '<a href="#'+data.entityType+'/view/' + data.entityId + '">' + data.entityName + '</a>';
+            this.messageData['user'] = '<a href="#User/view/' + this.getHelper().escapeString(data.userId) + '">' + this.getHelper().escapeString(data.userName) + '</a>';
+            this.messageData['entity'] = '<a href="#'+this.getHelper().escapeString(data.entityType)+'/view/' + this.getHelper().escapeString(data.entityId) + '">' + this.getHelper().escapeString(data.entityName) + '</a>';
 
             this.createMessage();
         }

programming_language: JavaScript
filename: navbar.js
change_type: ModificationType.MODIFY
diff: @@ -41,7 +41,6 @@ Espo.define('views/site/navbar', 'view', function (Dep) {
                 menuDataList: this.getMenuDataList(),
                 quickCreateList: this.quickCreateList,
                 enableQuickCreate: this.quickCreateList.length > 0,
-                userName: this.getUser().get('name'),
                 userId: this.getUser().id,
                 logoSrc: this.getLogoSrc()
             };
@@ -528,7 +527,7 @@ Espo.define('views/site/navbar', 'view', function (Dep) {
             var list = [
                 {
                     link: '#User/view/' + this.getUser().id,
-                    html: avatarHtml + this.getUser().get('name')
+                    html: avatarHtml + this.getHelper().escapeString(this.getUser().get('name')),
                 },
                 {divider: true}
             ];

programming_language: JavaScript
filename: note.js
change_type: ModificationType.MODIFY
diff: @@ -85,7 +85,7 @@ Espo.define('views/stream/note', 'view', function (Dep) {
             this.messageData = {
                 'user': 'field:createdBy',
                 'entity': 'field:parent',
-                'entityType': this.translateEntityType(this.model.get('parentType')),
+                'entityType': this.getHelper().escapeString(this.translateEntityType(this.model.get('parentType'))),
             };
 
             if (!this.options.noEdit && (this.isEditable || this.isRemovable)) {

programming_language: JavaScript
filename: assign.js
change_type: ModificationType.MODIFY
diff: @@ -52,7 +52,7 @@ Espo.define('views/stream/notes/assign', 'views/stream/note', function (Dep) {
             this.assignedUserId = data.assignedUserId || null;
             this.assignedUserName = data.assignedUserName || null;
 
-            this.messageData['assignee'] = '<a href="#User/view/' + data.assignedUserId + '">' + data.assignedUserName + '</a>';
+            this.messageData['assignee'] = '<a href="#User/view/' + this.getHelper().escapeString(data.assignedUserId) + '">' + this.getHelper().escapeString(data.assignedUserName) + '</a>';
 
             if (this.isUserStream) {
                 if (this.assignedUserId) {

programming_language: JavaScript
filename: create-related.js
change_type: ModificationType.MODIFY
diff: @@ -56,7 +56,7 @@ Espo.define('views/stream/notes/create-related', 'views/stream/note', function (
             this.entityName = this.model.get('relatedName') ||  data.entityName || null;
 
             this.messageData['relatedEntityType'] = this.translateEntityType(this.entityType);
-            this.messageData['relatedEntity'] = '<a href="#' + this.entityType + '/view/' + this.entityId + '">' + this.entityName +'</a>';
+            this.messageData['relatedEntity'] = '<a href="#' + this.getHelper().escapeString(this.entityType) + '/view/' + this.getHelper().escapeString(this.entityId) + '">' + this.getHelper().escapeString(this.entityName) +'</a>';
 
             this.createMessage();
         }

programming_language: JavaScript
filename: create.js
change_type: ModificationType.MODIFY
diff: @@ -52,7 +52,7 @@ Espo.define('views/stream/notes/create', 'views/stream/note', function (Dep) {
                 this.assignedUserId = data.assignedUserId || null;
                 this.assignedUserName = data.assignedUserName || null;
 
-                this.messageData['assignee'] = '<a href="#User/view/' + this.assignedUserId + '">' + this.assignedUserName + '</a>';
+                this.messageData['assignee'] = '<a href="#User/view/' + this.assignedUserId + '">' + this.getHelper().escapeString(this.assignedUserName) + '</a>';
 
                 var isYou = false;
                 if (this.isUserStream) {

programming_language: JavaScript
filename: email-received.js
change_type: ModificationType.MODIFY
diff: @@ -67,7 +67,7 @@ Espo.define('views/stream/notes/email-received', 'views/stream/note', function (
                 }
             }
 
-            this.messageData['email'] = '<a href="#Email/view/' + data.emailId + '">' + data.emailName + '</a>';
+            this.messageData['email'] = '<a href="#Email/view/' + this.getHelper().escapeString(data.emailId) + '">' + this.getHelper().escapeString(data.emailName) + '</a>';
 
             this.messageName = 'emailReceived';
 
@@ -77,7 +77,7 @@ Espo.define('views/stream/notes/email-received', 'views/stream/note', function (
 
             if (data.personEntityId) {
                 this.messageName += 'From';
-                this.messageData['from'] = '<a href="#'+data.personEntityType+'/view/' + data.personEntityId + '">' + data.personEntityName + '</a>';
+                this.messageData['from'] = '<a href="#'+this.getHelper().escapeString(data.personEntityType)+'/view/' + this.getHelper().escapeString(data.personEntityId) + '">' + this.getHelper().escapeString(data.personEntityName) + '</a>';
             }
 
             if (this.model.get('parentType') === data.personEntityType && this.model.get('parentId') == data.personEntityId) {

programming_language: JavaScript
filename: email-sent.js
change_type: ModificationType.MODIFY
diff: @@ -65,11 +65,11 @@ Espo.define('views/stream/notes/email-sent', 'views/stream/note', function (Dep)
                 }
             }
 
-            this.messageData['email'] = '<a href="#Email/view/' + data.emailId + '">' + data.emailName + '</a>';
+            this.messageData['email'] = '<a href="#Email/view/' + this.getHelper().escapeString(data.emailId) + '">' + this.getHelper().escapeString(data.emailName) + '</a>';
 
             this.messageName = 'emailSent';
 
-            this.messageData['by'] = '<a href="#'+data.personEntityType+'/view/' + data.personEntityId + '">' + data.personEntityName + '</a>';
+            this.messageData['by'] = '<a href="#'+this.getHelper().escapeString(data.personEntityType)+'/view/' + this.getHelper().escapeString(data.personEntityId) + '">' + this.getHelper().escapeString(data.personEntityName) + '</a>';
 
 
             if (this.isThis) {

programming_language: JavaScript
filename: mention-in-post.js
change_type: ModificationType.MODIFY
diff: @@ -76,7 +76,7 @@ Espo.define('views/stream/notes/mention-in-post', 'views/stream/note', function
                                 teamIdList.forEach(function (teamId) {
                                     var teamName = teamNameHash[teamId];
                                     if (teamName) {
-                                        teamHtmlList.push('<a href="#Team/view/' + teamId + '">' + teamName + '</a>');
+                                        teamHtmlList.push('<a href="#Team/view/' + this.getHelper().escapeString(teamId) + '">' + this.getHelper().escapeString(teamName) + '</a>');
                                     }
                                 }, this);
 
@@ -93,7 +93,7 @@ Espo.define('views/stream/notes/mention-in-post', 'views/stream/note', function
                                     userIdList.forEach(function (userId) {
                                         var userName = userNameHash[userId];
                                         if (userName) {
-                                            userHtmlList.push('<a href="#User/view/' + userId + '">' + userName + '</a>');
+                                            userHtmlList.push('<a href="#User/view/' + this.getHelper().escapeString(userId) + '">' + this.getHelper().escapeString(userName) + '</a>');
                                         }
                                     }, this);
                                     this.messageData['target'] = userHtmlList.join(', ');
@@ -113,4 +113,3 @@ Espo.define('views/stream/notes/mention-in-post', 'views/stream/note', function
 
     });
 });
-

programming_language: JavaScript
filename: post.js
change_type: ModificationType.MODIFY
diff: @@ -85,7 +85,7 @@ Espo.define('views/stream/notes/post', 'views/stream/note', function (Dep) {
                         teamIdList.forEach(function (teamId) {
                             var teamName = teamNameHash[teamId];
                             if (teamName) {
-                                teamHtmlList.push('<a href="#Team/view/' + teamId + '">' + teamName + '</a>');
+                                teamHtmlList.push('<a href="#Team/view/' + this.getHelper().escapeString(teamId) + '">' + this.getHelper().escapeString(teamName) + '</a>');
                             }
                         }, this);
 
@@ -103,7 +103,7 @@ Espo.define('views/stream/notes/post', 'views/stream/note', function (Dep) {
                         portalIdList.forEach(function (portalId) {
                             var portalName = portalNameHash[portalId];
                             if (portalName) {
-                                portalHtmlList.push('<a href="#Portal/view/' + portalId + '">' + portalName + '</a>');
+                                portalHtmlList.push('<a href="#Portal/view/' + this.getHelper().escapeString(portalId) + '">' + this.getHelper().escapeString(portalName) + '</a>');
                             }
                         }, this);
 
@@ -135,7 +135,7 @@ Espo.define('views/stream/notes/post', 'views/stream/note', function (Dep) {
                                     } else {
                                         var userName = userNameHash[userId];
                                         if (userName) {
-                                            userHtmlList.push('<a href="#User/view/' + userId + '">' + userName + '</a>');
+                                            userHtmlList.push('<a href="#User/view/' + this.getHelper().escapeString(userId) + '">' + this.getHelper().escapeString(userName) + '</a>');
                                         }
                                     }
                                 }

programming_language: JavaScript
filename: relate.js
change_type: ModificationType.MODIFY
diff: @@ -55,7 +55,7 @@ Espo.define('views/stream/notes/relate', 'views/stream/note', function (Dep) {
             this.entityName = this.model.get('relatedName') ||  data.entityName || null;
 
             this.messageData['relatedEntityType'] = this.translateEntityType(this.entityType);
-            this.messageData['relatedEntity'] = '<a href="#' + this.entityType + '/view/' + this.entityId + '">' + this.entityName +'</a>';
+            this.messageData['relatedEntity'] = '<a href="#' + this.getHelper().escapeString(this.entityType) + '/view/' + this.getHelper().escapeString(this.entityId) + '">' + this.getHelper().escapeString(this.entityName) +'</a>';
 
             this.createMessage();
         },

programming_language: JavaScript
filename: status.js
change_type: ModificationType.MODIFY
diff: @@ -56,7 +56,7 @@ Espo.define('views/stream/notes/status', 'views/stream/note', function (Dep) {
 
             this.style = data.style || 'default';
 
-            this.statusText = this.getLanguage().translateOption(value, field, this.model.get('parentType'));
+            this.statusText = this.getHelper().escapeString(this.getLanguage().translateOption(value, field, this.model.get('parentType')));
 
             this.messageData['field'] = this.translate(field, 'fields', this.model.get('parentType')).toLowerCase();
 

programming_language: JavaScript