HTML Sanitizer: Strip Scripts, Event Handlers and Unsafe URLs

Rebuilds untrusted HTML from an allow-list of tags and attributes and reports each removal with its line number.

Use the tool

Why this tool exists

User-supplied HTML can carry scripts, event handlers and javascript: links. This tool parses the markup, keeps only a short list of text, list, table and image tags, drops script, style, iframe, form and similar elements with their content, removes event handlers and style attributes, and allows only http, https, mailto and tel links.

It is hand-written and has had no third-party security review, so treat it as a preview of what an allow-list does. In production use a maintained library and a Content-Security-Policy. Nothing you paste is sent anywhere.

How to use it

  1. Paste the untrusted HTML.
  2. Choose whether to keep ids or allow data: images.
  3. Read the cleaned HTML and the change list.
  4. Copy the result.

Frequently asked questions

Is this DOMPurify?

No. It is a separate, smaller implementation. Use a maintained library for real products.

Are encoded tricks handled?

URL values are decoded and stripped of hidden characters before the scheme check, and output is escaped.

Why are ids removed?

Ids can clash with page scripts (DOM clobbering). You can keep them with the option.