Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html-sanitize): replace html-sanitize with dom-purify because of bug #81

Merged
merged 3 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@types/react-copy-to-clipboard": "5.0.2",
"@types/react-dom": "17.0.11",
"@types/react-table": "7.7.10",
"@types/sanitize-html": "2.6.2",
"@types/sort-object-keys": "1.1.0",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
Expand Down
96 changes: 36 additions & 60 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@meemoo/react-components": "2.21.5",
"@studiohyperdrive/pagination": "1.0.0",
"@tanstack/react-query": "^4.14.1",
"@viaa/avo2-components": "3.1.1",
"@viaa/avo2-components": "3.1.3",
"@viaa/avo2-types": "2.46.4",
"graphql": "16.6.0",
"immer": "9.0.12",
Expand All @@ -51,6 +51,7 @@
"clsx": "^1.1.1",
"copy-to-clipboard": "3.3.1",
"date-fns": "2.28.0",
"dompurify": "^2.4.1",
"file-saver": "^2.0.5",
"i18next-http-backend": "^1.4.1",
"ky": "0.30.0",
Expand All @@ -63,8 +64,7 @@
"react-scrollbars-custom": "4.1.1",
"react-select": "^5.2.2",
"react-table": "7.7.0",
"react-to-string": "^0.1.1",
"sanitize-html": "2.7.0"
"react-to-string": "^0.1.1"
},
"devDependencies": {
"@commitlint/cli": "16.1.0",
Expand All @@ -82,6 +82,7 @@
"@tanstack/react-query": "^4.14.1",
"@testing-library/jest-dom": "5.16.2",
"@testing-library/react": "12.1.2",
"@types/dompurify": "^2.4.0",
"@types/file-saver": "^2.0.5",
"@types/jest": "^27.4.0",
"@types/lodash-es": "4.17.6",
Expand All @@ -93,7 +94,6 @@
"@types/react-router": "5.1.18",
"@types/react-router-dom": "5.3.3",
"@types/react-table": "7.7.10",
"@types/sanitize-html": "2.6.2",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "5.11.0",
"@viaa/avo2-components": "3.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added that.
One is a peer dependency, but you added it to dev dependencies as well to make sure it is always installed in the developer machine.
although i ran into the issue a few times where i update the peer dependency and nothing changes, because i also need to change it in the dev dependency section

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from './defaults';

import { AdminConfigManager } from '~core/config';
import { DatabaseType } from '@viaa/avo2-types';

export const INITIAL_MEDIA_GRID_COMPONENTS_STATE = (): MediaGridBlockComponentState[] => [{}];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import { Avo } from '@viaa/avo2-types';
import { isArray, isFunction, isPlainObject, kebabCase } from 'lodash-es';
import moment from 'moment';
import { stringifyUrl } from 'query-string';

import { AdminConfigManager } from '~core/config';
import { ContentPageOverviewParams } from '~modules/content-page/components/wrappers/PageOverviewWrapper/PageOverviewWrapper';
import { PAGES_PER_PAGE } from '~modules/content-page/const/content-page.consts';
import { RichEditorStateKey } from '~modules/content-page/const/rich-text-editor.consts';
import { CONTENT_PAGE_SERVICE_BASE_URL } from '~modules/content-page/services/content-page.const';
import {
convertContentPageInfoToDbContentPage,
convertDbContentPagesToContentPageInfos,
convertDbContentPageToContentPageInfo
convertDbContentPageToContentPageInfo,
} from '~modules/content-page/services/content-page.converters';
import { CustomError } from '~modules/shared/helpers/custom-error';

import { fetchWithLogoutJson } from '../../shared/helpers/fetch-with-logout';
import { mapDeep } from '../../shared/helpers/map-deep/map-deep';
import { sanitizeHtml } from '../../shared/helpers/sanitize';
import { SanitizePreset } from '../../shared/helpers/sanitize/presets';
import { ContentBlockConfig } from '../types/content-block.types';

import { AdminConfigManager } from '~core/config';
import { CustomError } from '~modules/shared/helpers/custom-error';
import { CONTENT_PAGE_SERVICE_BASE_URL } from '~modules/content-page/services/content-page.const';
import { RichEditorStateKey } from '~modules/content-page/const/rich-text-editor.consts';
import {
ContentOverviewTableCols,
ContentPageInfo,
Expand Down Expand Up @@ -267,10 +267,11 @@ export class ContentPageService {
if (value && value.toHTML && isFunction(value.toHTML)) {
htmlFromRichTextEditor = value.toHTML();
}
obj[htmlKey] = sanitizeHtml(
const sanitizedHtml = sanitizeHtml(
htmlFromRichTextEditor || obj[htmlKey] || '',
'full'
SanitizePreset.full
);
obj[htmlKey] = sanitizedHtml;
} else if (!isPlainObject(value) && !isArray(value)) {
obj[key] = value;
} else if (isPlainObject(value)) {
Expand Down Expand Up @@ -391,7 +392,7 @@ export class ContentPageService {

public static getDescription(
contentPageInfo: ContentPageInfo,
sanitizePreset: SanitizePreset = 'link'
sanitizePreset: SanitizePreset = SanitizePreset.link
): string | null {
const description = (contentPageInfo as any).description_state
? (contentPageInfo as any).description_state.toHTML()
Expand All @@ -407,7 +408,9 @@ export class ContentPageService {
try {
const dbContentPage = await fetchWithLogoutJson<DbContentPage | null>(
stringifyUrl({
url: AdminConfigManager.getConfig().services.getContentPageByPathEndpoint || this.getBaseUrl(),
url:
AdminConfigManager.getConfig().services.getContentPageByPathEndpoint ||
this.getBaseUrl(),
query: {
path,
},
Expand All @@ -416,9 +419,7 @@ export class ContentPageService {
if (!dbContentPage) {
return null;
}
return convertDbContentPageToContentPageInfo(
dbContentPage
);
return convertDbContentPageToContentPageInfo(dbContentPage);
} catch (err) {
throw new CustomError('Failed to get content page by path', err);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { compact, get } from 'lodash-es';
import moment from 'moment';
import React, { FunctionComponent } from 'react';

import {
BlockHeading,
Container,
Expand All @@ -12,6 +8,9 @@ import {
TagOption,
Thumbnail,
} from '@viaa/avo2-components';
import { compact, get } from 'lodash-es';
import moment from 'moment';
import React, { FunctionComponent } from 'react';
Comment on lines +11 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this throw linting warnings about import groups?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no for me it doesn't
might have something to do with the monorepo and split version of the .eslint config file

I'll look at it some other time.

import { GET_CONTENT_PAGE_WIDTH_OPTIONS } from '~modules/content-page/const/content-page.consts';
import { useContentTypes } from '~modules/content-page/hooks/useContentTypes';
import { ContentPageService } from '~modules/content-page/services/content-page.service';
Expand All @@ -23,6 +22,7 @@ import {
renderDetailRow,
renderSimpleDetailRows,
} from '~modules/shared/helpers/render-detail-fields';
import { SanitizePreset } from '~modules/shared/helpers/sanitize/presets';
import { useTranslation } from '~modules/shared/hooks/useTranslation';
import { useUserGroupOptions } from '~modules/user-group/hooks/useUserGroupOptions';

Expand Down Expand Up @@ -102,7 +102,7 @@ export const ContentPageDetailMetaData: FunctionComponent<ContentDetailMetaDataP

return tHtml('admin/content/views/content-detail-meta-data___nee');
};
const description = ContentPageService.getDescription(contentPageInfo, 'full');
const description = ContentPageService.getDescription(contentPageInfo, SanitizePreset.full);
return (
<Container mode="vertical" size="small">
<Container mode="horizontal">
Expand All @@ -111,7 +111,7 @@ export const ContentPageDetailMetaData: FunctionComponent<ContentDetailMetaDataP
<BlockHeading type="h4">
{tHtml('admin/content/views/content-detail___omschrijving')}
</BlockHeading>
<Html content={description || '-'} sanitizePreset="full" />
<Html content={description || '-'} sanitizePreset={SanitizePreset.full} />
</Spacer>
)}

Expand Down
Loading