ting
Opinionated HTML Sanitizer for Node.js. Built upon sanitize-html.
- Keep up with the latest standards (new tags are allowed, e.g.
<aside>
,<progress>
,<time>
...). <iframe>
is not allowed.style
attribute is not allowed.id
attribute is not allowed unlessidFilter
returns true (see Options).- Inline SVG is not allowed (use
<img>
with an external SVG source). - Customizable via sanitize-html options.
- TypeScript friendly.
Installation
yarn add ting
Usage
const ting = ; ting;
Example:
const ting = ; const dirty = `<script>alert(1)</script><img src="x.jpg" onclick="alert(1)"/><img src="cool.jpg"/><figcaption>caption</figcaption>`; const safe = ting;console;/** Prints <img src="x.jpg" /> <img src="cool.jpg" /> <figcaption>caption</figcaption> */
Options
- Example: allow all
id
s starting with"user-content-"
:
ting;/** Prints <a id="user-content-link">fine</a> <a>no id</a> */
Overriding sanitize-html Options
ting is built upon sanitize-html, you can override the internal sanitize-html options, or pass a new one (which would make ting no different than sanitize-html). e.g. to allow <iframe>
tags, override the allowedTags
and allowedAttributes
of sanitize-html options.
ting;// Prints: <iframe src="https://coldfunction.com"></iframe>