Skip to content

Commit e37bdc2

Browse files
committed
pkp/pkp-lib#1660 added js side html sanitizer to handle XXS issue
1 parent a3dc39d commit e37bdc2

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/components/ListPanel/reviewerRecommendations/ReviewerRecommendationsListPanel.vue

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
<TableBody>
2525
<TableRow v-for="item in items" :key="item.id">
2626
<TableCell :is-row-header="true">
27-
<span class="text-base-normal">
28-
{{ localize(item.title) }}
29-
</span>
27+
<span
28+
v-strip-unsafe-html="localize(item.title)"
29+
class="text-lg-normal"
30+
></span>
3031
</TableCell>
3132

3233
<TableCell>
@@ -77,6 +78,7 @@ import ReviewerRecommendationsEditModal from './ReviewerRecommendationsEditModal
7778
7879
import {useModal} from '@/composables/useModal';
7980
import {useLocalize} from '@/composables/useLocalize';
81+
import {sanitizeHtml} from '@/directives/stripUnsafeHtml';
8082
8183
const {t} = useLocalize();
8284
@@ -249,7 +251,7 @@ export default {
249251
? this.confirmDeactivateMessage
250252
: this.confirmActivateMessage,
251253
{
252-
title: this.localize(recommendation.title),
254+
title: sanitizeHtml(this.localize(recommendation.title)),
253255
},
254256
),
255257
actions: [
@@ -362,7 +364,7 @@ export default {
362364
name: 'delete',
363365
title: this.deleteRecommendationLabel,
364366
message: this.replaceLocaleParams(this.confirmDeleteMessage, {
365-
title: this.localize(recommendation.title),
367+
title: sanitizeHtml(this.localize(recommendation.title)),
366368
}),
367369
actions: [
368370
{

src/directives/stripUnsafeHtml.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ const sanitizeConfig = {
44
USE_PROFILES: {html: true},
55
};
66

7+
export function sanitizeHtml(value) {
8+
return DOMPurify.sanitize(value, sanitizeConfig);
9+
}
10+
711
export const stripUnsafeHtml = {
812
// Called only once, when the directive is first bound to the element.
913
// This is where you can do one-time setup work.
1014
mounted(el, binding) {
1115
// Handle null and undefined values by defaulting to an empty string
1216
const value = binding.value == null ? '' : String(binding.value);
13-
const cleanContent = DOMPurify.sanitize(value, sanitizeConfig);
17+
const cleanContent = sanitizeHtml(value, sanitizeConfig);
1418
el.innerHTML = cleanContent;
1519
},
1620
// Called whenever the bound value changes.
1721
updated(el, binding) {
1822
// Only re-sanitize and update if the value has changed, handling null and undefined
1923
if (binding.value !== binding.oldValue) {
2024
const value = binding.value == null ? '' : String(binding.value);
21-
const cleanContent = DOMPurify.sanitize(value, sanitizeConfig);
25+
const cleanContent = sanitizeHtml(value, sanitizeConfig);
2226
el.innerHTML = cleanContent;
2327
}
2428
},

0 commit comments

Comments
 (0)