Kantoor.Webmail.HtmlSanitizer (Kantoor v1.0.0)

Turns hostile HTML mail into something that is safe to put inside the sandboxed iframe, in two layers:

  1. an allow-list scrub (html_sanitize_ex, see Kantoor.Webmail.HtmlScrubber) that removes scripts, styles, forms, frames, event handlers, javascript: and other URL schemes, remote images and CSS (so no url() beacons);
  2. the iframe itself: sandbox WITHOUT allow-scripts/allow-same-origin, plus a CSP meta tag (default-src 'none') in the document.

Remote content is blocked unless remote: true (a per-view toggle, never persisted). Links get rel="noopener noreferrer nofollow" and open in a new tab (<base target=_blank>).

Summary

Functions

True when the HTML references remote images (so the toggle is worth showing).

Sanitizes html. Options: :remote (allow remote images, default false) and :inline (%{cid => {mime, bytes}}, embedded images to inline as data URIs).

The complete srcdoc document for the iframe, including its CSP. Remote images are only permitted by the CSP when remote: true.

Functions

remote_content?(html)

@spec remote_content?(String.t()) :: boolean()

True when the HTML references remote images (so the toggle is worth showing).

sanitize(html, opts \\ [])

@spec sanitize(String.t(), keyword()) :: String.t()

Sanitizes html. Options: :remote (allow remote images, default false) and :inline (%{cid => {mime, bytes}}, embedded images to inline as data URIs).

srcdoc(html, opts \\ [])

@spec srcdoc(String.t(), keyword()) :: String.t()

The complete srcdoc document for the iframe, including its CSP. Remote images are only permitted by the CSP when remote: true.