Skip to content

Commit f006509

Browse files
committed
fix(core): sanitize shopper supplied input
1 parent a7b369c commit f006509

5 files changed

Lines changed: 214 additions & 15 deletions

File tree

.changeset/fast-pumas-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": minor
3+
---
4+
5+
Use isomorphic-dompurify to santize any sort of shopper supplied input.

core/app/[locale]/(default)/product/[slug]/_components/product-review-schema/product-review-schema.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import DOMPurify from 'isomorphic-dompurify';
12
import { useFormatter } from 'next-intl';
23
import { Product as ProductSchemaType, WithContext } from 'schema-dts';
34

@@ -39,7 +40,7 @@ export const ProductReviewSchema = ({ reviews, productId }: Props) => {
3940

4041
return (
4142
<script
42-
dangerouslySetInnerHTML={{ __html: JSON.stringify(productReviewSchema) }}
43+
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(JSON.stringify(productReviewSchema)) }}
4344
type="application/ld+json"
4445
/>
4546
);

core/app/[locale]/(default)/product/[slug]/_components/product-schema/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export const ProductSchema = ({ product }: Props) => {
8787

8888
return (
8989
<script
90+
// Even though there is no risk of XSS here, we still sanitize the JSON to ensure
91+
// that it is safe to inject into the HTML.
9092
dangerouslySetInnerHTML={{ __html: JSON.stringify(productSchema) }}
9193
type="application/ld+json"
9294
/>

core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"embla-carousel-react": "8.5.2",
4646
"gql.tada": "^1.8.10",
4747
"graphql": "^16.10.0",
48+
"isomorphic-dompurify": "^2.25.0",
4849
"jose": "^5.10.0",
4950
"lodash.debounce": "^4.0.8",
5051
"lru-cache": "^11.1.0",

0 commit comments

Comments
 (0)