Skip to content

Commit 9c575e3

Browse files
committed
🔒️(frontend) remove dangerouslySetInnerHTML from codebase
dangerouslySetInnerHTML were introduced to quickly render translated strings containing HTML, but they can lead to security vulnerabilities if not handled properly. Better to use React components to ensure safety.
1 parent a6b472a commit 9c575e3

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to
1515
- ♿(frontend) improve accessibility:
1616
- ♿(frontend) add skip to content button for keyboard accessibility #1624
1717
- ♿(frontend) fix toggle panel button a11y labels #1634
18+
- 🔒️(frontend) remove dangerouslySetInnerHTML from codebase #1712
1819
- ⚡️(frontend) improve Comments feature #1687
1920

2021
### Fixed

src/frontend/apps/impress/src/features/docs/docs-grid/components/DocGridContentList.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { TreeViewMoveModeEnum } from '@gouvfr-lasuite/ui-kit';
44
import { useModal } from '@openfun/cunningham-react';
55
import { useQueryClient } from '@tanstack/react-query';
66
import { useMemo, useRef } from 'react';
7-
import { useTranslation } from 'react-i18next';
7+
import { Trans, useTranslation } from 'react-i18next';
88

99
import { AlertModal, Card, Text } from '@/components';
10-
import { Doc, KEY_LIST_DOC } from '@/docs/doc-management';
10+
import { Doc, KEY_LIST_DOC, useTrans } from '@/docs/doc-management';
1111
import {
1212
getDocAccesses,
1313
getDocInvitations,
@@ -60,6 +60,7 @@ export const DraggableDocGridContentList = ({
6060
const { mutate: handleDeleteInvitation } = useDeleteDocInvitation();
6161
const { mutate: handleDeleteAccess } = useDeleteDocAccess();
6262
const onDragData = useRef<DocDragEndData | null>(null);
63+
const { untitledDocument } = useTrans();
6364

6465
const handleMoveDoc = async () => {
6566
if (!onDragData.current) {
@@ -144,8 +145,8 @@ export const DraggableDocGridContentList = ({
144145
return t('You must be at least the administrator of the target document');
145146
}
146147

147-
return selectedDoc?.title || t('Unnamed document');
148-
}, [canDrag, canDrop, selectedDoc, t]);
148+
return selectedDoc?.title || untitledDocument;
149+
}, [canDrag, canDrop, selectedDoc?.title, t, untitledDocument]);
149150

150151
const cannotMoveDoc =
151152
!canDrag || (canDrop !== undefined && !canDrop) || isError;
@@ -193,17 +194,16 @@ export const DraggableDocGridContentList = ({
193194
{...modalConfirmation}
194195
title={t('Move document')}
195196
description={
196-
<span
197-
dangerouslySetInnerHTML={{
198-
__html: t(
199-
'By moving this document to <strong>{{targetDocumentTitle}}</strong>, it will lose its current access rights and inherit the permissions of that document. <strong>This access change cannot be undone.</strong>',
200-
{
201-
targetDocumentTitle:
202-
onDragData.current?.target.title ?? t('Unnamed document'),
203-
},
204-
),
205-
}}
206-
/>
197+
<Text $display="inline">
198+
<Trans
199+
i18nKey="By moving this document to <strong>{{targetDocumentTitle}}</strong>, it will lose its current access rights and inherit the permissions of that document. <strong>This access change cannot be undone.</strong>"
200+
values={{
201+
targetDocumentTitle:
202+
onDragData.current?.target.title ?? untitledDocument,
203+
}}
204+
components={{ strong: <strong /> }}
205+
/>
206+
</Text>
207207
}
208208
confirmLabel={t('Move')}
209209
onConfirm={() => {

0 commit comments

Comments
 (0)