Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

DOMPurify

No security coverage Under active development

Provides the DOMPurify XSS sanitizer as the Drupal library dompurify/dompurify.

Modules and themes add it as a library dependency instead of each shipping their own copy, so DOMPurify loads once per page.

Usage

Declare the library as a dependency in your *.libraries.yml:

my-library:
  js:
    js/my_library.js: {}
  dependencies:
    - core/drupal
    - core/once
    - dompurify/dompurify

Sanitize untrusted HTML before inserting it into the page:

(function (Drupal, once, DOMPurify) {
  Drupal.behaviors.myLibrary = {
    attach(context) {
      once('my-library', '[data-untrusted-html]', context).forEach((element) => {
        element.innerHTML = DOMPurify.sanitize(element.dataset.untrustedHtml, {
          USE_PROFILES: { html: true },
        });
      });
    },
  };
})(Drupal, once, DOMPurify);

Library source

By default DOMPurify 3.5.0 loads from the jsDelivr CDN with a Subresource Integrity hash. If libraries/dompurify/dist/purify.min.js exists, the module serves that local copy instead. See README.md to install it with Composer through Asset Packagist.

Documentation

Drupal 10–11

Ask your assistant about DOMPurify

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Dec 2026
Latest release
8 hours ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Releases

Version Type Core PHP Release date
1.0.0 Stable 10–11 Dec 1, 2026
1.0.x-dev Dev 10–11 Dec 1, 2026