Get started with sanitize-html CDN

MIT licensed

Sanitize-HTML library converts untrusted HTML to safe, XSS-risk-minimized output format.

Tags:
  • html
  • parser
  • sanitizer
  • apostrophecms

Stable version

Copied!

How to start using sanitize-html CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with sanitize-html CDN - cdnhub.io</title>
  <script src="https://cdn.jsdelivr.net/npm/sanitize-html@2.12.1/sanitize-html.min.js"></script>
</head>
<body>
  <script>
    const dirtyHtml = '<script src="malicious-script.js"></script><p>Hello, World!</p>';
    const sanitizer = new DOMParser().parseFromString('<html></html>'.toString(), 'text/html').createDocumentFragment();
    const cleanHtml = sanitizeHtml(dirtyHtml, {
      allowedClasses: [],
      allowedTags: ['p'],
      allowedAttributes: {}
    }).toString();

    sanitizer.innerHTML = cleanHtml;
    document.body.appendChild(sanitizer);
  </script>
</body>
</html>

All versions