{"id":"GHSA-v2f9-rv6w-vw8r","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.9.12, 1.10.16, 1.11.17, 1.12.16, 1.13.1 and above.\n\n### Workarounds\n\n1. Create a 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 $('\u003cdiv class=\"ui list\"\u003e\u003c/div\u003e');\n};\n\nconst createLeafContainerElement = function createLeafContainerElement() {\n  return $('\u003cdiv class=\"list\"\u003e\u003c/div\u003e');\n};\n\nconst createLeafIconElement = function createLeafIconElement() {\n  return $('\u003ci class=\"folder icon\"\u003e\u003c/i\u003e');\n};\n\nconst createLeafTitleElement = function createLeafTitleElement() {\n  return $('\u003cdiv class=\"header\"\u003e\u003c/div\u003e');\n};\n\nconst createLeafTitleSpan = function createLeafTitleSpan(displayName) {\n  return $(`\u003cspan style=\"margin-right: 5px; cursor: pointer;\"\u003e${displayName}\u003c/span\u003e`);\n};\n\nconst createLeafContentElement = function createLeafContentElement() {\n  return $('\u003cdiv class=\"content\"\u003e\u003c/div\u003e');\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 =\u003e chosenCode === code)) {\n        checked = 'checked=\"checked\"';\n      }\n      if (multi) {\n        return $(`\u003cdiv class=\"ui checkbox\" data-value=\"${code}\"\u003e\u003cinput ${checked} type=\"checkbox\" name=\"${type}\"\u003e\u003c/div\u003e`);\n      }\n\n      return $(`\u003cdiv class=\"ui radio checkbox\" data-value=\"${code}\"\u003e\u003cinput ${checked} type=\"radio\" name=\"${type}\"\u003e\u003c/div\u003e`);\n    };\n\n    const isLeafLoaded = function isLeafLoaded(code) {\n      return loadedLeafs.some(leafCode =\u003e 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) =\u003e {\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 \u003e level) {\n        loadLeafAction(parentCode, expandButton, content, icon, leafContainerElement);\n      }\n\n      expandButton.click(() =\u003e {\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 = $('\u003cdiv class=\"item\"\u003e\u003c/div\u003e');\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) =\u003e {\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) =\u003e {\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 =\u003e ({\n              name: sanitizeInput(item[choiceName]),\n              value: sanitizeInput(item[choiceValue]),\n            }));\n\n            if (!element.hasClass('multiple')) {\n              results.unshift({\n                name: '&nbsp;',\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 \u003e 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) =\u003e {\n              menuElement.append((\n                $(`\u003cdiv class=\"item\" data-value=\"${item[choiceValue]}\"\u003e${sanitizeInput(item[choiceName])}\u003c/div\u003e`)\n              ));\n            });\n\n            element.dropdown('refresh');\n            element.dropdown('set selected', element.find('input.autocomplete').val().split(',').filter(String));\n          },\n        });\n      }\n    });\n  },\n});\n```\n\n3. Create new file `assets/admin/sylius-product-auto-complete.js`:\n\n```js\n// assets/admin/sylius-product-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  productAutoComplete() {\n    this.each((index, element) =\u003e {\n      const $element = $(element);\n      $element.dropdown('set selected', $element.find('input[name*=\"[associations]\"]').val().split(',').filter(String));\n    });\n\n    this.dropdown({\n      delay: {\n        search: 250,\n      },\n      forceSelection: false,\n      apiSettings: {\n        dataType: 'JSON',\n        cache: false,\n        data: {\n          criteria: { search: { type: 'contains', value: '' } },\n        },\n        beforeSend(settings) {\n          /* eslint-disable-next-line no-param-reassign */\n          settings.data.criteria.search.value = settings.urlData.query;\n\n          return settings;\n        },\n        onResponse(response) {\n          return {\n            success: true,\n            results: response._embedded.items.map(item =\u003e ({\n              name: sanitizeInput(item.name),\n              value: sanitizeInput(item.code),\n            })),\n          };\n        },\n      },\n      onAdd(addedValue, addedText, $addedChoice) {\n        const inputAssociation = $addedChoice.parents('.product-select').find('input[name*=\"[associations]\"]');\n        const associatedProductCodes = inputAssociation.val().length \u003e 0 ? inputAssociation.val().split(',').filter(String) : [];\n\n        associatedProductCodes.push(addedValue);\n        $.unique(associatedProductCodes.sort());\n\n        inputAssociation.attr('value', associatedProductCodes.join());\n      },\n      onRemove(removedValue, removedText, $removedChoice) {\n        const inputAssociation = $removedChoice.parents('.product-select').find('input[name*=\"[associations]\"]');\n        const associatedProductCodes = inputAssociation.val().length \u003e 0 ? inputAssociation.val().split(',').filter(String) : [];\n\n        associatedProductCodes.splice($.inArray(removedValue, associatedProductCodes), 1);\n\n        inputAssociation.attr('value', associatedProductCodes.join());\n      },\n    });\n  },\n});\n```\n\n4. Add new import in `assets/admin/entry.js`:\n\n```js\n// assets/admin/entry.js\n// ...\nimport './sylius-lazy-choice-tree';\nimport './sylius-auto-complete';\nimport './sylius-product-auto-complete';\n```\n\n5.  If you're using Gulp, update your `gulpfile.babel.js`:\n\n```diff\n  import chug from 'gulp-chug';\n+ import concat from 'gulp-concat';\n  import gulp from 'gulp';\n  import yargs from 'yargs';\n\n  const { argv } = ...\n\n+ const rootPath = argv.rootPath || 'public/assets';\n+ \n  const config = [...];\n    '--rootPath',\n    argv.rootPath || '../../../../../../../public/assets',\n    '--nodeModulesPath',\n    argv.nodeModulesPath || '../../../../../../../node_modules',\n  ];\n\n  export const buildAdmin = ...\n\n+ export const patchAdminJs = function patchAdminJs() {\n+   return gulp.src([\n+     `${rootPath}/admin/js/app.js`,\n+     'assets/admin/sylius-auto-complete.js',\n+     'assets/admin/sylius-product-auto-complete.js',\n+     'assets/admin/sylius-lazy-choice-tree.js',\n+   ])\n+     .pipe(concat('app.js'))\n+     .pipe(gulp.dest(`${rootPath}/admin/js`));\n+ };\n+ patchAdminJs.description = 'Append admin security patches to built app.js.';\n\n ...\n\n- export const build = gulp.parallel(buildAdmin, buildShop);\n+ export const build = gulp.series(\n+   gulp.parallel(buildAdmin, buildShop),\n+   patchAdminJs,\n+ );\n\n ...\n\n- gulp.task('admin', buildAdmin);\n+ gulp.task('admin', gulp.series(buildAdmin, patchAdminJs));\n\n  ...\n```\n\n6. Rebuild your assets:\n\n```bash\nyarn build\n``` \n\n### Acknowledgements\n\nThis security issue has been reported by [Checkmarx Research Group](https://checkmarx.com), thank you!\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [Sylius issues](https://github.com/Sylius/Sylius/issues)\n* Email us at security@sylius.com","aliases":["CVE-2024-34349"],"modified":"2026-03-10T03:46:13.782773Z","published":"2024-05-10T15:33:01Z","database_specific":{"cwe_ids":["CWE-79"],"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2024-05-10T15:33:01Z","nvd_published_at":"2024-05-14T15:38:41Z"},"references":[{"type":"WEB","url":"https://github.com/Sylius/Sylius/security/advisories/GHSA-v2f9-rv6w-vw8r"},{"type":"WEB","url":"https://github.com/Sylius/Sylius/commit/ba4b66da5af88cdb1bba6174de8bdf42f4853e12"},{"type":"PACKAGE","url":"https://github.com/Sylius/Sylius"}],"affected":[{"package":{"name":"sylius/sylius","ecosystem":"Packagist","purl":"pkg:composer/sylius/sylius"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"1.9.12"}]}],"versions":["v0.1.0","v0.10.0","v0.11.0","v0.12.0","v0.13.0","v0.14.0","v0.15.0","v0.16.0","v0.17.0","v0.18.0","v0.19.0","v0.2.0","v0.3.0","v0.5.0","v0.6.0","v0.7.0","v0.8.0","v0.9.0","v1.0.0","v1.0.0-alpha.1","v1.0.0-alpha.2","v1.0.0-beta.1","v1.0.0-beta.2","v1.0.0-beta.3","v1.0.0-rc.1","v1.0.0-rc.2","v1.0.1","v1.0.10","v1.0.11","v1.0.12","v1.0.13","v1.0.14","v1.0.15","v1.0.16","v1.0.17","v1.0.18","v1.0.2","v1.0.3","v1.0.4","v1.0.5","v1.0.6","v1.0.7","v1.0.8","v1.0.9","v1.1.0","v1.1.0-RC","v1.1.1","v1.1.10","v1.1.11","v1.1.12","v1.1.13","v1.1.14","v1.1.15","v1.1.16","v1.1.17","v1.1.18","v1.1.2","v1.1.3","v1.1.4","v1.1.5","v1.1.6","v1.1.7","v1.1.8","v1.1.9","v1.2.0","v1.2.0-BETA","v1.2.0-RC","v1.2.1","v1.2.10","v1.2.11","v1.2.12","v1.2.13","v1.2.14","v1.2.15","v1.2.16","v1.2.17","v1.2.2","v1.2.3","v1.2.4","v1.2.5","v1.2.6","v1.2.7","v1.2.8","v1.2.9","v1.3.0","v1.3.0-BETA","v1.3.1","v1.3.10","v1.3.11","v1.3.12","v1.3.13","v1.3.14","v1.3.15","v1.3.16","v1.3.2","v1.3.3","v1.3.4","v1.3.5","v1.3.6","v1.3.7","v1.3.8","v1.3.9","v1.4.0","v1.4.0-BETA.1","v1.4.1","v1.4.10","v1.4.11","v1.4.12","v1.4.2","v1.4.3","v1.4.4","v1.4.5","v1.4.6","v1.4.7","v1.4.8","v1.4.9","v1.5.0","v1.5.0-RC.1","v1.5.1","v1.5.2","v1.5.3","v1.5.4","v1.5.5","v1.5.6","v1.5.7","v1.5.8","v1.5.9","v1.6.0","v1.6.0-ALPHA.1","v1.6.0-ALPHA.2","v1.6.0-RC.1","v1.6.1","v1.6.2","v1.6.3","v1.6.4","v1.6.5","v1.6.6","v1.6.7","v1.6.8","v1.6.9","v1.7.0","v1.7.0-ALPHA.1","v1.7.0-ALPHA.2","v1.7.0-RC.1","v1.7.1","v1.7.10","v1.7.11","v1.7.2","v1.7.3","v1.7.4","v1.7.5","v1.7.6","v1.7.7","v1.7.8","v1.7.9","v1.8.0","v1.8.0-RC.1","v1.8.1","v1.8.10","v1.8.11","v1.8.12","v1.8.2","v1.8.3","v1.8.4","v1.8.5","v1.8.6","v1.8.7","v1.8.8","v1.8.9","v1.9.0","v1.9.0-ALPHA.1","v1.9.0-ALPHA.2","v1.9.0-BETA.1","v1.9.0-BETA.2","v1.9.0-BETA.3","v1.9.0-RC.1","v1.9.0-RC.2","v1.9.1","v1.9.10","v1.9.11","v1.9.2","v1.9.3","v1.9.4","v1.9.5","v1.9.6","v1.9.7","v1.9.8","v1.9.9"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json"}},{"package":{"name":"sylius/sylius","ecosystem":"Packagist","purl":"pkg:composer/sylius/sylius"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"1.10.0-alpha.1"},{"fixed":"1.10.16"}]}],"versions":["v1.10.0","v1.10.0-alpha.1","v1.10.0-beta.1","v1.10.0-rc.1","v1.10.1","v1.10.10","v1.10.11","v1.10.12","v1.10.13","v1.10.14","v1.10.15","v1.10.2","v1.10.3","v1.10.4","v1.10.5","v1.10.6","v1.10.7","v1.10.8","v1.10.9"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json"}},{"package":{"name":"sylius/sylius","ecosystem":"Packagist","purl":"pkg:composer/sylius/sylius"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"1.11.0-alpha.1"},{"fixed":"1.11.17"}]}],"versions":["v1.11.0","v1.11.0-alpha.1","v1.11.0-alpha.2","v1.11.0-beta.1","v1.11.0-rc.1","v1.11.1","v1.11.10","v1.11.11","v1.11.12","v1.11.13","v1.11.14","v1.11.15","v1.11.16","v1.11.2","v1.11.3","v1.11.4","v1.11.5","v1.11.6","v1.11.7","v1.11.8","v1.11.9"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json"}},{"package":{"name":"sylius/sylius","ecosystem":"Packagist","purl":"pkg:composer/sylius/sylius"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"1.12.0-alpha.1"},{"fixed":"1.12.16"}]}],"versions":["v1.12.0","v1.12.0-alpha.1","v1.12.0-alpha.2","v1.12.0-beta.1","v1.12.0-rc.1","v1.12.1","v1.12.10","v1.12.11","v1.12.12","v1.12.13","v1.12.14","v1.12.15","v1.12.2","v1.12.3","v1.12.4","v1.12.5","v1.12.6","v1.12.7","v1.12.8","v1.12.9"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json"}},{"package":{"name":"sylius/sylius","ecosystem":"Packagist","purl":"pkg:composer/sylius/sylius"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"1.13.0-alpha.1"},{"fixed":"1.13.1"}]}],"versions":["v1.13.0","v1.13.0-alpha.1","v1.13.0-alpha.2","v1.13.0-beta.1","v1.13.0-rc.1"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/05/GHSA-v2f9-rv6w-vw8r/GHSA-v2f9-rv6w-vw8r.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:L/I:L/A:N"},{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"}]}