2.7.0 • Published 11 days ago

isomorphic-dompurify v2.7.0

Weekly downloads
44,880
License
MIT
Repository
github
Last release
11 days ago

Isomorphic DOMPurify

npm version Test Status Bundlephobia Minified Size

The library makes it possible to seamlessly use DOMPurify on server and client in the same way. It does nothing by itself except providing an isomorphic/universal wrapper around DOMPurify, so all credits go to DOMPurify authors and contributors.

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks.

Motivation

DOMPurify needs a DOM tree to base on, which is not available in Node by default. To work on the server side, we need a fake DOM to be created and supplied to DOMPurify. It means that DOMPurify initialization logic on the server is not the same as on the client.

This project was born with the idea of encapsulating DOMPurify initialization details and providing an easy way to import the library on both, server and client, for example in Next.js apps.

It was inspired by Isomorphic Unfetch.

Requirements

isomorphic-dompurifyNode.jsEnvironment
<=0.19.0>=12Server
>=0.20.0>=14Server
>=1.4.0>=16Server
>=1.10.0>=18Server

Installation

$ npm i isomorphic-dompurify

Updates

Please note that DOMPurify library doesn't follow Semantic Versioning, so we have to release every change as a minor version because we cannot be 100% sure whether new features are added to patch DOMPurify releases or not.

Usage

Import:

import DOMPurify from "isomorphic-dompurify";

Importing the entire module for the client/browser version is recommended.

Sanitize:

const clean = DOMPurify.sanitize(dirtyString);

or with config:

const clean = DOMPurify.sanitize(dirtyString, { USE_PROFILES: { html: true } });

Known Issues

  1. Next.js and Remix are mistakenly trying to use the browser entry point on server, which causes the Window is not defined issue. #228 #214 https://github.com/vercel/next.js/discussions/58142
  2. Can't resolve 'canvas' on Next.js serverless app
  3. Starting from 0.16.0, there is a dependency conflict which causes ReferenceError: TextEncoder is not defined

License

DOMPurify - Apache 2.0 or MPL 2.0 © 2015 Mario Heiderich

Isomorphic DOMPurify - MIT License © 2020 Konstantin Komelin and contributors

@carbon/ibmdotcom-utilities@steakwallet/chains@infinitebrahmanuniverse/nolb-isoprocare-nordic-apinocodb-daily@everything-registry/sub-chunk-1937dumbo-sveltedocusaurus-docgendraftndjedi-reacteditmode-react-native@xyfun/uiextract-site-metadatagatsby-plugin-jaengatsby-jaen-mailpresstest-platform-x-prelemsezchainjs2frontend-hb--web-appjobiqo-cl-vanillavue-emailvue-email-edgehtml-converter-jshtml-converter-reactvue-lionvue-text-stylertoast-ui-modified-calendartui-calendar-angulartypedoc-plugin-dompurifyjxl-pdfhugo-lyraweb-marketing-starterwc-toast-calendari18next-dompurify-postprocessorigi-pq8-sdkmarkdown-it-dompurifymarkdownz@lumjs/doxsnahtuh-client@metahkg/server@lisanwade/pq8-sdk@lqjun/calendarmarkdown-publishjsdom-web-componentsleno-shared-componentsmetahkg-server@knapsack/update@levelcommerce/server@launchpad-ui/markdownnocodbnocodb-tomorrownocodb-wooter@mxsoft/tui-calendarpolaris-toast-ui-calendar@eox/storytellingplugin-wp-importer@reality.eth/reality-eth-lib@emanager/asyncapi-react-componentpq8-sdkspq8sdk@rmrk-team/rmrk-2d-renderer@rmrk-team/rmrk-hooksoss-translator@payvo/sdk-avax@predocs/components@neuvernetzung/design-systemplatform-x-prelems@officex/corenuxt-openapi-docs-module@rubensdeoliveira-ui/react@ezclabs/ezchainjs@baosight/efaurelia-slickgridastro-mastodon@avsync.live/formationscratch-svg-rendererarticle-archiver@bookmate/web-ui-kit@bezda/rhpreact-daedae-testreact-gardenreact-helsinki-headless-cms@accelbyte/widgets-v2@andrewdw/calendarsanity-plugin-inline-icon-manager@auspayplus/open-payments-checkout@wulperstudio/editor-renderreactive-framework-jsreact-purified@wincast/calendar@vue-email/core@vishnu10000/casa-ui@vishnu10000/casa-ui-library@sveltia/cms@stakekit/signers@sportsgram/ui-kit@slickgrid-universal/common@slickgrid-universal/custom-tooltip-plugin@toast-ui/calendarreact-ai-search-bar@zeno-ml/zeno-instance-views
2.7.0

11 days ago

2.6.0

29 days ago

2.5.0

1 month ago

2.4.0

2 months ago

2.3.0

3 months ago

2.2.0

3 months ago

2.1.0

4 months ago

2.0.0

4 months ago

1.13.0

4 months ago

1.12.0

4 months ago

1.11.0

5 months ago

1.10.0

5 months ago

1.9.0

7 months ago

1.8.0

9 months ago

1.7.0

10 months ago

1.6.0

11 months ago

1.5.0

12 months ago

1.4.0

12 months ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

0.27.0

1 year ago

0.26.0

1 year ago

0.25.0

1 year ago

0.24.0

1 year ago

0.23.0

2 years ago

0.21.0

2 years ago

0.22.0

2 years ago

0.20.0

2 years ago

0.19.0

2 years ago

0.17.0

2 years ago

0.18.0

2 years ago

0.16.0

2 years ago

0.15.0

3 years ago

0.14.0

3 years ago

0.13.0

3 years ago

0.12.0

3 years ago

0.11.0

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago