xemlock/htmlpurifier-html5
HTML5 definitions and tidy/sanitization rules for HTML Purifier, aligned with the WHATWG spec. Purify and normalize dirty HTML5 into valid output with an HTML5-ready config, plus flexible directives (e.g., safely allow YouTube iframes).
<article>, <section>) and accessibility (WCAG compliance with proper HTML5 structure). Aligns with trends toward headless CMS and component-based architectures.<figure>, <audio>).<iframe> only for YouTube via regex whitelisting).Adopt When:
Purifier facade or HTMLPurifier directly but need extended HTML5 support beyond legacy definitions (e.g., <dialog>, <track>).<form> only in trusted contexts or whitelisting <iframe> sources).<video> but blocking malicious scripts).Look Elsewhere If:
<b>, <i>). Consider Laravel’s Str::markdown() or a lightweight library like ParagonIE/Sanitizer.HTMLPurifier may suffice, reducing dependency bloat.DOMPurifier or use HTMLPurifier’s JavaScript port.PHP’s filter_var() for simple cases or consider caching purified outputs.*"This package lets us enable modern web features while keeping users safe. Here’s why it’s a no-brainer:
<article>), and interactive elements (<dialog>) without security risks. Think YouTube comments, interactive tutorials, or accessible documentation—all while blocking XSS attacks.Risk: Minimal. The package is MIT-licensed, Laravel-friendly, and actively maintained. We’re not betting on unproven tech—just leveraging existing tools smarter."*
*"This is a drop-in upgrade for Laravel’s HTML purification that solves two critical problems:
<video>, <track>, <dialog>) and attributes (e.g., async for <script>) while maintaining strict sanitization. No more hacking around with regex or custom parsers.config() or service container. Examples:
<iframe> only for YouTube: $config->set('HTML.SafeIframe', true)->set('URI.SafeIframeRegexp', '%^//www.youtube.com/embed/%');$config->set('HTML.Forms', false);<article>, <section>, etc.Integration:
Purifier facade or HTMLPurifier service provider.HTMLPurifier config with HTMLPurifier_HTML5Config::createDefault() in one line.ValidatedRequest) to use the new config.Performance:
HTMLPurifier (same core engine, just extended definitions).Migration Path:
HTMLPurifier with xemlock/htmlpurifier-html5 in composer.json.HTMLPurifier_HTML5Config (backward-compatible with most existing setups).Alternatives Considered:
HTMLPurifier: Lacks HTML5 support; would require custom definitions (higher maintenance).Recommendation: Adopt this package as part of our next major release cycle. It’s a low-risk, high-reward upgrade that enables features while reducing security risks."*
How can I help you explore Laravel packages today?