HTML sanitizer
Clean HTML written by users so that only the allowed tags and attributes remain and no script can hide in it. Typical uses: display comments, rich text fields or mails safely in a page.
html sanitize <html>
Description
Clean HTML with the preset basic: the clean HTML
Clean HTML with the preset basic: the clean HTML
Parameters
html: The HTML to clean (10 MB at most) - String - required
html: The HTML to clean (10 MB at most) - String - required
admin
html sanitize "<p onclick=\"steal()\">Bonjour <b>Marie</b> <a href=\"javascript:alert(1)\">voir</a><script>alert(1)</script></p><p>Lien : <a href=\"https://www.mentdb.org/\" title=\"MentDB\">site</a></p>"
mentdb
<p>Bonjour <b>Marie</b> <a>voir</a></p><p>Lien : <a href="https://www.mentdb.org/" title="MentDB">site</a></p>
html sanitize <html> <json_params>
Description
Clean HTML with parameters: preset (none, basic, relaxed), tags (more tags), attributes ({"tag": ["attribute"], ":all": ["class"]}), protocols (["http", "https", "mailto"]), allow_relative_urls (true), allow_data_images (false), nofollow (false), output (html, text, json: {html, text, changed, removed_tags, removed_attributes, removed_urls}), timeout_ms (10000)
Clean HTML with parameters: preset (none, basic, relaxed), tags (more tags), attributes ({"tag": ["attribute"], ":all": ["class"]}), protocols (["http", "https", "mailto"]), allow_relative_urls (true), allow_data_images (false), nofollow (false), output (html, text, json: {html, text, changed, removed_tags, removed_attributes, removed_urls}), timeout_ms (10000)
Parameters
html: The HTML to clean - String - required
json_params: The parameters, as a JSON object - String - required
html: The HTML to clean - String - required
json_params: The parameters, as a JSON object - String - required
admin
html sanitize "<p style=\"color:red\">Prix <img src=x onerror=alert(1)> 12 €</p><iframe src=\"https://evil.example\"></iframe>" "{\"preset\": \"relaxed\", \"output\": \"json\"}"
mentdb
{"html": "<p>Prix <img src=\"x\"> 12 \u20AC</p>", "text": "Prix 12 \u20AC", "changed": true, "removed_tags": {"iframe": 1}, "removed_attributes": {"img.onerror": 1, "p.style": 1}, "removed_urls": 0}
Plain text of a table and a list
admin
html sanitize "<h2>Commande</h2><table><tr><td>Stylo</td><td>2</td></tr></table><ul><li>livraison</li><li>facture</li></ul>" "{\"preset\": \"relaxed\", \"output\": \"text\"}"
mentdb
Commande Stylo 2 - livraison - facture
Links of users in nofollow, a class allowed
admin
html sanitize "<p class=\"note\">Voir <a href=\"https://example.com\" target=\"_blank\">ici</a></p>" "{\"attributes\": {\":all\": [\"class\"], \"a\": [\"target\"]}, \"nofollow\": true}"
mentdb
<p class="note">Voir <a href="https://example.com" target="_blank" rel="nofollow noopener noreferrer">ici</a></p>
Used in use cases (1 recipe)
Web & API developer › Clean a user comment before showing it, check a sign-up password and make a short link
Web & API developer › Clean a user comment before showing it, check a sign-up password and make a short link
