Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit e75ca2b

Browse files
authored
Install dompurify and use to sanitize product title for review blocks (#1117)
* install dompurify and use to sanitize product title for reviews * remove dompurify * remove dompurify implementation and add jsdoc covering what data is trusted
1 parent 2b5c814 commit e75ca2b

File tree

1 file changed

+18
-1
lines changed
  • assets/js/base/components/review-list-item

1 file changed

+18
-1
lines changed

assets/js/base/components/review-list-item/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ function getReviewContent( review ) {
8888
function getReviewProductName( review ) {
8989
return (
9090
<div className="wc-block-review-list-item__product">
91-
<a href={ review.product_permalink }>{ review.product_name }</a>
91+
<a
92+
href={ review.product_permalink }
93+
dangerouslySetInnerHTML={ {
94+
// `product_name` might have html entities for things like
95+
// emdash. So to display properly we need to allow the
96+
// browser to render.
97+
__html: review.product_name,
98+
} }
99+
/>
92100
</div>
93101
);
94102
}
@@ -193,4 +201,13 @@ ReviewListItem.propTypes = {
193201
review: PropTypes.object,
194202
};
195203

204+
/**
205+
* BE AWARE. ReviewListItem expects product data that is equivalent to what is
206+
* made avaialble for output in a public view. Thus content that may contain
207+
* html data is not sanitized further.
208+
*
209+
* Currently the following data is trusted (assumed to already be sanitized):
210+
* - `review.review` (review content).
211+
* - `review.product_name` (the product title)
212+
*/
196213
export default ReviewListItem;

0 commit comments

Comments
 (0)