Skip to content

Commit

Permalink
Fix <RichTextField> XSS vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Feb 13, 2023
1 parent 663435c commit c2113b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import useListSortContext from './useListSortContext';

export type {
ListControllerProps,
ListPaginationContextValue,
PaginationHookResult,
SortProps,
UseReferenceProps,
Expand All @@ -42,7 +43,6 @@ export {
ListContext,
ListFilterContext,
ListPaginationContext,
ListPaginationContextValue,
ListSortContext,
ListContextProvider,
useCheckMinimumRequiredProps,
Expand Down
1 change: 1 addition & 0 deletions packages/ra-ui-materialui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"classnames": "~2.2.5",
"connected-react-router": "^6.5.2",
"css-mediaquery": "^0.1.2",
"dompurify": "^2.4.3",
"downshift": "3.2.7",
"inflection": "~1.13.1",
"jsonexport": "^2.4.1",
Expand Down
7 changes: 6 additions & 1 deletion packages/ra-ui-materialui/src/field/RichTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import get from 'lodash/get';
import Typography, { TypographyProps } from '@material-ui/core/Typography';
import { useRecordContext } from 'ra-core';
import purify from 'dompurify';

import sanitizeFieldRestProps from './sanitizeFieldRestProps';
import { InjectedFieldProps, PublicFieldProps, fieldPropTypes } from './types';
Expand All @@ -29,7 +30,11 @@ const RichTextField: FC<RichTextFieldProps> = memo<RichTextFieldProps>(
) : stripTags ? (
removeTags(value)
) : (
<span dangerouslySetInnerHTML={{ __html: value }} />
<span
dangerouslySetInnerHTML={{
__html: purify.sanitize(value),
}}
/>
)}
</Typography>
);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8144,6 +8144,11 @@ domhandler@^4.2.0, domhandler@^4.3.0:
dependencies:
domelementtype "^2.2.0"

dompurify@^2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.4.3.tgz#f4133af0e6a50297fc8874e2eaedc13a3c308c03"
integrity sha512-q6QaLcakcRjebxjg8/+NP+h0rPfatOgOzc46Fst9VAA3jF2ApfKBNKMzdP4DYTqtUMXSCd5pRS/8Po/OmoCHZQ==

[email protected]:
version "1.5.1"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"
Expand Down

0 comments on commit c2113b8

Please sign in to comment.