🔒️(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.
This commit is contained in:
@@ -15,6 +15,7 @@ and this project adheres to
|
|||||||
- ♿(frontend) improve accessibility:
|
- ♿(frontend) improve accessibility:
|
||||||
- ♿(frontend) add skip to content button for keyboard accessibility #1624
|
- ♿(frontend) add skip to content button for keyboard accessibility #1624
|
||||||
- ♿(frontend) fix toggle panel button a11y labels #1634
|
- ♿(frontend) fix toggle panel button a11y labels #1634
|
||||||
|
- 🔒️(frontend) remove dangerouslySetInnerHTML from codebase #1712
|
||||||
- ⚡️(frontend) improve Comments feature #1687
|
- ⚡️(frontend) improve Comments feature #1687
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import { TreeViewMoveModeEnum } from '@gouvfr-lasuite/ui-kit';
|
|||||||
import { useModal } from '@openfun/cunningham-react';
|
import { useModal } from '@openfun/cunningham-react';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { useMemo, useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { Trans, useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { AlertModal, Card, Text } from '@/components';
|
import { AlertModal, Card, Text } from '@/components';
|
||||||
import { Doc, KEY_LIST_DOC } from '@/docs/doc-management';
|
import { Doc, KEY_LIST_DOC, useTrans } from '@/docs/doc-management';
|
||||||
import {
|
import {
|
||||||
getDocAccesses,
|
getDocAccesses,
|
||||||
getDocInvitations,
|
getDocInvitations,
|
||||||
@@ -60,6 +60,7 @@ export const DraggableDocGridContentList = ({
|
|||||||
const { mutate: handleDeleteInvitation } = useDeleteDocInvitation();
|
const { mutate: handleDeleteInvitation } = useDeleteDocInvitation();
|
||||||
const { mutate: handleDeleteAccess } = useDeleteDocAccess();
|
const { mutate: handleDeleteAccess } = useDeleteDocAccess();
|
||||||
const onDragData = useRef<DocDragEndData | null>(null);
|
const onDragData = useRef<DocDragEndData | null>(null);
|
||||||
|
const { untitledDocument } = useTrans();
|
||||||
|
|
||||||
const handleMoveDoc = async () => {
|
const handleMoveDoc = async () => {
|
||||||
if (!onDragData.current) {
|
if (!onDragData.current) {
|
||||||
@@ -144,8 +145,8 @@ export const DraggableDocGridContentList = ({
|
|||||||
return t('You must be at least the administrator of the target document');
|
return t('You must be at least the administrator of the target document');
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectedDoc?.title || t('Unnamed document');
|
return selectedDoc?.title || untitledDocument;
|
||||||
}, [canDrag, canDrop, selectedDoc, t]);
|
}, [canDrag, canDrop, selectedDoc?.title, t, untitledDocument]);
|
||||||
|
|
||||||
const cannotMoveDoc =
|
const cannotMoveDoc =
|
||||||
!canDrag || (canDrop !== undefined && !canDrop) || isError;
|
!canDrag || (canDrop !== undefined && !canDrop) || isError;
|
||||||
@@ -193,17 +194,16 @@ export const DraggableDocGridContentList = ({
|
|||||||
{...modalConfirmation}
|
{...modalConfirmation}
|
||||||
title={t('Move document')}
|
title={t('Move document')}
|
||||||
description={
|
description={
|
||||||
<span
|
<Text $display="inline">
|
||||||
dangerouslySetInnerHTML={{
|
<Trans
|
||||||
__html: t(
|
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>"
|
||||||
'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>',
|
values={{
|
||||||
{
|
targetDocumentTitle:
|
||||||
targetDocumentTitle:
|
onDragData.current?.target.title ?? untitledDocument,
|
||||||
onDragData.current?.target.title ?? t('Unnamed document'),
|
}}
|
||||||
},
|
components={{ strong: <strong /> }}
|
||||||
),
|
/>
|
||||||
}}
|
</Text>
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
confirmLabel={t('Move')}
|
confirmLabel={t('Move')}
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user