Skip to content

HtmlPolicy

What CkSanitizer::Html lets through: formatting alone, or formatting and media.

The policy chooses between two allow-lists and never opens a third door: under either, script, styles, forms, frames and every other kind of embedding go. Media is the default, CkSettings::DefaultHtmlPolicy.

Members

Member What stays
Formatting Paragraphs, headings, line breaks and rules, emphasis in every form, lists, quotes, code, tables and links. An image, a video or an audio element is removed with what it holds.
Media Everything Formatting keeps, plus img, video, audio and source — each with an address the library has read. The default.

The enum is backed by an int — Formatting is 0, Media 1.

Where it is used

The policy parameter of CkSanitizer::Html and CkSanitizer::Explain. The full list of elements and attributes each policy keeps is on the CkSanitizer page.

Quick look

use SafeCoder\CommonKit\CkSanitizer;
use SafeCoder\CommonKit\Enums\HtmlPolicy;

CkSanitizer::Html('<p>a<img src="/a.png">b</p>');                                // -> '<p>a<img src="/a.png">b</p>'
CkSanitizer::Html('<p>a<img src="/a.png">b</p>', policy: HtmlPolicy::Formatting);   // -> '<p>ab</p>'