A DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML, and SVG.
DOMPurify is a JavaScript library that sanitizes HTML, MathML, and SVG strings to prevent cross-site scripting (XSS) attacks. It takes potentially malicious user input and returns clean, safe markup by stripping out dangerous elements and attributes. The library is designed to be extremely fast, leveraging the browser's native DOM capabilities, and highly configurable to fit various security policies.
Web developers and security engineers who need to safely render user-generated HTML content in browsers or server-side applications, particularly those building forums, rich-text editors, or any application accepting untrusted markup.
Developers choose DOMPurify for its proven security track record, exceptional performance due to DOM-only processing, and extensive customization options that allow precise control over sanitization rules without compromising safety.
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:
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Built by Cure53 security experts with a documented threat model and bug bounty program, ensuring continuous vetting against XSS bypasses, as noted in the README's security goals.
Leverages the browser's built-in DOM parser for exceptional performance, described as 'super-fast' and 'uber-tolerant' in the README, making it ideal for real-time sanitization.
Offers extensive options like ALLOWED_TAGS, ADD_ATTR, and hooks, allowing precise control over sanitization rules, with demos showing customization for diverse use cases.
Handles HTML5, SVG, and MathML safely by default, covering a wide range of web content types without extra setup, as highlighted in the key features.
Requires jsdom in Node.js, and the README warns that older jsdom versions are buggy and can lead to XSS, adding complexity and potential security holes in server environments.
Options such as ALLOW_UNKNOWN_PROTOCOLS or improper CUSTOM_ELEMENT_HANDLING can introduce XSS if misused, demanding expert knowledge to avoid accidental bypasses.
In MSIE, DOMPurify returns the input unchanged, necessitating fallback sanitization logic, which complicates cross-browser support and increases development overhead.