• Stars
    star
    387
  • Rank 110,586 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use DOMPurify on server and client in the same way

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-dompurify Node.js Environment
<=0.19.0 >=12 Server
>=0.20.0 >=14 Server

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

  1. Import the library:
// Import a necessary function in the ES6 way (recommended):
import { sanitize, isSupported } from "isomorphic-dompurify";

// or the entire module:
import DOMPurify from 'isomorphic-dompurify';

// or as a CommonJS module:
const DOMPurify = require('isomorphic-dompurify');
  1. Sanitize a string:
const clean = DOMPurify.sanitize(dirty);

Known Issues

  1. Can't resolve 'canvas' on Next.js serverless app
  2. 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

More Repositories

1

laravel-translatable-string-exporter

Translatable String Exporter for Laravel
PHP
301
star
2

insecres

A console tool that finds insecure resources on HTTPS sites
Go
40
star
3

sui-dapp-starter

Full-Stack Sui Starter on Steroids
TypeScript
23
star
4

react-select-customization-examples

React Select Customization Examples
TypeScript
9
star
5

susyboot

Susy-powered Bootstrap grid replacement
CSS
8
star
6

create-fhenix-dapp

"Create React App" for Fhenix DApps
TypeScript
6
star
7

designless

Bootstrap 3 powered Drupal 7 theme with minimalistic design intended for personal blogs and other content centered sites.
CSS
5
star
8

sui-explorer-local

Local Sui Explorer: Cli
JavaScript
5
star
9

grunt-kickstart

Basic configuration for Grunt with SASS, Compass and LiveReload
JavaScript
4
star
10

yashare_counters_update

Yandex.Share with Counters Update (Drupal 7 module)
PHP
3
star
11

tailwindcss-counter

Tailwind CSS plugin to generate counter utilities
JavaScript
3
star
12

ashtangamoon-solid

Progressive Web App (PWA) for keeping track of full and new moon days
TypeScript
3
star
13

drupal_bulk_upgrade

Shell script for bulk upgrade of Drupal sites
Shell
2
star
14

idna_convert

The project moved from Drupal.org because of their license policies. The code is under GPL, but it includes a LGPL library.
2
star
15

marrysign

MarrySign (Backend/Blockchain)
TypeScript
2
star
16

create-sui-dapp

Sui dApp Starter: Cli
TypeScript
2
star
17

vue_drupal_demo

Drupal 8 module that implements demo functionality for Vue.js presentation given at DrupalCamp Krasnodar 2016
PHP
2
star
18

picback

A simple Angular app that consumes Drupal 8 RESTful WebServices. It allows to leave feedback in the format of pictures.
JavaScript
2
star
19

qrcoder

Drupal 8 module that provides QR Code field formatter for the core Link field.
PHP
2
star
20

ashtangamoon-vanilla

Progressive Web App (PWA) for keeping track of full and new moon days
JavaScript
2
star
21

rwdemo_drupal

Demo Drupal theme for the "Responsive Web Design & Drupal" presentation at Drupal White Nights 2014.
PHP
1
star
22

sui-dapp-kit-theme-creator

Turns colors into Sui dApp Kit themes
TypeScript
1
star
23

icearrow-extension

Chrome Extension for IceArrow
JavaScript
1
star
24

catchsmile

Catch a Smile Drupal 7 module
JavaScript
1
star
25

kafka-experiment-1

A Kafka experiment
JavaScript
1
star
26

RWDemo

Responsive Web Design demonstration for my presentation at Evercode Talks 3
1
star
27

nextjs-image-optimization-examples

Code examples for the Next.js image optimization tutorial https://uploadcare.com/blog/next-js-image-optimization/
JavaScript
1
star
28

catchsmile-wp7

Catch a Smile Windows Phone 7 application
C#
1
star
29

sui-dapp-starter.dev

Sui dApp Starter SIte
TypeScript
1
star