Sanitization

Sanitization is the process of removing from an input string items that could be used in a security attack. On the web, it typically refers to the removal, from a string input containing HTML, of items that could enable an attacker to launch a Cross-site scripting (XSS) attack. This includes elements such as <script> and event handler attributes like onerror.

The HTML Sanitizer API provides built-in support for HTML sanitization on the web. Developers can also use reputable third-party libraries such as DOMPurify. Because sanitization is difficult to get right, developers should usually not implement their own sanitization logic.