[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3261":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":37,"readmeContent":38,"aiSummary":39,"trendingCount":15,"starSnapshotCount":15,"syncStatus":40,"lastSyncTime":41,"discoverSource":42},3261,"DOMPurify","cure53\u002FDOMPurify","cure53","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:","https:\u002F\u002Fcure53.de\u002Fpurify",null,"JavaScript",17094,851,147,0,1,20,118,11,43.79,"Other",false,"main",true,[26,27,28,29,30,31,32,33,34,35,36],"cross-site-scripting","dom","dompurify","html","javascript","mathml","prevent-xss-attacks","sanitizer","security","svg","xss","2026-06-12 02:00:48","# DOMPurify\n\n[![npm](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002Fdompurify.svg)](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fdompurify) [![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MPL--2.0%20OR%20Apache--2.0-blue.svg)](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fblob\u002Fmain\u002FLICENSE) ![Tests](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fworkflows\u002FBuild%20&%20Test\u002Fbadge.svg) [![Downloads](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fdm\u002Fdompurify.svg)](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fdompurify) [![dependents](https:\u002F\u002Fbadgen.net\u002Fgithub\u002Fdependents-repo\u002Fcure53\u002Fdompurify?color=green&label=dependents)](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fnetwork\u002Fdependents)\n\n![npm package minimized gzipped size (select exports)](https:\u002F\u002Fimg.shields.io\u002Fbundlejs\u002Fsize\u002Fdompurify?color=%233C1&label=gzip) [![Cloudback](https:\u002F\u002Fapp.cloudback.it\u002Fbadge\u002Fcure53\u002FDOMPurify)](https:\u002F\u002Fcloudback.it) [![OpenSSF Best Practices](https:\u002F\u002Fwww.bestpractices.dev\u002Fprojects\u002F12162\u002Fbadge)](https:\u002F\u002Fwww.bestpractices.dev\u002Fprojects\u002F12162) [![OpenSSF Scorecard](https:\u002F\u002Fapi.scorecard.dev\u002Fprojects\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fbadge)](https:\u002F\u002Fscorecard.dev\u002Fviewer\u002F?uri=github.com\u002Fcure53\u002FDOMPurify) [![Socket Badge](https:\u002F\u002Fbadge.socket.dev\u002Fnpm\u002Fpackage\u002Fdompurify\u002Flatest)](https:\u002F\u002Fbadge.socket.dev\u002Fnpm\u002Fpackage\u002Fdompurify\u002Flatest)\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:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fcommit\u002Fa630922616927373485e0e787ab19e73e3691b2b) and, meanwhile, has reached version **v3.4.2**.\n\nDOMPurify runs as 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.9](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Freleases\u002Ftag\u002F2.5.9) is the latest version supporting MSIE. For important security updates compatible with MSIE, please use the [2.x branch](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Ftree\u002F2.x).**\n\nOur automated tests cover 9 browser\u002FOS combinations (Chromium, Firefox, and WebKit across Ubuntu, macOS, and Windows) on every push, plus Node.js v20, v22, v24, and v25 running DOMPurify on [jsdom](https:\u002F\u002Fgithub.com\u002Fjsdom\u002Fjsdom). 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 & Threat Model](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fwiki\u002FSecurity-Goals-&-Threat-Model). Please, read it. Like, really.\n\nThe DOMPurify project inspired the creation of the [HTML Sanitizer API](https:\u002F\u002Fwicg.github.io\u002Fsanitizer-api\u002F#sanitizer), which is already shipping in [many browsers](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FHTML_Sanitizer_API#browser_compatibility).\n\n## What does it do?\n\nDOMPurify sanitizes HTML and prevents XSS attacks. You can feed DOMPurify with e.g. a 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 version (source-map available)\n\n```html\n\u003Cscript type=\"text\u002Fjavascript\" src=\"dist\u002Fpurify.js\">\u003C\u002Fscript>\n```\n\n### Using the minified and tested production version (source-map available)\n\n```html\n\u003Cscript type=\"text\u002Fjavascript\" src=\"dist\u002Fpurify.min.js\">\u003C\u002Fscript>\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>hello there\u003C\u002Fb>');\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:\u002F\u002Fnodejs.org\u002Fen\u002Fabout\u002Fprevious-releases).\n\nRunning DOMPurify on the server requires a DOM to be present, which is probably no surprise. Usually, [jsdom](https:\u002F\u002Fgithub.com\u002Fjsdom\u002Fjsdom) 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:\u002F\u002Fgithub.com\u002Fcapricorn86\u002Fhappy-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>hello there\u003C\u002Fb>');\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>hello there\u003C\u002Fb>');\n```\n\nIf you have problems making it work in your specific setup, consider looking at the amazing [isomorphic-dompurify](https:\u002F\u002Fgithub.com\u002Fkkomelin\u002Fisomorphic-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>hello\u003C\u002Fs>');\n```\n\n## Is there a demo?\n\nOf course there is a demo! [Play with DOMPurify](https:\u002F\u002Fcure53.de\u002Fpurify)\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:\u002F\u002Fkeyserver.ubuntu.com\u002Fpks\u002Flookup?op=vindex&search=0xC26C858090F70ADA)\n\nAlso, you probably qualify for a bug bounty! The fine folks over at [Fastmail](https:\u002F\u002Fwww.fastmail.com\u002F) 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:\u002F\u002Fwww.fastmail.com\u002Fabout\u002Fbugbounty\u002F).\n\n## Some purification samples please?\n\nHow does purified markup look like? Well, [the demo](https:\u002F\u002Fcure53.de\u002Fpurify) 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)\u002F\u002F>'); \u002F\u002F becomes \u003Cimg src=\"x\">\nDOMPurify.sanitize('\u003Csvg>\u003Cg\u002Fonload=alert(2)\u002F\u002F\u003Cp>'); \u002F\u002F becomes \u003Csvg>\u003Cg>\u003C\u002Fg>\u003C\u002Fsvg>\nDOMPurify.sanitize('\u003Cp>abc\u003Ciframe\u002F\u002Fsrc=jAva&Tab;script:alert(3)>def\u003C\u002Fp>'); \u002F\u002F becomes \u003Cp>abc\u003C\u002Fp>\nDOMPurify.sanitize('\u003Cmath>\u003Cmi\u002F\u002Fxlink:href=\"data:x,\u003Cscript>alert(4)\u003C\u002Fscript>\">'); \u002F\u002F becomes \u003Cmath>\u003Cmi>\u003C\u002Fmi>\u003C\u002Fmath>\nDOMPurify.sanitize('\u003CTABLE>\u003Ctr>\u003Ctd>HELLO\u003C\u002Ftr>\u003C\u002FTABL>'); \u002F\u002F becomes \u003Ctable>\u003Ctbody>\u003Ctr>\u003Ctd>HELLO\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\nDOMPurify.sanitize('\u003CUL>\u003Cli>\u003CA HREF=\u002F\u002Fgoogle.com>click\u003C\u002FUL>'); \u002F\u002F becomes \u003Cul>\u003Cli>\u003Ca href=\"\u002F\u002Fgoogle.com\">click\u003C\u002Fa>\u003C\u002Fli>\u003C\u002Ful>\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:\u002F\u002Fgithub.com\u002Fw3c\u002Fwebappsec-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) =>\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 [`\u002Fdemos`](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Ftree\u002Fmain\u002Fdemos) folder to see a bunch of examples on how you can [customize DOMPurify](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Ftree\u002Fmain\u002Fdemos#what-is-this).\n\n### General settings\n\n```js\n\u002F\u002F strip {{ ... }}, ${ ... } and \u003C% ... %> to make output safe for template systems\n\u002F\u002F be careful please, this mode is not recommended for production usage.\n\u002F\u002F allowing template parsing in user-controlled HTML is not advised at all.\n\u002F\u002F only use this mode if there is really no alternative.\nconst clean = DOMPurify.sanitize(dirty, { SAFE_FOR_TEMPLATES: true });\n\n\u002F\u002F change how e.g. comments containing risky HTML characters are treated.\n\u002F\u002F be very careful, this setting should only be set to `false` if you really only handle\n\u002F\u002F HTML and nothing else, no SVG, MathML or the like.\n\u002F\u002F 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\n```js\n\u002F\u002F allow only \u003Cb> elements, very strict\nconst clean = DOMPurify.sanitize(dirty, { ALLOWED_TAGS: ['b'] });\n\n\u002F\u002F allow only \u003Cb> and \u003Cq> with style attributes\nconst clean = DOMPurify.sanitize(dirty, {\n  ALLOWED_TAGS: ['b', 'q'],\n  ALLOWED_ATTR: ['style'],\n});\n\n\u002F\u002F allow all safe HTML elements but neither SVG nor MathML\n\u002F\u002F note that the USE_PROFILES setting will override the ALLOWED_TAGS setting\n\u002F\u002F so don't use them together\nconst clean = DOMPurify.sanitize(dirty, { USE_PROFILES: { html: true } });\n\n\u002F\u002F allow all safe SVG elements and SVG Filters, no HTML or MathML\nconst clean = DOMPurify.sanitize(dirty, {\n  USE_PROFILES: { svg: true, svgFilters: true },\n});\n\n\u002F\u002F allow all safe MathML elements and SVG, but no SVG Filters\nconst clean = DOMPurify.sanitize(dirty, {\n  USE_PROFILES: { mathMl: true, svg: true },\n});\n\n\u002F\u002F change the default namespace from HTML to something different\nconst clean = DOMPurify.sanitize(dirty, {\n  NAMESPACE: 'http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg',\n});\n\n\u002F\u002F leave all safe HTML as it is and add \u003Cstyle> elements to block-list\nconst clean = DOMPurify.sanitize(dirty, { FORBID_TAGS: ['style'] });\n\n\u002F\u002F leave all safe HTML as it is and add style attributes to block-list\nconst clean = DOMPurify.sanitize(dirty, { FORBID_ATTR: ['style'] });\n\n\u002F\u002F extend the existing array of allowed tags and add \u003Cmy-tag> to allow-list\nconst clean = DOMPurify.sanitize(dirty, { ADD_TAGS: ['my-tag'] });\n\n\u002F\u002F 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\u002F\u002F use functions to control which additional tags and attributes are allowed\nconst allowlist = {\n  one: ['attribute-one'],\n  two: ['attribute-two'],\n};\nconst clean = DOMPurify.sanitize(\n  '\u003Cone attribute-one=\"1\" attribute-two=\"2\">\u003C\u002Fone>\u003Ctwo attribute-one=\"1\" attribute-two=\"2\">\u003C\u002Ftwo>',\n  {\n    ADD_TAGS: (tagName) => {\n      return Object.keys(allowlist).includes(tagName);\n    },\n    ADD_ATTR: (attributeName, tagName) => {\n      return allowlist[tagName]?.includes(attributeName) || false;\n    },\n  }\n); \u002F\u002F \u003Cone attribute-one=\"1\">\u003C\u002Fone>\u003Ctwo attribute-two=\"2\">\u003C\u002Ftwo>\n\n\u002F\u002F prohibit ARIA attributes, leave other safe HTML as is (default is true)\nconst clean = DOMPurify.sanitize(dirty, { ALLOW_ARIA_ATTR: false });\n\n\u002F\u002F 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\n```js\n\u002F\u002F DOMPurify allows to define rules for Custom Elements. When using the CUSTOM_ELEMENT_HANDLING\n\u002F\u002F literal, it is possible to define exactly what elements you wish to allow (by default, none are allowed).\n\u002F\u002F\n\u002F\u002F The same goes for their attributes. By default, the built-in or configured allow.list is used.\n\u002F\u002F\n\u002F\u002F You can use a RegExp literal to specify what is allowed or a predicate, examples for both can be seen below.\n\u002F\u002F When using a predicate function for attributeNameCheck, it can optionally receive the tagName as a second parameter\n\u002F\u002F for more granular control over which attributes are allowed for specific elements.\n\u002F\u002F 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\">\u003C\u002Ffoo-bar>\u003Cdiv is=\"foo-baz\">\u003C\u002Fdiv>',\n  {\n    CUSTOM_ELEMENT_HANDLING: {\n      tagNameCheck: null, \u002F\u002F no custom elements are allowed\n      attributeNameCheck: null, \u002F\u002F default \u002F standard attribute allow-list is used\n      allowCustomizedBuiltInElements: false, \u002F\u002F no customized built-ins allowed\n    },\n  }\n); \u002F\u002F \u003Cdiv is=\"\">\u003C\u002Fdiv>\n\nconst clean = DOMPurify.sanitize(\n  '\u003Cfoo-bar baz=\"foobar\" forbidden=\"true\">\u003C\u002Ffoo-bar>\u003Cdiv is=\"foo-baz\">\u003C\u002Fdiv>',\n  {\n    CUSTOM_ELEMENT_HANDLING: {\n      tagNameCheck: \u002F^foo-\u002F, \u002F\u002F allow all tags starting with \"foo-\"\n      attributeNameCheck: \u002Fbaz\u002F, \u002F\u002F allow all attributes containing \"baz\"\n      allowCustomizedBuiltInElements: true, \u002F\u002F customized built-ins are allowed\n    },\n  }\n); \u002F\u002F \u003Cfoo-bar baz=\"foobar\">\u003C\u002Ffoo-bar>\u003Cdiv is=\"foo-baz\">\u003C\u002Fdiv>\n\nconst clean = DOMPurify.sanitize(\n  '\u003Cfoo-bar baz=\"foobar\" forbidden=\"true\">\u003C\u002Ffoo-bar>\u003Cdiv is=\"foo-baz\">\u003C\u002Fdiv>',\n  {\n    CUSTOM_ELEMENT_HANDLING: {\n      tagNameCheck: (tagName) => tagName.match(\u002F^foo-\u002F), \u002F\u002F allow all tags starting with \"foo-\"\n      attributeNameCheck: (attr) => attr.match(\u002Fbaz\u002F), \u002F\u002F allow all containing \"baz\"\n      allowCustomizedBuiltInElements: true, \u002F\u002F allow customized built-ins\n    },\n  }\n); \u002F\u002F \u003Cfoo-bar baz=\"foobar\">\u003C\u002Ffoo-bar>\u003Cdiv is=\"foo-baz\">\u003C\u002Fdiv>\n\n\u002F\u002F Example with attributeNameCheck receiving tagName as a second parameter\nconst clean = DOMPurify.sanitize(\n  '\u003Celement-one attribute-one=\"1\" attribute-two=\"2\">\u003C\u002Felement-one>\u003Celement-two attribute-one=\"1\" attribute-two=\"2\">\u003C\u002Felement-two>',\n  {\n    CUSTOM_ELEMENT_HANDLING: {\n      tagNameCheck: (tagName) => tagName.match(\u002F^element-(one|two)$\u002F),\n      attributeNameCheck: (attr, tagName) => {\n        if (tagName === 'element-one') {\n          return ['attribute-one'].includes(attr);\n        } else if (tagName === 'element-two') {\n          return ['attribute-two'].includes(attr);\n        } else {\n          return false;\n        }\n      },\n      allowCustomizedBuiltInElements: false,\n    },\n  }\n); \u002F\u002F \u003Celement-one attribute-one=\"1\">\u003C\u002Felement-one>\u003Celement-two attribute-two=\"2\">\u003C\u002Felement-two>\n```\n\n### Control behavior relating to URI values\n\n```js\n\u002F\u002F extend the existing array of elements that can use Data URIs\nconst clean = DOMPurify.sanitize(dirty, { ADD_DATA_URI_TAGS: ['a', 'area'] });\n\n\u002F\u002F 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\n```js\n\u002F\u002F allow external protocol handlers in URL attributes (default is false, be careful, XSS risk)\n\u002F\u002F by default only http, https, ftp, ftps, tel, mailto, callto, sms, cid, xmpp and matrix are allowed.\nconst clean = DOMPurify.sanitize(dirty, { ALLOW_UNKNOWN_PROTOCOLS: true });\n\n\u002F\u002F allow specific protocol handlers in URL attributes via regex (default is false, be careful, XSS risk)\n\u002F\u002F by default only (protocol-)relative URLs, http, https, ftp, ftps, tel, mailto, callto, sms, cid, xmpp and matrix are allowed.\n\u002F\u002F Default RegExp: \u002F^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))\u002Fi;\nconst clean = DOMPurify.sanitize(dirty, {\n  ALLOWED_URI_REGEXP:\n    \u002F^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))\u002Fi,\n});\n```\n\n### Influence the return-type\n\n```js\n\u002F\u002F return a DOM HTMLBodyElement instead of an HTML string (default is false)\nconst clean = DOMPurify.sanitize(dirty, { RETURN_DOM: true });\n\n\u002F\u002F return a DOM DocumentFragment instead of an HTML string (default is false)\nconst clean = DOMPurify.sanitize(dirty, { RETURN_DOM_FRAGMENT: true });\n\n\u002F\u002F use the RETURN_TRUSTED_TYPE flag to turn on Trusted Types support if available\nconst clean = DOMPurify.sanitize(dirty, { RETURN_TRUSTED_TYPE: true }); \u002F\u002F will return a TrustedHTML object instead of a string if possible\n\n\u002F\u002F use a provided Trusted Types policy\nconst clean = DOMPurify.sanitize(dirty, {\n  \u002F\u002F supplied policy must define createHTML and createScriptURL\n  TRUSTED_TYPES_POLICY: trustedTypes.createPolicy('dompurify', {\n    createHTML(s) {\n      return s;\n    },\n    createScriptURL(s) {\n      return s;\n    },\n  }),\n});\n```\n\n### Influence how we sanitize\n\n```js\n\u002F\u002F return entire document including \u003Chtml> tags (default is false)\nconst clean = DOMPurify.sanitize(dirty, { WHOLE_DOCUMENT: true });\n\n\u002F\u002F 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\u002F\u002F enforce strict DOM Clobbering protection via namespace isolation (default is false)\n\u002F\u002F when enabled, isolates the namespace of named properties (i.e., `id` and `name` attributes)\n\u002F\u002F from JS variables by prefixing them with the string `user-content-`\nconst clean = DOMPurify.sanitize(dirty, { SANITIZE_NAMED_PROPS: true });\n\n\u002F\u002F keep an element's content when the element is removed (default is true)\nconst clean = DOMPurify.sanitize(dirty, { KEEP_CONTENT: false });\n\n\u002F\u002F 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\u002F\u002F remove all \u003Ca> elements under \u003Cp> elements that are removed\nconst clean = DOMPurify.sanitize(dirty, {\n  FORBID_CONTENTS: ['a'],\n  FORBID_TAGS: ['p'],\n});\n\n\u002F\u002F extend the default FORBID_CONTENTS list to also remove \u003Ca> elements under \u003Cp> elements\nconst clean = DOMPurify.sanitize(dirty, {\n  ADD_FORBID_CONTENTS: ['a'],\n  FORBID_TAGS: ['p'],\n});\n\n\u002F\u002F change the parser type so sanitized data is treated as XML and not as HTML, which is the default\nconst clean = DOMPurify.sanitize(dirty, {\n  PARSER_MEDIA_TYPE: 'application\u002Fxhtml+xml',\n});\n```\n\n### Influence where we sanitize\n\n```js\n\u002F\u002F 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 }); \u002F\u002F see https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fissues\u002F288 for more info\n```\n\nThere is even [more examples here](https:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Ftree\u002Fmain\u002Fdemos#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:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Fblob\u002Fmain\u002Fdemos\u002Fhooks-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    \u002F\u002F Do something with the current node\n    \u002F\u002F You can also mutate hookEvent for current node (i.e. set hookEvent.forceKeepAttr = true)\n    \u002F\u002F 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:\u002F\u002Fgithub.com\u002Fcure53\u002FDOMPurify\u002Factions\n\nYou can further run local tests by executing `npm run test`.\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 a deprecated version of `npm`, we cannot fully ensure the versions of installed dependencies, which might lead to unanticipated problems.\n\n#### Scripts\n\nWe use ESLint via `xo` as part of our pre-commit workflow to help ensure code consistency. In addition, we use [Prettier](https:\u002F\u002Fgithub.com\u002Fprettier\u002Fprettier) for source and Markdown formatting, and `\u002Fdist` assets are built through `rollup`.\n\nThese are our npm scripts:\n\n- `npm run dev` to build the unminified UMD bundle while watching sources for changes\n- `npm run test` to lint the sources, run tests through jsdom, and run Karma tests in Chrome\n  - `npm run test:jsdom` to only run tests through jsdom\n  - `npm run test:browser` to only run tests through Playwright\n  - `npm run test:ci` to run the CI test flow for jsdom and Karma\u002FBrowserStack\n  - `npm run test:fuzz` to run a small fuzzer covering `sanitize()` and CONFIG\n- `npm run lint` to lint the sources using ESLint via xo\n- `npm run format` to format JavaScript\u002FTypeScript and Markdown sources with Prettier\n  - `npm run format:js` to only format JavaScript\u002FTypeScript sources\n  - `npm run format:md` to only format Markdown files\n- `npm run build` to build type declarations and distribution bundles, then fix and clean up generated types\n  - `npm run build:types` to only emit TypeScript declaration files\n  - `npm run build:rollup` to build all Rollup bundles\n  - `npm run build:umd` to only build an unminified UMD bundle\n  - `npm run build:umd:min` to only build a minified UMD bundle\n  - `npm run build:es` to only build the ES module bundle\n  - `npm run build:cjs` to only build the CommonJS bundle\n  - `npm run build:fix-types` to post-process generated type files\n  - `npm run build:cleanup` to clean up temporary generated type output\n- `npm run verify-typescript` to run the TypeScript verification script\n- `npm run commit-amend-build` to run the maintainer helper script for amending build output\n\nNote: all run scripts triggered via `npm run \u003Cscript>`.\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 a few hours after learning about a bypass. The list can be subscribed to here:\n\n[https:\u002F\u002Flists.ruhr-uni-bochum.de\u002Fmailman\u002Flistinfo\u002Fdompurify-security](https:\u002F\u002Flists.ruhr-uni-bochum.de\u002Fmailman\u002Flistinfo\u002Fdompurify-security)\n\nFeature releases will not be announced to this list.\n\n## Who contributed?\n\nMany people have helped DOMPurify become what it is today, and they deserve to be acknowledged!\n\n[kodareef5](https:\u002F\u002Fgithub.com\u002Fkodareef5), [DavidOliver](https:\u002F\u002Fgithub.com\u002FDavidOliver), [1Jesper1](https:\u002F\u002Fgithub.com\u002F1Jesper1), [bencalif](https:\u002F\u002Fgithub.com\u002Fbencalif), [trace37labs](https:\u002F\u002Fgithub.com\u002Ftrace37labs), [eddieran](https:\u002F\u002Fgithub.com\u002Feddieran), [christos-eth](https:\u002F\u002Fgithub.com\u002Fchristos-eth), [researchatfluidattacks](https:\u002F\u002Fgithub.com\u002Fresearchatfluidattacks), [frevadiscor](https:\u002F\u002Fgithub.com\u002Ffrevadiscor), [Rotzbua](https:\u002F\u002Fgithub.com\u002FRotzbua), [binhpv](https:\u002F\u002Fgithub.com\u002Fbinhpv), [MariusRumpf](https:\u002F\u002Fgithub.com\u002FMariusRumpf), [prasadrajandran](https:\u002F\u002Fgithub.com\u002Fprasadrajandran), [Cybozu 💛💸](https:\u002F\u002Fgithub.com\u002Fcybozu), [hata6502 💸](https:\u002F\u002Fgithub.com\u002Fhata6502), [openclaw 💸](https:\u002F\u002Fgithub.com\u002Fopenclaw), [intra-mart-dh 💸](https:\u002F\u002Fgithub.com\u002Fintra-mart-dh), [nelstrom ❤️](https:\u002F\u002Fgithub.com\u002Fnelstrom), [hash_kitten ❤️](https:\u002F\u002Ftwitter.com\u002Fhash_kitten), [kevin_mizu ❤️](https:\u002F\u002Ftwitter.com\u002Fkevin_mizu), [icesfont ❤️](https:\u002F\u002Fgithub.com\u002Ficesfont), [reduckted ❤️](https:\u002F\u002Fgithub.com\u002Freduckted), [dcramer 💸](https:\u002F\u002Fgithub.com\u002Fdcramer), [JGraph 💸](https:\u002F\u002Fgithub.com\u002Fjgraph), [baekilda 💸](https:\u002F\u002Fgithub.com\u002Fbaekilda), [Healthchecks 💸](https:\u002F\u002Fgithub.com\u002Fhealthchecks), [Sentry 💸](https:\u002F\u002Fgithub.com\u002Fgetsentry), [jarrodldavis 💸](https:\u002F\u002Fgithub.com\u002Fjarrodldavis), [CynegeticIO](https:\u002F\u002Fgithub.com\u002FCynegeticIO), [ssi02014 ❤️](https:\u002F\u002Fgithub.com\u002Fssi02014), [GrantGryczan](https:\u002F\u002Fgithub.com\u002FGrantGryczan), [Lowdefy](https:\u002F\u002Ftwitter.com\u002Flowdefy), [granlem](https:\u002F\u002Ftwitter.com\u002FMaximeVeit), [oreoshake](https:\u002F\u002Fgithub.com\u002Foreoshake), [tdeekens ❤️](https:\u002F\u002Fgithub.com\u002Ftdeekens), [peernohell ❤️](https:\u002F\u002Fgithub.com\u002Fpeernohell), [is2ei](https:\u002F\u002Fgithub.com\u002Fis2ei), [SoheilKhodayari](https:\u002F\u002Fgithub.com\u002FSoheilKhodayari), [franktopel](https:\u002F\u002Fgithub.com\u002Ffranktopel), [NateScarlet](https:\u002F\u002Fgithub.com\u002FNateScarlet), [neilj](https:\u002F\u002Fgithub.com\u002Fneilj), [fhemberger](https:\u002F\u002Fgithub.com\u002Ffhemberger), [Joris-van-der-Wel](https:\u002F\u002Fgithub.com\u002FJoris-van-der-Wel), [ydaniv](https:\u002F\u002Fgithub.com\u002Fydaniv), [terjanq](https:\u002F\u002Ftwitter.com\u002Fterjanq), [filedescriptor](https:\u002F\u002Fgithub.com\u002Ffiledescriptor), [ConradIrwin](https:\u002F\u002Fgithub.com\u002FConradIrwin), [gibson042](https:\u002F\u002Fgithub.com\u002Fgibson042), [choumx](https:\u002F\u002Fgithub.com\u002Fchoumx), [0xSobky](https:\u002F\u002Fgithub.com\u002F0xSobky), [styfle](https:\u002F\u002Fgithub.com\u002Fstyfle), [koto](https:\u002F\u002Fgithub.com\u002Fkoto), [tlau88](https:\u002F\u002Fgithub.com\u002Ftlau88), [strugee](https:\u002F\u002Fgithub.com\u002Fstrugee), [oparoz](https:\u002F\u002Fgithub.com\u002Foparoz), [mathiasbynens](https:\u002F\u002Fgithub.com\u002Fmathiasbynens), [edg2s](https:\u002F\u002Fgithub.com\u002Fedg2s), [dnkolegov](https:\u002F\u002Fgithub.com\u002Fdnkolegov), [dhardtke](https:\u002F\u002Fgithub.com\u002Fdhardtke), [wirehead](https:\u002F\u002Fgithub.com\u002Fwirehead), [thorn0](https:\u002F\u002Fgithub.com\u002Fthorn0), [styu](https:\u002F\u002Fgithub.com\u002Fstyu), [mozfreddyb](https:\u002F\u002Fgithub.com\u002Fmozfreddyb), [mikesamuel](https:\u002F\u002Fgithub.com\u002Fmikesamuel), [jorangreef](https:\u002F\u002Fgithub.com\u002Fjorangreef), [jimmyhchan](https:\u002F\u002Fgithub.com\u002Fjimmyhchan), [jameydeorio](https:\u002F\u002Fgithub.com\u002Fjameydeorio), [jameskraus](https:\u002F\u002Fgithub.com\u002Fjameskraus), [hyderali](https:\u002F\u002Fgithub.com\u002Fhyderali), [hansottowirtz](https:\u002F\u002Fgithub.com\u002Fhansottowirtz), [hackvertor](https:\u002F\u002Fgithub.com\u002Fhackvertor), [freddyb](https:\u002F\u002Fgithub.com\u002Ffreddyb), [flavorjones](https:\u002F\u002Fgithub.com\u002Fflavorjones), [djfarrelly](https:\u002F\u002Fgithub.com\u002Fdjfarrelly), [devd](https:\u002F\u002Fgithub.com\u002Fdevd), [camerondunford](https:\u002F\u002Fgithub.com\u002Fcamerondunford), [buu700](https:\u002F\u002Fgithub.com\u002Fbuu700), [buildog](https:\u002F\u002Fgithub.com\u002Fbuildog), [alabiaga](https:\u002F\u002Fgithub.com\u002Falabiaga), [Vector919](https:\u002F\u002Fgithub.com\u002FVector919), [Robbert](https:\u002F\u002Fgithub.com\u002FRobbert), [GreLI](https:\u002F\u002Fgithub.com\u002FGreLI), [FuzzySockets](https:\u002F\u002Fgithub.com\u002FFuzzySockets), [ArtemBernatskyy](https:\u002F\u002Fgithub.com\u002FArtemBernatskyy), [@garethheyes](https:\u002F\u002Ftwitter.com\u002Fgarethheyes), [@shafigullin](https:\u002F\u002Ftwitter.com\u002Fshafigullin), [@mmrupp](https:\u002F\u002Ftwitter.com\u002Fmmrupp), [@irsdl](https:\u002F\u002Ftwitter.com\u002Firsdl),[ShikariSenpai](https:\u002F\u002Fgithub.com\u002FShikariSenpai), [ansjdnakjdnajkd](https:\u002F\u002Fgithub.com\u002Fansjdnakjdnajkd), [@asutherland](https:\u002F\u002Ftwitter.com\u002Fasutherland), [@mathias](https:\u002F\u002Ftwitter.com\u002Fmathias), [@cgvwzq](https:\u002F\u002Ftwitter.com\u002Fcgvwzq), [@robbertatwork](https:\u002F\u002Ftwitter.com\u002Frobbertatwork), [@giutro](https:\u002F\u002Ftwitter.com\u002Fgiutro), [@CmdEngineer\\_](https:\u002F\u002Ftwitter.com\u002FCmdEngineer_), [@avr4mit](https:\u002F\u002Ftwitter.com\u002Favr4mit), [davecardwell](https:\u002F\u002Fgithub.com\u002Fdavecardwell) and especially [@securitymb ❤️](https:\u002F\u002Ftwitter.com\u002Fsecuritymb) & [@masatokinugawa ❤️](https:\u002F\u002Ftwitter.com\u002Fmasatokinugawa)\n","DOMPurify 是一个专注于 DOM 的、超快且高度容错的 XSS 消毒器，适用于 HTML、MathML 和 SVG。它通过默认的安全设置运行，同时提供了大量的可配置选项和钩子，以适应不同需求。该工具使用纯 JavaScript 编写，支持所有现代浏览器（包括 Safari 10+、Opera 15+、Edge、Firefox 和 Chrome），并在 Blink、Gecko 或 WebKit 引擎上表现良好，对于 IE 等旧版浏览器则不会执行任何操作。DOMPurify 特别适合需要防止跨站脚本攻击的应用场景，如用户生成内容的网站或应用，在这些环境中确保了输入数据的安全性。",2,"2026-06-11 02:53:12","top_language"]