CVE-2020-15253 (published 2020-10-14T19:15Z)

Versions of Grocy <= 2.7.1 are vulnerable to Cross-Site Scripting via the Create Shopping List module, that is rendered upon deleting that Shopping List. The issue was also found in users, batteries, chores, equipment, locations, quantity units, shopping locations, tasks, taskcategories, product groups, recipes and products. Authentication is required to exploit these issues and Grocy should not be publicly exposed. The linked reference details a proof-of-concept.

Severity: LOW
CVSS v2 base score: 3.5 (AV:N/AC:M/Au:S/C:N/I:P/A:N)
CVSS v3 base score: 4.8, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:H/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/grocy/grocy
commit_details: repo_url: https://github.com/grocy/grocy
author: Bernd Bestel
author_date: 2020-09-08 18:10:30+02:00
msg: Excape HTML (where needed, for bootbox) (references #996)
repository: repo_url: https://github.com/grocy/grocy
repo_name: grocy/grocy
description: ERP beyond your fridge - Grocy is a web-based self-hosted groceries & household management solution for your home
repo_language: Blade
owner: grocy
file_changes: filename: extensions.js
change_type: ModificationType.MODIFY
diff: @@ -172,10 +172,12 @@ function animateCSS(selector, animationName, callback, speed = "faster")
 
 	nodes.on('animationend', handleAnimationEnd);
 }
+
 function RandomString()
 {
 	return Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
 }
+
 function getQRCodeForContent(url)
 {
 	var qr = qrcode(0, 'L');
@@ -183,6 +185,7 @@ function getQRCodeForContent(url)
 	qr.make();
 	return qr.createImgTag(10, 5);
 }
+
 function getQRCodeForAPIKey(apikey_type, apikey_key)
 {
 	var content = U('/api') + '|' + apikey_key;
@@ -192,3 +195,8 @@ function getQRCodeForAPIKey(apikey_type, apikey_key)
 	}
 	return getQRCodeForContent(content);
 }
+
+function SanitizeHtml(input)
+{
+	return $("<div/>").text(input).html();
+}

programming_language: JavaScript
filename: batteries.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.battery-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-battery-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-battery-name'));
 	var objectId = $(e.currentTarget).attr('data-battery-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: chores.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.chore-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-chore-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-chore-name'));
 	var objectId = $(e.currentTarget).attr('data-chore-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: productpicker.js
change_type: ModificationType.MODIFY
diff: @@ -162,7 +162,7 @@ $('#product_id_text_input').on('blur', function(e)
 
 			Grocy.Components.ProductPicker.PopupOpen = true;
 			bootbox.dialog({
-				message: __t('"%s" could not be resolved to a product, how do you want to proceed?', input),
+				message: __t('"%s" could not be resolved to a product, how do you want to proceed?', SanitizeHtml(input)),
 				title: __t('Create or assign product'),
 				onEscape: function()
 				{

programming_language: JavaScript
filename: equipment.js
change_type: ModificationType.MODIFY
diff: @@ -68,7 +68,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.equipment-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-equipment-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-equipment-name'));
 	var objectId = $(e.currentTarget).attr('data-equipment-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: locations.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.location-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-location-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-location-name'));
 	var objectId = $(e.currentTarget).attr('data-location-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: mealplan.js
change_type: ModificationType.MODIFY
diff: @@ -563,7 +563,7 @@ $(document).on('click', '.recipe-order-missing-button', function(e)
 	// to prevent that the tooltip stays until clicked anywhere else
 	document.activeElement.blur();
 
-	var objectName = $(e.currentTarget).attr('data-recipe-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-recipe-name'));
 	var objectId = $(e.currentTarget).attr('data-recipe-id');
 	var button = $(this);
 	var servings = $(e.currentTarget).attr('data-mealplan-servings');
@@ -667,7 +667,7 @@ $(document).on('click', '.recipe-consume-button', function(e)
 	// to prevent that the tooltip stays until clicked anywhere else
 	document.activeElement.blur();
 
-	var objectName = $(e.currentTarget).attr('data-recipe-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-recipe-name'));
 	var objectId = $(e.currentTarget).attr('data-recipe-id');
 	var servings = $(e.currentTarget).attr('data-mealplan-servings');
 

programming_language: Lua
filename: productgroups.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.product-group-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-group-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-group-name'));
 	var objectId = $(e.currentTarget).attr('data-group-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: products.js
change_type: ModificationType.MODIFY
diff: @@ -38,7 +38,7 @@ if (typeof GetUriParam("product-group") !== "undefined")
 
 $(document).on('click', '.product-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-product-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-product-name'));
 	var objectId = $(e.currentTarget).attr('data-product-id');
 
 	Grocy.Api.Get('stock/products/' + objectId,

programming_language: JavaScript
filename: quantityunits.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.quantityunit-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-quantityunit-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-quantityunit-name'));
 	var objectId = $(e.currentTarget).attr('data-quantityunit-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: recipeform.js
change_type: ModificationType.MODIFY
diff: @@ -126,7 +126,7 @@ $('#recipe-form input').keydown(function(event)
 
 $(document).on('click', '.recipe-pos-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-recipe-pos-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-recipe-pos-name'));
 	var objectId = $(e.currentTarget).attr('data-recipe-pos-id');
 
 	bootbox.confirm({
@@ -163,7 +163,7 @@ $(document).on('click', '.recipe-pos-delete-button', function(e)
 
 $(document).on('click', '.recipe-include-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-recipe-include-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-recipe-include-name'));
 	var objectId = $(e.currentTarget).attr('data-recipe-include-id');
 
 	bootbox.confirm({
@@ -200,7 +200,7 @@ $(document).on('click', '.recipe-include-delete-button', function(e)
 
 $(document).on('click', '.recipe-pos-show-note-button', function(e)
 {
-	var note = $(e.currentTarget).attr('data-recipe-pos-note');
+	var note = SanitizeHtml($(e.currentTarget).attr('data-recipe-pos-note'));
 
 	bootbox.alert(note);
 });

programming_language: JavaScript
filename: recipes.js
change_type: ModificationType.MODIFY
diff: @@ -81,7 +81,7 @@ $(".recipe-delete").on('click', function(e)
 {
 	e.preventDefault();
 
-	var objectName = $(e.currentTarget).attr('data-recipe-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-recipe-name'));
 	var objectId = $(e.currentTarget).attr('data-recipe-id');
 
 	bootbox.confirm({
@@ -118,7 +118,7 @@ $(".recipe-delete").on('click', function(e)
 
 $(document).on('click', '.recipe-shopping-list', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-recipe-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-recipe-name'));
 	var objectId = $(e.currentTarget).attr('data-recipe-id');
 
 	bootbox.confirm({
@@ -164,7 +164,7 @@ $(document).on('click', '.recipe-shopping-list', function(e)
 
 $(".recipe-consume").on('click', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-recipe-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-recipe-name'));
 	var objectId = $(e.currentTarget).attr('data-recipe-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: shoppinglist.js
change_type: ModificationType.MODIFY
diff: @@ -77,7 +77,7 @@ $(".status-filter-message").on("click", function()
 
 $("#delete-selected-shopping-list").on("click", function()
 {
-	var objectName = $("#selected-shopping-list option:selected").text();
+	var objectName = SanitizeHtml($("#selected-shopping-list option:selected").text());
 	var objectId = $("#selected-shopping-list").val();
 
 	bootbox.confirm({
@@ -158,7 +158,7 @@ $(document).on('click', '#add-products-below-min-stock-amount', function(e)
 $(document).on('click', '#clear-shopping-list', function(e)
 {
 	bootbox.confirm({
-		message: __t('Are you sure to empty shopping list "%s"?', $("#selected-shopping-list option:selected").text()),
+		message: __t('Are you sure to empty shopping list "%s"?', SanitizeHtml($("#selected-shopping-list option:selected").text())),
 		closeButton: false,
 		buttons: {
 			confirm: {

programming_language: JavaScript
filename: shoppinglocations.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.shoppinglocation-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-shoppinglocation-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-shoppinglocation-name'));
 	var objectId = $(e.currentTarget).attr('data-shoppinglocation-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: taskcategories.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.task-category-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-category-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-category-name'));
 	var objectId = $(e.currentTarget).attr('data-category-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: tasks.js
change_type: ModificationType.MODIFY
diff: @@ -119,7 +119,7 @@ $(document).on('click', '.delete-task-button', function(e)
 {
 	e.preventDefault();
 
-	var objectName = $(e.currentTarget).attr('data-task-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-task-name'));
 	var objectId = $(e.currentTarget).attr('data-task-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: userentities.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.userentity-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-userentity-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-userentity-name'));
 	var objectId = $(e.currentTarget).attr('data-userentity-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: userfields.js
change_type: ModificationType.MODIFY
diff: @@ -33,7 +33,7 @@ $("#entity-filter").on("change", function()
 
 $(document).on('click', '.userfield-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-userfield-name');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-userfield-name'));
 	var objectId = $(e.currentTarget).attr('data-userfield-id');
 
 	bootbox.confirm({

programming_language: JavaScript
filename: users.js
change_type: ModificationType.MODIFY
diff: @@ -21,7 +21,7 @@ $("#search").on("keyup", Delay(function()
 
 $(document).on('click', '.user-delete-button', function(e)
 {
-	var objectName = $(e.currentTarget).attr('data-user-username');
+	var objectName = SanitizeHtml($(e.currentTarget).attr('data-user-username'));
 	var objectId = $(e.currentTarget).attr('data-user-id');
 
 	bootbox.confirm({

programming_language: JavaScript
repo_url: https://github.com/grocy/grocy
commit_details: repo_url: https://github.com/grocy/grocy
author: Bernd Bestel
author_date: 2020-09-08 18:25:42+02:00
msg: Excape shopping list item notes (references #996)
repository: repo_url: https://github.com/grocy/grocy
repo_name: grocy/grocy
description: ERP beyond your fridge - Grocy is a web-based self-hosted groceries & household management solution for your home
repo_language: Blade
owner: grocy
file_changes: filename: shoppinglist.blade.php
change_type: ModificationType.MODIFY
diff: @@ -190,7 +190,7 @@
 						</a>
 					</td>
 					<td>
-						@if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}<br>@endif<em>{!! nl2br($listItem->note) !!}</em>
+						@if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}<br>@endif<em>{!! nl2br(e($listItem->note)) !!}</em>
 					</td>
 					<td>
 						<span class="locale-number locale-number-quantity-amount">{{ $listItem->amount }}</span> @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name_plural) }}@endif
@@ -296,7 +296,7 @@
 					@foreach($listItems as $listItem)
 					<tr>
 						<td>
-							@if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}<br>@endif<em>{!! nl2br($listItem->note) !!}</em>
+							@if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}<br>@endif<em>{!! nl2br(e($listItem->note)) !!}</em>
 						</td>
 						<td>
 							{{ $listItem->amount }} @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name_plural) }}@endif

programming_language: PHP