From 8bda468130c82a91a7b3284f3d41b5fac93a309c Mon Sep 17 00:00:00 2001 From: "advisory-database[bot]" <45398580+advisory-database[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 12:38:06 +0000 Subject: [PATCH] Publish GHSA-v2f9-rv6w-vw8r --- .../05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json b/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json index 19ec3478997..379e0959bb9 100644 --- a/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json +++ b/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json @@ -1,7 +1,7 @@ { "schema_version": "1.4.0", "id": "GHSA-v2f9-rv6w-vw8r", - "modified": "2024-05-10T15:33:01Z", + "modified": "2024-07-08T12:36:38Z", "published": "2024-05-10T15:33:01Z", "aliases": [ "CVE-2024-34349" @@ -9,7 +9,10 @@ "summary": "Sylius potentially vulnerable to Cross Site Scripting via \"Name\" field (Taxons, Products, Options, Variants) in Admin Panel", "details": "### Impact\n\nThere is a possibility to execute javascript code in the Admin panel. In order to perform an XSS attack input a script into `Name` field in which of the resources: Taxons, Products, Product Options or Product Variants. The code will be executed while using an autocomplete field with one of the listed entities in the Admin Panel. Also for the taxons in the category tree on the product form. \n\n### Patches\nThe issue is fixed in versions: 1.12.16, 1.13.1 and above.\n\n### Workarounds\n\n1. Create new file `assets/admin/sylius-lazy-choice-tree.js`:\n\n```js\n// assets/admin/sylius-lazy-choice-tree.js\n\nfunction sanitizeInput(input) {\n const div = document.createElement('div');\n div.textContent = input;\n return div.innerHTML; // Converts text content to plain HTML, stripping any scripts\n}\n\nconst createRootContainer = function createRootContainer() {\n return $('
');\n};\n\nconst createLeafContainerElement = function createLeafContainerElement() {\n return $('');\n};\n\nconst createLeafIconElement = function createLeafIconElement() {\n return $('');\n};\n\nconst createLeafTitleElement = function createLeafTitleElement() {\n return $('');\n};\n\nconst createLeafTitleSpan = function createLeafTitleSpan(displayName) {\n return $(`${displayName}`);\n};\n\nconst createLeafContentElement = function createLeafContentElement() {\n return $('');\n};\n\n$.fn.extend({\n choiceTree(type, multiple, defaultLevel) {\n const tree = this;\n const loader = tree.find('.dimmer');\n const loadedLeafs = [];\n const $input = tree.find('input[type=\"hidden\"]');\n\n const createCheckboxElement = function createCheckboxElement(name, code, multi) {\n const chosenNodes = $input.val().split(',');\n let checked = '';\n if (chosenNodes.some(chosenCode => chosenCode === code)) {\n checked = 'checked=\"checked\"';\n }\n if (multi) {\n return $(``);\n }\n\n return $(``);\n };\n\n const isLeafLoaded = function isLeafLoaded(code) {\n return loadedLeafs.some(leafCode => leafCode === code);\n };\n\n let createLeafFunc;\n\n const loadLeafAction = function loadLeafAction(parentCode, expandButton, content, icon, leafContainerElement) {\n icon.toggleClass('open');\n\n if (!isLeafLoaded(parentCode)) {\n expandButton.api({\n on: 'now',\n url: tree.data('tree-leafs-url') || tree.data('taxon-leafs-url'),\n method: 'GET',\n cache: false,\n data: {\n parentCode,\n },\n beforeSend(settings) {\n loader.addClass('active');\n\n return settings;\n },\n onSuccess(response) {\n response.forEach((leafNode) => {\n leafContainerElement.append((\n createLeafFunc(sanitizeInput(leafNode.name), leafNode.code, leafNode.hasChildren, multiple, leafNode.level)\n ));\n });\n content.append(leafContainerElement);\n loader.removeClass('active');\n loadedLeafs.push(parentCode);\n\n leafContainerElement.toggle();\n },\n });\n }\n\n leafContainerElement.toggle();\n };\n\n const bindExpandLeafAction = function bindExpandLeafAction(parentCode, expandButton, content, icon, level) {\n const leafContainerElement = createLeafContainerElement();\n if (defaultLevel > level) {\n loadLeafAction(parentCode, expandButton, content, icon, leafContainerElement);\n }\n\n expandButton.click(() => {\n loadLeafAction(parentCode, expandButton, content, icon, leafContainerElement);\n });\n };\n\n const bindCheckboxAction = function bindCheckboxAction(checkboxElement) {\n checkboxElement.checkbox({\n onChecked() {\n const { value } = checkboxElement[0].dataset;\n const checkedValues = $input.val().split(',').filter(Boolean);\n checkedValues.push(value);\n $input.val(checkedValues.join());\n },\n onUnchecked() {\n const { value } = checkboxElement[0].dataset;\n const checkedValues = $input.val().split(',').filter(Boolean);\n const i = checkedValues.indexOf(value);\n if (i !== -1) {\n checkedValues.splice(i, 1);\n }\n $input.val(checkedValues.join());\n },\n });\n };\n\n const createLeaf = function createLeaf(name, code, hasChildren, multipleChoice, level) {\n const displayNameElement = createLeafTitleSpan(name);\n const titleElement = createLeafTitleElement();\n const iconElement = createLeafIconElement();\n const checkboxElement = createCheckboxElement(name, code, multipleChoice);\n\n bindCheckboxAction(checkboxElement);\n\n const leafElement = $('');\n const leafContentElement = createLeafContentElement();\n\n leafElement.append(iconElement);\n titleElement.append(displayNameElement);\n titleElement.append(checkboxElement);\n leafContentElement.append(titleElement);\n\n if (!hasChildren) {\n iconElement.addClass('outline');\n }\n if (hasChildren) {\n bindExpandLeafAction(code, displayNameElement, leafContentElement, iconElement, level);\n }\n leafElement.append(leafContentElement);\n\n return leafElement;\n };\n createLeafFunc = createLeaf;\n\n tree.api({\n on: 'now',\n method: 'GET',\n url: tree.data('tree-root-nodes-url') || tree.data('taxon-root-nodes-url'),\n cache: false,\n beforeSend(settings) {\n loader.addClass('active');\n\n return settings;\n },\n onSuccess(response) {\n const rootContainer = createRootContainer();\n response.forEach((rootNode) => {\n rootContainer.append((\n createLeaf(sanitizeInput(rootNode.name), rootNode.code, rootNode.hasChildren, multiple, rootNode.level)\n ));\n });\n tree.append(rootContainer);\n loader.removeClass('active');\n },\n });\n },\n});\n```\n\n2. Create new file `assets/admin/sylius-auto-complete.js`:\n\n```js\n// assets/admin/sylius-auto-complete.js\n\nfunction sanitizeInput(input) {\n const div = document.createElement('div');\n div.textContent = input;\n return div.innerHTML; // Converts text content to plain HTML, stripping any scripts\n}\n\n$.fn.extend({\n autoComplete() {\n this.each((idx, el) => {\n const element = $(el);\n const criteriaName = element.data('criteria-name');\n const choiceName = element.data('choice-name');\n const choiceValue = element.data('choice-value');\n const autocompleteValue = element.find('input.autocomplete').val();\n const loadForEditUrl = element.data('load-edit-url');\n\n element.dropdown({\n delay: {\n search: 250,\n },\n forceSelection: false,\n saveRemoteData: false,\n verbose: true,\n apiSettings: {\n dataType: 'JSON',\n cache: false,\n beforeSend(settings) {\n /* eslint-disable-next-line no-param-reassign */\n settings.data[criteriaName] = settings.urlData.query;\n\n return settings;\n },\n onResponse(response) {\n let results = response.map(item => ({\n name: sanitizeInput(item[choiceName]),\n value: sanitizeInput(item[choiceValue]),\n }));\n\n if (!element.hasClass('multiple')) {\n results.unshift({\n name: ' ',\n value: '',\n });\n }\n\n return {\n success: true,\n results: results,\n };\n },\n },\n });\n\n if (autocompleteValue.split(',').filter(String).length > 0) {\n const menuElement = element.find('div.menu');\n\n menuElement.api({\n on: 'now',\n method: 'GET',\n url: loadForEditUrl,\n beforeSend(settings) {\n /* eslint-disable-next-line no-param-reassign */\n settings.data[choiceValue] = autocompleteValue.split(',').filter(String);\n\n return settings;\n },\n onSuccess(response) {\n response.forEach((item) => {\n menuElement.append((\n $(`