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

refactor(config): expose sanitizeSvg function, fix diffing logic #2862

Merged
merged 3 commits into from
Oct 26, 2022

Conversation

emmenko
Copy link
Member

@emmenko emmenko commented Oct 26, 2022

I noticed when using the CLI config:sync command that the SVG icon was always marked as changed.

The problem is in the fact that the API sanitizes the SVG before saving the data but we were also pre-sanitizing it when the config was parsed. This lead to updates to have run the sanitize 2 times.

Now we don't sanitize when parsing the icon but only during the diffing, so ensure the diffed data is the same.

@changeset-bot
Copy link

changeset-bot bot commented Oct 26, 2022

🦋 Changeset detected

Latest commit: a4238ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
@commercetools-frontend/application-config Patch
@commercetools-frontend/mc-scripts Patch
@commercetools-frontend/application-shell Patch
@commercetools-frontend/cypress Patch
@commercetools-frontend/mc-dev-authentication Patch
@commercetools-frontend/mc-html-template Patch
@commercetools-applications/merchant-center-template-starter-typescript Patch
@commercetools-applications/merchant-center-template-starter Patch
@commercetools-local/playground Patch
@commercetools-backend/eslint-config-node Patch
@commercetools-backend/express Patch
@commercetools-backend/loggers Patch
@commercetools-frontend/actions-global Patch
@commercetools-frontend/application-components Patch
@commercetools-frontend/application-shell-connectors Patch
@commercetools-frontend/assets Patch
@commercetools-frontend/babel-preset-mc-app Patch
@commercetools-frontend/browser-history Patch
@commercetools-frontend/codemod Patch
@commercetools-frontend/constants Patch
@commercetools-frontend/create-mc-app Patch
@commercetools-frontend/eslint-config-mc-app Patch
@commercetools-frontend/i18n Patch
@commercetools-frontend/jest-preset-mc-app Patch
@commercetools-frontend/jest-stylelint-runner Patch
@commercetools-frontend/l10n Patch
@commercetools-frontend/notifications Patch
@commercetools-frontend/permissions Patch
@commercetools-frontend/react-notifications Patch
@commercetools-frontend/sdk Patch
@commercetools-frontend/sentry Patch
@commercetools-frontend/url-utils Patch
@commercetools-local/visual-testing-app Patch
@commercetools-website/custom-applications Patch
@commercetools-website/components-playground Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -1 +1,2 @@
export * from './formatters';
export { default as sanitizeSvg } from './sanitize-svg';
Copy link
Member Author

Choose a reason for hiding this comment

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

So that we can use the same logic in the backend.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 26, 2022

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-oahkttxjf-commercetools.vercel.app
https://appkit-sha-f6c58e59ac2cb0260f143ed99421bdabacec38f6.commercetools.vercel.app
https://appkit-pr-2862.commercetools.vercel.app

Built with commit a4238ac.
This pull request is being automatically deployed with vercel-action

Comment on lines +11 to +16
RETURN_DOM: true,
FORBID_ATTR: [
// To avoid injection by using `style="filter:url(\"data:image/svg+xml,<svg`
'style',
],
});
}).innerHTML;
Copy link
Contributor

@CarlosCortizasCT CarlosCortizasCT Oct 26, 2022

Choose a reason for hiding this comment

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

Could you perhaps explain what this changes are meant for?
Is it to sanitize the same way it's done in the API?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes sorry. We already changed this in the backend, due to some security findings.

image

https://research.securitum.com/mutation-xss-via-mathml-mutation-dompurify-2-0-17-bypass/

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation 👍

Copy link
Contributor

@kark kark Oct 26, 2022

Choose a reason for hiding this comment

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

Wowzers, thanks for explaining 🙏 I guess we should remember to change that then in the <InlineSvg> component from the ui-kit too (probably as part of the upcoming svg changes)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good point!

Copy link
Contributor

@CarlosCortizasCT CarlosCortizasCT left a comment

Choose a reason for hiding this comment

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

👍

@emmenko emmenko merged commit 836c86a into main Oct 26, 2022
@emmenko emmenko deleted the nm-export-sanitize-svg branch October 26, 2022 13:38
@ghost ghost mentioned this pull request Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants