{"id":13458864,"url":"https://github.com/cure53/DOMPurify","last_synced_at":"2025-03-24T16:31:02.831Z","repository":{"id":14220784,"uuid":"16927692","full_name":"cure53/DOMPurify","owner":"cure53","description":"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. Demo:","archived":false,"fork":false,"pushed_at":"2025-03-16T15:38:41.000Z","size":9723,"stargazers_count":14776,"open_issues_count":1,"forks_count":766,"subscribers_count":154,"default_branch":"main","last_synced_at":"2025-03-17T22:31:54.984Z","etag":null,"topics":["cross-site-scripting","dom","dompurify","html","javascript","mathml","prevent-xss-attacks","sanitizer","security","svg","xss"],"latest_commit_sha":null,"homepage":"https://cure53.de/purify","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cure53.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"cure53"}},"created_at":"2014-02-17T21:48:14.000Z","updated_at":"2025-03-17T20:43:06.000Z","dependencies_parsed_at":"2023-01-14T12:30:22.458Z","dependency_job_id":"7f69c37e-0c74-4c6c-a057-f2cf2223d52a","html_url":"https://github.com/cure53/DOMPurify","commit_stats":{"total_commits":1660,"total_committers":116,"mean_commits":"14.310344827586206","dds":0.4126506024096386,"last_synced_commit":"2cf6e2510699261a0004e3431c4e8a0bbd65b230"},"previous_names":[],"tags_count":128,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cure53%2FDOMPurify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cure53%2FDOMPurify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cure53%2FDOMPurify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cure53%2FDOMPurify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cure53","download_url":"https://codeload.github.com/cure53/DOMPurify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244119616,"owners_count":20401021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-site-scripting","dom","dompurify","html","javascript","mathml","prevent-xss-attacks","sanitizer","security","svg","xss"],"created_at":"2024-07-31T09:00:59.006Z","updated_at":"2025-03-24T16:31:02.823Z","avatar_url":"https://github.com/cure53.png","language":"JavaScript","readme":"# DOMPurify\n\n[![npm version](https://badge.fury.io/js/dompurify.svg)](http://badge.fury.io/js/dompurify) ![Build and Test](https://github.com/cure53/DOMPurify/workflows/Build%20and%20Test/badge.svg) [![Downloads](https://img.shields.io/npm/dm/dompurify.svg)](https://www.npmjs.com/package/dompurify) ![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/dompurify?color=%233C1\u0026label=minified) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/cure53/dompurify?color=%233C1) [![dependents](https://badgen.net/github/dependents-repo/cure53/dompurify?color=green\u0026label=dependents)](https://github.com/cure53/DOMPurify/network/dependents)\n\nDOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.\n\nIt's also very simple to use and get started with. DOMPurify was [started in February 2014](https://github.com/cure53/DOMPurify/commit/a630922616927373485e0e787ab19e73e3691b2b) and, meanwhile, has reached version **v3.2.4**.\n\nDOMPurify is written in JavaScript and works in all modern browsers (Safari (10+), Opera (15+), Edge, Firefox and Chrome - as well as almost anything else using Blink, Gecko or WebKit). It doesn't break on MSIE or other legacy browsers. It simply does nothing.\n\n**Note that [DOMPurify v2.5.8](https://github.com/cure53/DOMPurify/releases/tag/2.5.8) is the latest version supporting MSIE. For important security updates compatible with MSIE, please use the [2.x branch](https://github.com/cure53/DOMPurify/tree/2.x).**\n\nOur automated tests cover [28 different browsers](https://github.com/cure53/DOMPurify/blob/main/test/karma.custom-launchers.config.js#L5) right now, more to come. We also cover Node.js v17.x, v18.x, v19.x, v20.x, v21.x and v22.x, running DOMPurify on [jsdom](https://github.com/jsdom/jsdom). Older Node versions are known to work as well, but hey... no guarantees.\n\nDOMPurify is written by security people who have vast background in web attacks and XSS. Fear not. For more details please also read about our [Security Goals \u0026 Threat Model](https://github.com/cure53/DOMPurify/wiki/Security-Goals-\u0026-Threat-Model). Please, read it. Like, really.\n\n## What does it do?\n\nDOMPurify sanitizes HTML and prevents XSS attacks. You can feed DOMPurify with string full of dirty HTML and it will return a string (unless configured otherwise) with clean HTML. DOMPurify will strip out everything that contains dangerous HTML and thereby prevent XSS attacks and other nastiness. It's also damn bloody fast. We use the technologies the browser provides and turn them into an XSS filter. The faster your browser, the faster DOMPurify will be.\n\n## How do I use it?\n\nIt's easy. Just include DOMPurify on your website.\n\n### Using the unminified development version\n\n```html\n\u003cscript type=\"text/javascript\" src=\"src/purify.js\"\u003e\u003c/script\u003e\n```\n\n### Using the minified and tested production version (source-map available)\n\n```html\n\u003cscript type=\"text/javascript\" src=\"dist/purify.min.js\"\u003e\u003c/script\u003e\n```\n\nAfterwards you can sanitize strings by executing the following code:\n\n```js\nconst clean = DOMPurify.sanitize(dirty);\n```\n\nOr maybe this, if you love working with Angular or alike:\n\n```js\nimport DOMPurify from 'dompurify';\n\nconst clean = DOMPurify.sanitize('\u003cb\u003ehello there\u003c/b\u003e');\n```\n\nThe resulting HTML can be written into a DOM element using `innerHTML` or the DOM using `document.write()`. That is fully up to you.\nNote that by default, we permit HTML, SVG **and** MathML. If you only need HTML, which might be a very common use-case, you can easily set that up as well:\n\n```js\nconst clean = DOMPurify.sanitize(dirty, { USE_PROFILES: { html: true } });\n```\n\n### Is there any foot-gun potential?\n\nWell, please note, if you _first_ sanitize HTML and then modify it _afterwards_, you might easily **void the effects of sanitization**. If you feed the sanitized markup to another library _after_ sanitization, please be certain that the library doesn't mess around with the HTML on its own.\n\n### Okay, makes sense, let's move on\n\nAfter sanitizing your markup, you can also have a look at the property `DOMPurify.removed` and find out, what elements and attributes were thrown out. Please **do not use** this property for making any security critical decisions. This is just a little helper for curious minds.\n\n### Running DOMPurify on the server\n\nDOMPurify technically also works server-side with Node.js. Our support strives to follow the [Node.js release cycle](https://nodejs.org/en/about/releases/).\n\nRunning DOMPurify on the server requires a DOM to be present, which is probably no surprise. Usually, [jsdom](https://github.com/jsdom/jsdom) is the tool of choice and we **strongly recommend** to use the latest version of _jsdom_.\n\nWhy? Because older versions of _jsdom_ are known to be buggy in ways that result in XSS _even if_ DOMPurify does everything 100% correctly. There are **known attack vectors** in, e.g. _jsdom v19.0.0_ that are fixed in _jsdom v20.0.0_ - and we really recommend to keep _jsdom_ up to date because of that.\n\nPlease also be aware that tools like [happy-dom](https://github.com/capricorn86/happy-dom) exist but **are not considered safe** at this point. Combining DOMPurify with _happy-dom_ is currently not recommended and will likely lead to XSS.\n\nOther than that, you are fine to use DOMPurify on the server. Probably. This really depends on _jsdom_ or whatever DOM you utilize server-side. If you can live with that, this is how you get it to work:\n\n```bash\nnpm install dompurify\nnpm install jsdom\n```\n\nFor _jsdom_ (please use an up-to-date version), this should do the trick:\n\n```js\nconst createDOMPurify = require('dompurify');\nconst { JSDOM } = require('jsdom');\n\nconst window = new JSDOM('').window;\nconst DOMPurify = createDOMPurify(window);\nconst clean = DOMPurify.sanitize('\u003cb\u003ehello there\u003c/b\u003e');\n```\n\nOr even this, if you prefer working with imports:\n\n```js\nimport { JSDOM } from 'jsdom';\nimport DOMPurify from 'dompurify';\n\nconst window = new JSDOM('').window;\nconst purify = DOMPurify(window);\nconst clean = purify.sanitize('\u003cb\u003ehello there\u003c/b\u003e');\n```\n\nIf you have problems making it work in your specific setup, consider looking at the amazing [isomorphic-dompurify](https://github.com/kkomelin/isomorphic-dompurify) project which solves lots of problems people might run into.\n\n```bash\nnpm install isomorphic-dompurify\n```\n\n```js\nimport DOMPurify from 'isomorphic-dompurify';\n\nconst clean = DOMPurify.sanitize('\u003cs\u003ehello\u003c/s\u003e');\n```\n\n## Is there a demo?\n\nOf course there is a demo! [Play with DOMPurify](https://cure53.de/purify)\n\n## What if I find a _security_ bug?\n\nFirst of all, please immediately contact us via [email](mailto:mario@cure53.de) so we can work on a fix. [PGP key](https://keyserver.ubuntu.com/pks/lookup?op=vindex\u0026search=0xC26C858090F70ADA)\n\nAlso, you probably qualify for a bug bounty! The fine folks over at [Fastmail](https://www.fastmail.com/) use DOMPurify for their services and added our library to their bug bounty scope. So, if you find a way to bypass or weaken DOMPurify, please also have a look at their website and the [bug bounty info](https://www.fastmail.com/about/bugbounty/).\n\n## Some purification samples please?\n\nHow does purified markup look like? Well, [the demo](https://cure53.de/purify) shows it for a big bunch of nasty elements. But let's also show some smaller examples!\n\n```js\nDOMPurify.sanitize('\u003cimg src=x onerror=alert(1)//\u003e'); // becomes \u003cimg src=\"x\"\u003e\nDOMPurify.sanitize('\u003csvg\u003e\u003cg/onload=alert(2)//\u003cp\u003e'); // becomes \u003csvg\u003e\u003cg\u003e\u003c/g\u003e\u003c/svg\u003e\nDOMPurify.sanitize('\u003cp\u003eabc\u003ciframe//src=jAva\u0026Tab;script:alert(3)\u003edef\u003c/p\u003e'); // becomes \u003cp\u003eabc\u003c/p\u003e\nDOMPurify.sanitize('\u003cmath\u003e\u003cmi//xlink:href=\"data:x,\u003cscript\u003ealert(4)\u003c/script\u003e\"\u003e'); // becomes \u003cmath\u003e\u003cmi\u003e\u003c/mi\u003e\u003c/math\u003e\nDOMPurify.sanitize('\u003cTABLE\u003e\u003ctr\u003e\u003ctd\u003eHELLO\u003c/tr\u003e\u003c/TABL\u003e'); // becomes \u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003eHELLO\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\nDOMPurify.sanitize('\u003cUL\u003e\u003cli\u003e\u003cA HREF=//google.com\u003eclick\u003c/UL\u003e'); // becomes \u003cul\u003e\u003cli\u003e\u003ca href=\"//google.com\"\u003eclick\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\n```\n\n## What is supported?\n\nDOMPurify currently supports HTML5, SVG and MathML. DOMPurify per default allows CSS, HTML custom data attributes. DOMPurify also supports the Shadow DOM - and sanitizes DOM templates recursively. DOMPurify also allows you to sanitize HTML for being used with the jQuery `$()` and `elm.html()` API without any known problems.\n\n## What about legacy browsers like Internet Explorer?\n\nDOMPurify does nothing at all. It simply returns exactly the string that you fed it. DOMPurify exposes a property called `isSupported`, which tells you whether it will be able to do its job, so you can come up with your own backup plan.\n\n## What about DOMPurify and Trusted Types?\n\nIn version 1.0.9, support for [Trusted Types API](https://github.com/w3c/webappsec-trusted-types) was added to DOMPurify.\nIn version 2.0.0, a config flag was added to control DOMPurify's behavior regarding this.\n\nWhen `DOMPurify.sanitize` is used in an environment where the Trusted Types API is available and `RETURN_TRUSTED_TYPE` is set to `true`, it tries to return a `TrustedHTML` value instead of a string (the behavior for `RETURN_DOM` and `RETURN_DOM_FRAGMENT` config options does not change).\n\nNote that in order to create a policy in `trustedTypes` using DOMPurify, `RETURN_TRUSTED_TYPE: false` is required, as `createHTML` expects a normal string, not `TrustedHTML`. The example below shows this.\n\n```js\nwindow.trustedTypes!.createPolicy('default', {\n  createHTML: (to_escape) =\u003e\n    DOMPurify.sanitize(to_escape, { RETURN_TRUSTED_TYPE: false }),\n});\n```\n\n## Can I configure DOMPurify?\n\nYes. The included default configuration values are pretty good already - but you can of course override them. Check out the [`/demos`](https://github.com/cure53/DOMPurify/tree/main/demos) folder to see a bunch of examples on how you can [customize DOMPurify](https://github.com/cure53/DOMPurify/tree/main/demos#what-is-this).\n\n### General settings\n```js\n// strip {{ ... }}, ${ ... } and \u003c% ... %\u003e to make output safe for template systems\n// be careful please, this mode is not recommended for production usage.\n// allowing template parsing in user-controlled HTML is not advised at all.\n// only use this mode if there is really no alternative.\nconst clean = DOMPurify.sanitize(dirty, {SAFE_FOR_TEMPLATES: true});\n\n\n// change how e.g. comments containing risky HTML characters are treated.\n// be very careful, this setting should only be set to `false` if you really only handle \n// HTML and nothing else, no SVG, MathML or the like. \n// Otherwise, changing from `true` to `false` will lead to XSS in this or some other way.\nconst clean = DOMPurify.sanitize(dirty, {SAFE_FOR_XML: false});\n```\n\n### Control our allow-lists and block-lists\n```js\n// allow only \u003cb\u003e elements, very strict\nconst clean = DOMPurify.sanitize(dirty, {ALLOWED_TAGS: ['b']});\n\n// allow only \u003cb\u003e and \u003cq\u003e with style attributes\nconst clean = DOMPurify.sanitize(dirty, {ALLOWED_TAGS: ['b', 'q'], ALLOWED_ATTR: ['style']});\n\n// allow all safe HTML elements but neither SVG nor MathML\n// note that the USE_PROFILES setting will override the ALLOWED_TAGS setting\n// so don't use them together\nconst clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {html: true}});\n\n// allow all safe SVG elements and SVG Filters, no HTML or MathML\nconst clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {svg: true, svgFilters: true}});\n\n// allow all safe MathML elements and SVG, but no SVG Filters\nconst clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {mathMl: true, svg: true}});\n\n// change the default namespace from HTML to something different\nconst clean = DOMPurify.sanitize(dirty, {NAMESPACE: 'http://www.w3.org/2000/svg'});\n\n// leave all safe HTML as it is and add \u003cstyle\u003e elements to block-list\nconst clean = DOMPurify.sanitize(dirty, {FORBID_TAGS: ['style']});\n\n// leave all safe HTML as it is and add style attributes to block-list\nconst clean = DOMPurify.sanitize(dirty, {FORBID_ATTR: ['style']});\n\n// extend the existing array of allowed tags and add \u003cmy-tag\u003e to allow-list\nconst clean = DOMPurify.sanitize(dirty, {ADD_TAGS: ['my-tag']});\n\n// extend the existing array of allowed attributes and add my-attr to allow-list\nconst clean = DOMPurify.sanitize(dirty, {ADD_ATTR: ['my-attr']});\n\n// prohibit ARIA attributes, leave other safe HTML as is (default is true)\nconst clean = DOMPurify.sanitize(dirty, {ALLOW_ARIA_ATTR: false});\n\n// prohibit HTML5 data attributes, leave other safe HTML as is (default is true)\nconst clean = DOMPurify.sanitize(dirty, {ALLOW_DATA_ATTR: false});\n```\n\n### Control behavior relating to Custom Elements\n```js\n// DOMPurify allows to define rules for Custom Elements. When using the CUSTOM_ELEMENT_HANDLING\n// literal, it is possible to define exactly what elements you wish to allow (by default, none are allowed).\n//\n// The same goes for their attributes. By default, the built-in or configured allow.list is used.\n//\n// You can use a RegExp literal to specify what is allowed or a predicate, examples for both can be seen below.\n// The default values are very restrictive to prevent accidental XSS bypasses. Handle with great care!\n\nconst clean = DOMPurify.sanitize(\n    '\u003cfoo-bar baz=\"foobar\" forbidden=\"true\"\u003e\u003c/foo-bar\u003e\u003cdiv is=\"foo-baz\"\u003e\u003c/div\u003e',\n    {\n        CUSTOM_ELEMENT_HANDLING: {\n            tagNameCheck: null, // no custom elements are allowed\n            attributeNameCheck: null, // default / standard attribute allow-list is used\n            allowCustomizedBuiltInElements: false, // no customized built-ins allowed\n        },\n    }\n); // \u003cdiv is=\"\"\u003e\u003c/div\u003e\n\nconst clean = DOMPurify.sanitize(\n    '\u003cfoo-bar baz=\"foobar\" forbidden=\"true\"\u003e\u003c/foo-bar\u003e\u003cdiv is=\"foo-baz\"\u003e\u003c/div\u003e',\n    {\n        CUSTOM_ELEMENT_HANDLING: {\n            tagNameCheck: /^foo-/, // allow all tags starting with \"foo-\"\n            attributeNameCheck: /baz/, // allow all attributes containing \"baz\"\n            allowCustomizedBuiltInElements: true, // customized built-ins are allowed\n        },\n    }\n); // \u003cfoo-bar baz=\"foobar\"\u003e\u003c/foo-bar\u003e\u003cdiv is=\"foo-baz\"\u003e\u003c/div\u003e\n\nconst clean = DOMPurify.sanitize(\n    '\u003cfoo-bar baz=\"foobar\" forbidden=\"true\"\u003e\u003c/foo-bar\u003e\u003cdiv is=\"foo-baz\"\u003e\u003c/div\u003e',\n    {\n        CUSTOM_ELEMENT_HANDLING: {\n            tagNameCheck: (tagName) =\u003e tagName.match(/^foo-/), // allow all tags starting with \"foo-\"\n            attributeNameCheck: (attr) =\u003e attr.match(/baz/), // allow all containing \"baz\"\n            allowCustomizedBuiltInElements: true, // allow customized built-ins\n        },\n    }\n); // \u003cfoo-bar baz=\"foobar\"\u003e\u003c/foo-bar\u003e\u003cdiv is=\"foo-baz\"\u003e\u003c/div\u003e\n```\n### Control behavior relating to URI values\n```js\n// extend the existing array of elements that can use Data URIs\nconst clean = DOMPurify.sanitize(dirty, {ADD_DATA_URI_TAGS: ['a', 'area']});\n\n// extend the existing array of elements that are safe for URI-like values (be careful, XSS risk)\nconst clean = DOMPurify.sanitize(dirty, {ADD_URI_SAFE_ATTR: ['my-attr']});\n\n```\n### Control permitted attribute values\n```js\n// allow external protocol handlers in URL attributes (default is false, be careful, XSS risk)\n// by default only http, https, ftp, ftps, tel, mailto, callto, sms, cid and xmpp are allowed.\nconst clean = DOMPurify.sanitize(dirty, {ALLOW_UNKNOWN_PROTOCOLS: true});\n\n// allow specific protocols handlers in URL attributes via regex (default is false, be careful, XSS risk)\n// by default only http, https, ftp, ftps, tel, mailto, callto, sms, cid and xmpp are allowed.\n// Default RegExp: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i;\nconst clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|xxx):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i});\n\n```\n### Influence the return-type\n```js\n// return a DOM HTMLBodyElement instead of an HTML string (default is false)\nconst clean = DOMPurify.sanitize(dirty, {RETURN_DOM: true});\n\n// return a DOM DocumentFragment instead of an HTML string (default is false)\nconst clean = DOMPurify.sanitize(dirty, {RETURN_DOM_FRAGMENT: true});\n\n// use the RETURN_TRUSTED_TYPE flag to turn on Trusted Types support if available\nconst clean = DOMPurify.sanitize(dirty, {RETURN_TRUSTED_TYPE: true}); // will return a TrustedHTML object instead of a string if possible\n\n// use a provided Trusted Types policy\nconst clean = DOMPurify.sanitize(dirty, {\n    // supplied policy must define createHTML and createScriptURL\n    TRUSTED_TYPES_POLICY: trustedTypes.createPolicy({\n        createHTML(s) { return s},\n        createScriptURL(s) { return s},\n    }\n});\n```\n### Influence how we sanitize\n```js\n// return entire document including \u003chtml\u003e tags (default is false)\nconst clean = DOMPurify.sanitize(dirty, {WHOLE_DOCUMENT: true});\n\n// disable DOM Clobbering protection on output (default is true, handle with care, minor XSS risks here)\nconst clean = DOMPurify.sanitize(dirty, {SANITIZE_DOM: false});\n\n// enforce strict DOM Clobbering protection via namespace isolation (default is false)\n// when enabled, isolates the namespace of named properties (i.e., `id` and `name` attributes)\n// from JS variables by prefixing them with the string `user-content-`\nconst clean = DOMPurify.sanitize(dirty, {SANITIZE_NAMED_PROPS: true});\n\n// keep an element's content when the element is removed (default is true)\nconst clean = DOMPurify.sanitize(dirty, {KEEP_CONTENT: false});\n\n// glue elements like style, script or others to document.body and prevent unintuitive browser behavior in several edge-cases (default is false)\nconst clean = DOMPurify.sanitize(dirty, {FORCE_BODY: true});\n\n// remove all \u003ca\u003e elements under \u003cp\u003e elements that are removed\nconst clean = DOMPurify.sanitize(dirty, {FORBID_CONTENTS: ['a'], FORBID_TAGS: ['p']});\n\n// change the parser type so sanitized data is treated as XML and not as HTML, which is the default\nconst clean = DOMPurify.sanitize(dirty, {PARSER_MEDIA_TYPE: 'application/xhtml+xml'});\n```\n### Influence where we sanitize\n```js\n// use the IN_PLACE mode to sanitize a node \"in place\", which is much faster depending on how you use DOMPurify\nconst dirty = document.createElement('a');\ndirty.setAttribute('href', 'javascript:alert(1)');\n\nconst clean = DOMPurify.sanitize(dirty, {IN_PLACE: true}); // see https://github.com/cure53/DOMPurify/issues/288 for more info\n```\n\nThere is even [more examples here](https://github.com/cure53/DOMPurify/tree/main/demos#what-is-this), showing how you can run, customize and configure DOMPurify to fit your needs.\n\n## Persistent Configuration\n\nInstead of repeatedly passing the same configuration to `DOMPurify.sanitize`, you can use the `DOMPurify.setConfig` method. Your configuration will persist until your next call to `DOMPurify.setConfig`, or until you invoke `DOMPurify.clearConfig` to reset it. Remember that there is only one active configuration, which means once it is set, all extra configuration parameters passed to `DOMPurify.sanitize` are ignored.\n\n## Hooks\n\nDOMPurify allows you to augment its functionality by attaching one or more functions with the `DOMPurify.addHook` method to one of the following hooks:\n\n- `beforeSanitizeElements`\n- `uponSanitizeElement` (No 's' - called for every element)\n- `afterSanitizeElements`\n- `beforeSanitizeAttributes`\n- `uponSanitizeAttribute`\n- `afterSanitizeAttributes`\n- `beforeSanitizeShadowDOM`\n- `uponSanitizeShadowNode`\n- `afterSanitizeShadowDOM`\n\nIt passes the currently processed DOM node, when needed a literal with verified node and attribute data and the DOMPurify configuration to the callback. Check out the [MentalJS hook demo](https://github.com/cure53/DOMPurify/blob/main/demos/hooks-mentaljs-demo.html) to see how the API can be used nicely.\n\n_Example_:\n\n```js\nDOMPurify.addHook(\n  'uponSanitizeAttribute',\n  function (currentNode, hookEvent, config) {\n    // Do something with the current node\n    // You can also mutate hookEvent for current node (i.e. set hookEvent.forceKeepAttr = true)\n    // For other than 'uponSanitizeAttribute' hook types hookEvent equals to null\n  }\n);\n```\n\n## Removed Configuration\n\n| Option          | Since | Note                     |\n|-----------------|-------|--------------------------|\n| SAFE_FOR_JQUERY | 2.1.0 | No replacement required. |\n\n## Continuous Integration\n\nWe are currently using Github Actions in combination with BrowserStack. This gives us the possibility to confirm for each and every commit that all is going according to plan in all supported browsers. Check out the build logs here: https://github.com/cure53/DOMPurify/actions\n\nYou can further run local tests by executing `npm test`. The tests work fine with Node.js v0.6.2 and jsdom@8.5.0.\n\nAll relevant commits will be signed with the key `0x24BB6BF4` for additional security (since 8th of April 2016).\n\n### Development and contributing\n\n#### Installation (`npm i`)\n\nWe support `npm` officially. GitHub Actions workflow is configured to install dependencies using `npm`. When using deprecated version of `npm` we can not fully ensure the versions of installed dependencies which might lead to unanticipated problems.\n\n#### Scripts\n\nWe rely on npm run-scripts for integrating with our tooling infrastructure. We use ESLint as a pre-commit hook to ensure code consistency. Moreover, to ease formatting we use [prettier](https://github.com/prettier/prettier) while building the `/dist` assets happens through `rollup`.\n\nThese are our npm scripts:\n\n- `npm run dev` to start building while watching sources for changes\n- `npm run test` to run our test suite via jsdom and karma\n  - `test:jsdom` to only run tests through jsdom\n  - `test:karma` to only run tests through karma\n- `npm run lint` to lint the sources using ESLint (via xo)\n- `npm run format` to format our sources using prettier to ease to pass ESLint\n- `npm run build` to build our distribution assets minified and unminified as a UMD module\n  - `npm run build:umd` to only build an unminified UMD module\n  - `npm run build:umd:min` to only build a minified UMD module\n\nNote: all run scripts triggered via `npm run \u003cscript\u003e`.\n\nThere are more npm scripts but they are mainly to integrate with CI or are meant to be \"private\" for instance to amend build distribution files with every commit.\n\n## Security Mailing List\n\nWe maintain a mailing list that notifies whenever a security-critical release of DOMPurify was published. This means, if someone found a bypass and we fixed it with a release (which always happens when a bypass was found) a mail will go out to that list. This usually happens within minutes or few hours after learning about a bypass. The list can be subscribed to here:\n\n[https://lists.ruhr-uni-bochum.de/mailman/listinfo/dompurify-security](https://lists.ruhr-uni-bochum.de/mailman/listinfo/dompurify-security)\n\nFeature releases will not be announced to this list.\n\n## Who contributed?\n\nMany people helped and help DOMPurify become what it is and need to be acknowledged here!\n\n[hash_kitten ❤️](https://twitter.com/hash_kitten), [kevin_mizu ❤️](https://twitter.com/kevin_mizu), [icesfont ❤️](https://github.com/icesfont), [reduckted ❤️](https://github.com/reduckted), [dcramer 💸](https://github.com/dcramer), [JGraph 💸](https://github.com/jgraph), [baekilda 💸](https://github.com/baekilda), [Healthchecks 💸](https://github.com/healthchecks), [Sentry 💸](https://github.com/getsentry), [jarrodldavis 💸](https://github.com/jarrodldavis), [CynegeticIO](https://github.com/CynegeticIO), [ssi02014 ❤️](https://github.com/ssi02014), [GrantGryczan](https://github.com/GrantGryczan), [Lowdefy](https://twitter.com/lowdefy), [granlem](https://twitter.com/MaximeVeit), [oreoshake](https://github.com/oreoshake), [tdeekens ❤️](https://github.com/tdeekens), [peernohell ❤️](https://github.com/peernohell), [is2ei](https://github.com/is2ei), [SoheilKhodayari](https://github.com/SoheilKhodayari), [franktopel](https://github.com/franktopel), [NateScarlet](https://github.com/NateScarlet), [neilj](https://github.com/neilj), [fhemberger](https://github.com/fhemberger), [Joris-van-der-Wel](https://github.com/Joris-van-der-Wel), [ydaniv](https://github.com/ydaniv), [terjanq](https://twitter.com/terjanq), [filedescriptor](https://github.com/filedescriptor), [ConradIrwin](https://github.com/ConradIrwin), [gibson042](https://github.com/gibson042), [choumx](https://github.com/choumx), [0xSobky](https://github.com/0xSobky), [styfle](https://github.com/styfle), [koto](https://github.com/koto), [tlau88](https://github.com/tlau88), [strugee](https://github.com/strugee), [oparoz](https://github.com/oparoz), [mathiasbynens](https://github.com/mathiasbynens), [edg2s](https://github.com/edg2s), [dnkolegov](https://github.com/dnkolegov), [dhardtke](https://github.com/dhardtke), [wirehead](https://github.com/wirehead), [thorn0](https://github.com/thorn0), [styu](https://github.com/styu), [mozfreddyb](https://github.com/mozfreddyb), [mikesamuel](https://github.com/mikesamuel), [jorangreef](https://github.com/jorangreef), [jimmyhchan](https://github.com/jimmyhchan), [jameydeorio](https://github.com/jameydeorio), [jameskraus](https://github.com/jameskraus), [hyderali](https://github.com/hyderali), [hansottowirtz](https://github.com/hansottowirtz), [hackvertor](https://github.com/hackvertor), [freddyb](https://github.com/freddyb), [flavorjones](https://github.com/flavorjones), [djfarrelly](https://github.com/djfarrelly), [devd](https://github.com/devd), [camerondunford](https://github.com/camerondunford), [buu700](https://github.com/buu700), [buildog](https://github.com/buildog), [alabiaga](https://github.com/alabiaga), [Vector919](https://github.com/Vector919), [Robbert](https://github.com/Robbert), [GreLI](https://github.com/GreLI), [FuzzySockets](https://github.com/FuzzySockets), [ArtemBernatskyy](https://github.com/ArtemBernatskyy), [@garethheyes](https://twitter.com/garethheyes), [@shafigullin](https://twitter.com/shafigullin), [@mmrupp](https://twitter.com/mmrupp), [@irsdl](https://twitter.com/irsdl),[ShikariSenpai](https://github.com/ShikariSenpai), [ansjdnakjdnajkd](https://github.com/ansjdnakjdnajkd), [@asutherland](https://twitter.com/asutherland), [@mathias](https://twitter.com/mathias), [@cgvwzq](https://twitter.com/cgvwzq), [@robbertatwork](https://twitter.com/robbertatwork), [@giutro](https://twitter.com/giutro), [@CmdEngineer\\_](https://twitter.com/CmdEngineer_), [@avr4mit](https://twitter.com/avr4mit), [davecardwell](https://github.com/davecardwell) and especially [@securitymb ❤️](https://twitter.com/securitymb) \u0026 [@masatokinugawa ❤️](https://twitter.com/masatokinugawa)\n\n## Testing powered by\n\n\u003ca target=\"_blank\" href=\"https://www.browserstack.com/\"\u003e\u003cimg width=\"200\" src=\"https://github.com/cure53/DOMPurify/assets/6709482/f70be7eb-8fc4-41ea-9653-9d359235328f\"\u003e\u003c/a\u003e\u003cbr\u003e\n\nAnd last but not least, thanks to [BrowserStack Open-Source Program](https://www.browserstack.com/open-source) for supporting this project with their services for free and delivering excellent, dedicated and very professional support on top of that.\n","funding_links":["https://github.com/sponsors/cure53"],"categories":["Uncategorized","JavaScript","Tools","Input Validation \u0026 Output Encoding","Security","Weapons","JavaScript (485)","前端开发框架及项目","html","Security [🔝](#readme)","DOM Manipulation","security","Code","安全性","前端常用","41. 实用工具/其他插件"],"sub_categories":["Uncategorized","Preventing","Runner","Tools","其他_文本生成、文本对话","Sanitizers","运行器","24.3 Web Sockets","运行器e2e测试"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcure53%2FDOMPurify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcure53%2FDOMPurify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcure53%2FDOMPurify/lists"}