Skip to content

Commit

Permalink
CIF-3024 - DOM XSS in multiple CIF core components (#1014)
Browse files Browse the repository at this point in the history
* resolves the DOM XSS issues
  • Loading branch information
alwinjoseph02 authored Jul 26, 2024
1 parent f3f0dd5 commit f84d420
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ui.apps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions ui.apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"babel-plugin-istanbul": "^5.2.0",
"chai": "^4.2.0",
"glob": "^7.1.6",
"graphql": "^15.3.0",
"karma": "^6.3.16",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
Expand All @@ -60,11 +61,11 @@
"prettier": "^1.19.1",
"sinon": "^7.5.0",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11",
"graphql": "^15.3.0"
"webpack-cli": "^3.3.11"
},
"dependencies": {
"@adobe/magento-storefront-events-sdk": "1.1.16",
"@babel/polyfill": "^7.8.3"
"@babel/polyfill": "^7.8.3",
"dompurify": "^3.1.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
'use strict';

import DOMPurify from 'dompurify';

class PriceFormatter {
constructor(locale) {
this._locale = locale || window.CIF.locale || document.documentElement.lang || navigator.language;
Expand Down Expand Up @@ -88,7 +90,7 @@ class PriceFormatter {
})}</span>`;
}
}
return innerHTML;
return DOMPurify.sanitize(innerHTML);
}

formatPrice(price) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
'use strict';

import DOMPurify from 'dompurify';

class Product {
constructor(config) {
this._element = config.element;
Expand Down Expand Up @@ -90,7 +92,7 @@ class Product {
// Update values and enable add to cart button
this._element.querySelector(Product.selectors.sku).innerText = variant.sku;
this._element.querySelector(Product.selectors.name).innerText = variant.name;
this._element.querySelector(Product.selectors.description).innerHTML = variant.description;
this._element.querySelector(Product.selectors.description).innerHTML = DOMPurify.sanitize(variant.description);

// Use client-side fetched price
if (this._state.sku in this._state.prices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
'use strict';

import DOMPurify from 'dompurify';

class Product {
constructor(config) {
this._element = config.element;
Expand Down Expand Up @@ -88,7 +90,7 @@ class Product {
const nameEl = this._element.querySelector(Product.selectors.name);
if (nameEl) nameEl.innerText = variant.name;
const descriptionEl = this._element.querySelector(Product.selectors.description);
if (descriptionEl) descriptionEl.innerHTML = variant.description;
if (descriptionEl) descriptionEl.innerHTML = DOMPurify.sanitize(variant.description);

// Use client-side fetched price
if (this._state.sku in this._state.prices) {
Expand Down

0 comments on commit f84d420

Please sign in to comment.